This commit is contained in:
partisan 2024-10-14 22:15:38 +02:00
parent 3d47c80446
commit 49f613ddeb
15 changed files with 98 additions and 234 deletions

View file

@ -116,7 +116,7 @@ func cacheImage(imageURL, filename string) (string, error) {
}
if err != nil {
return "", err
return "", fmt.Errorf("failed to decode image: %v", err)
}
// Ensure the cache directory exists
@ -206,12 +206,23 @@ func handleImageStatus(w http.ResponseWriter, r *http.Request) {
printDebug("Status map: %v", statusMap)
for _, id := range ids {
filename := id + ".webp"
cachedImagePath := filepath.Join(cacheDir, filename)
// Check for different possible extensions
extensions := []string{".webp", ".svg"}
var cachedImagePath string
var found bool
if _, err := os.Stat(cachedImagePath); err == nil {
// Image is cached and ready
statusMap[id] = "/image_cache/" + filename
for _, ext := range extensions {
filename := id + ext
path := filepath.Join(cacheDir, filename)
if _, err := os.Stat(path); err == nil {
cachedImagePath = "/image_cache/" + filename
found = true
break
}
}
if found {
statusMap[id] = cachedImagePath
} else {
// Image is not ready
statusMap[id] = ""