fixed favicon backend not really workin
This commit is contained in:
parent
72cbfbab10
commit
4a0738745a
4 changed files with 43 additions and 20 deletions
40
favicon.go
40
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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue