Prechádzať zdrojové kódy

Optimized thumbnail generation logic

TC 2 týždňov pred
rodič
commit
ef9c3f61be
1 zmenil súbory, kde vykonal 9 pridanie a 0 odobranie
  1. 9 0
      mod/bokofs/bokothumb/bokodir.go

+ 9 - 0
mod/bokofs/bokothumb/bokodir.go

@@ -94,6 +94,15 @@ func (r *RouterDir) OpenFile(ctx context.Context, name string, flag int, perm os
 				r.renderer.RenderThumbnail(filepath.Join(r.FsPath, name, entry.Name()), outputFolder)
 			}()
 		}
+	} else {
+		//Requested a file path. Render the thumbnail
+		outputFolder := filepath.Join(r.ThumbStore, name)
+		if err := os.MkdirAll(filepath.Dir(outputFolder), 0755); err != nil {
+			return nil, err
+		}
+		//The RenderThumbnail function will immeidiately return if the thumbnail already exists
+		//If the thumbnail is not present, it will be generated in real time
+		r.renderer.RenderThumbnail(filepath.Join(r.FsPath, name), outputFolder)
 	}
 
 	fmt.Println("[Bokothumb]", "OpenFile called to "+name)