diff --git a/favicon.go b/favicon.go index 837e3f9..e338fc9 100644 --- a/favicon.go +++ b/favicon.go @@ -59,6 +59,8 @@ func faviconIDFromURL(rawURL string) string { // Resolves favicon URL using multiple methods func resolveFaviconURL(rawFavicon, pageURL string) (faviconURL, cacheID string) { + cacheID = faviconIDFromURL(pageURL) + // Handle data URLs first if strings.HasPrefix(rawFavicon, "data:image") { parts := strings.SplitN(rawFavicon, ";base64,", 2) @@ -297,10 +299,12 @@ func findFaviconInHTML(pageURL string) string { return faviconURL } -// Get proxy URL (cached) - remains mostly the same func getFaviconProxyURL(rawFavicon, pageURL string) string { - // First try cache without any locks - cacheID := faviconIDFromURL(pageURL) // Simple hash of pageURL + if pageURL == "" { + return "/static/images/missing.svg" + } + + cacheID := faviconIDFromURL(pageURL) filename := fmt.Sprintf("%s_thumb.webp", cacheID) cachedPath := filepath.Join(config.DriveCache.Path, "images", filename) @@ -308,18 +312,14 @@ func getFaviconProxyURL(rawFavicon, pageURL string) string { return fmt.Sprintf("/image/%s_thumb.webp", cacheID) } - // Cache miss - resolve favicon URL (may hit network) - faviconURL, cacheID := resolveFaviconURL(rawFavicon, pageURL) - if faviconURL == "" || cacheID == "" { + // Resolve URL (but ignore resolved ID — we always use the one from pageURL) + faviconURL, _ := resolveFaviconURL(rawFavicon, pageURL) + if faviconURL == "" { + recordInvalidImageID(cacheID) return "/static/images/missing.svg" } - // Recheck cache after resolution (in case another request cached it) - if _, err := os.Stat(cachedPath); err == nil { - return fmt.Sprintf("/image/%s_thumb.webp", cacheID) - } - - // Check download status with lock + // Avoid re-downloading faviconCache.RLock() downloading := faviconCache.m[cacheID] faviconCache.RUnlock() @@ -335,7 +335,10 @@ func getFaviconProxyURL(rawFavicon, pageURL string) string { delete(faviconCache.m, cacheID) faviconCache.Unlock() }() - cacheFavicon(faviconURL, cacheID) + _, _, err := cacheFavicon(faviconURL, cacheID) + if err != nil { + recordInvalidImageID(cacheID) + } }() } @@ -344,10 +347,13 @@ func getFaviconProxyURL(rawFavicon, pageURL string) string { // Caches favicon, always saving *_thumb.webp func cacheFavicon(imageURL, imageID string) (string, bool, error) { - if imageURL == "" { - recordInvalidImageID(imageID) - return "", false, fmt.Errorf("empty image URL for image ID %s", imageID) - } + // if imageURL == "" { + // recordInvalidImageID(imageID) + // return "", false, fmt.Errorf("empty image URL for image ID %s", imageID) + // } + + // Debug + fmt.Printf("Downloading favicon [%s] for ID [%s]\n", imageURL, imageID) filename := fmt.Sprintf("%s_thumb.webp", imageID) imageCacheDir := filepath.Join(config.DriveCache.Path, "images") diff --git a/static/js/dynamicscrollingimages.js b/static/js/dynamicscrollingimages.js index 731f8e4..a15b253 100644 --- a/static/js/dynamicscrollingimages.js +++ b/static/js/dynamicscrollingimages.js @@ -2,6 +2,9 @@ (function() { // Add loading effects to image and title function addLoadingEffects(imgElement) { + const container = imgElement.closest('.image'); + if (!container) return; // avoid null dereference + const title = imgElement.closest('.image').querySelector('.img_title'); imgElement.classList.add('loading-image'); title.classList.add('title-loading'); diff --git a/templates/text.html b/templates/text.html index 9d23620..b04f4f1 100755 --- a/templates/text.html +++ b/templates/text.html @@ -146,7 +146,13 @@