|
@@ -59,11 +59,6 @@ func (rh *RenderHandler) BuildCacheForFolder(path string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (rh *RenderHandler) CacheExists(file string) bool {
|
|
|
- cacheFolder := filepath.ToSlash(filepath.Clean(filepath.Dir(file))) + "/.cache/"
|
|
|
- return fileExists(cacheFolder+filepath.Base(file)+".jpg") || fileExists(cacheFolder+filepath.Base(file)+".png")
|
|
|
-}
|
|
|
-
|
|
|
//Try to load a cache from file. If not exists, generate it now
|
|
|
func (rh *RenderHandler) LoadCache(file string, generateOnly bool) (string, error) {
|
|
|
//Create a cache folder
|
|
@@ -248,7 +243,7 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
|
|
|
//Updated implementation 24/12/2020: Load image with cache first before rendering those without
|
|
|
|
|
|
for _, file := range files {
|
|
|
- if rh.CacheExists(file) == false {
|
|
|
+ if CacheExists(file) == false {
|
|
|
//Cache not exists. Render this later
|
|
|
filesWithoutCache = append(filesWithoutCache, file)
|
|
|
} else {
|
|
@@ -294,6 +289,44 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
|
|
|
|
|
|
}
|
|
|
|
|
|
+//Check if the cache for a file exists
|
|
|
+func CacheExists(file string) bool {
|
|
|
+ cacheFolder := filepath.ToSlash(filepath.Clean(filepath.Dir(file))) + "/.cache/"
|
|
|
+ return fileExists(cacheFolder+filepath.Base(file)+".jpg") || fileExists(cacheFolder+filepath.Base(file)+".png")
|
|
|
+}
|
|
|
+
|
|
|
+//Get cache path for this file, given realpath
|
|
|
+func GetCacheFilePath(file string) (string, error) {
|
|
|
+ if CacheExists(file) {
|
|
|
+ cacheFolder := filepath.ToSlash(filepath.Clean(filepath.Dir(file))) + "/.cache/"
|
|
|
+ if fileExists(cacheFolder + filepath.Base(file) + ".jpg") {
|
|
|
+ return cacheFolder + filepath.Base(file) + ".jpg", nil
|
|
|
+ } else if fileExists(cacheFolder + filepath.Base(file) + ".png") {
|
|
|
+ return cacheFolder + filepath.Base(file) + ".png", nil
|
|
|
+ } else {
|
|
|
+ return "", errors.New("Unable to resolve thumbnail cache location")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return "", errors.New("No thumbnail cached for this file")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//Remove cache if exists, given realpath
|
|
|
+func RemoveCache(file string) error {
|
|
|
+ if CacheExists(file) {
|
|
|
+ cachePath, err := GetCacheFilePath(file)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ //Remove the thumbnail cache
|
|
|
+ os.Remove(cachePath)
|
|
|
+ return nil
|
|
|
+ } else {
|
|
|
+ return errors.New("Thumbnail cache not exists for this file")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func specialGlob(path string) ([]string, error) {
|
|
|
files, err := filepath.Glob(path)
|
|
|
if err != nil {
|