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")
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -146,7 +146,13 @@
|
|||
<div class="result_item">
|
||||
<div class="result_header">
|
||||
<div class="favicon-container">
|
||||
<img src="{{ .FaviconURL }}" alt="🌐" class="favicon">
|
||||
<img
|
||||
src="/static/images/placeholder.svg"
|
||||
data-id="{{ .FaviconID }}"
|
||||
data-full="/image/{{ .FaviconID }}_thumb.webp"
|
||||
alt="🌐"
|
||||
class="favicon placeholder-img"
|
||||
/>
|
||||
</div>
|
||||
<div class="result-url">
|
||||
{{ .PrettyLink.Domain }}
|
||||
|
@ -191,6 +197,7 @@
|
|||
<script defer src="/static/js/dynamicscrolling.js"></script>
|
||||
<script defer src="/static/js/autocomplete.js"></script>
|
||||
<script defer src="/static/js/minimenu.js"></script>
|
||||
<script defer src="/static/js/dynamicscrollingimages.js"></script>
|
||||
<script>
|
||||
document.querySelectorAll('.js-enabled').forEach(el => el.classList.remove('js-enabled'));
|
||||
</script>
|
||||
|
|
11
text.go
11
text.go
|
@ -56,6 +56,7 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
|
|||
type DecoratedResult struct {
|
||||
TextSearchResult
|
||||
FaviconURL string
|
||||
FaviconID string
|
||||
PrettyLink LinkParts
|
||||
}
|
||||
|
||||
|
@ -65,10 +66,16 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
|
|||
continue
|
||||
}
|
||||
|
||||
// First format the link
|
||||
prettyLink := FormatLinkHTML(r.URL)
|
||||
faviconID := faviconIDFromURL(r.URL)
|
||||
faviconURL := getFaviconProxyURL("", r.URL) //string(prettyLink.Domain)
|
||||
|
||||
decoratedResults = append(decoratedResults, DecoratedResult{
|
||||
TextSearchResult: r,
|
||||
FaviconURL: getFaviconProxyURL("", r.URL),
|
||||
PrettyLink: FormatLinkHTML(r.URL),
|
||||
PrettyLink: prettyLink,
|
||||
FaviconID: faviconID,
|
||||
FaviconURL: faviconURL,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue