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
|
// Resolves favicon URL using multiple methods
|
||||||
func resolveFaviconURL(rawFavicon, pageURL string) (faviconURL, cacheID string) {
|
func resolveFaviconURL(rawFavicon, pageURL string) (faviconURL, cacheID string) {
|
||||||
|
cacheID = faviconIDFromURL(pageURL)
|
||||||
|
|
||||||
// Handle data URLs first
|
// Handle data URLs first
|
||||||
if strings.HasPrefix(rawFavicon, "data:image") {
|
if strings.HasPrefix(rawFavicon, "data:image") {
|
||||||
parts := strings.SplitN(rawFavicon, ";base64,", 2)
|
parts := strings.SplitN(rawFavicon, ";base64,", 2)
|
||||||
|
@ -297,10 +299,12 @@ func findFaviconInHTML(pageURL string) string {
|
||||||
return faviconURL
|
return faviconURL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get proxy URL (cached) - remains mostly the same
|
|
||||||
func getFaviconProxyURL(rawFavicon, pageURL string) string {
|
func getFaviconProxyURL(rawFavicon, pageURL string) string {
|
||||||
// First try cache without any locks
|
if pageURL == "" {
|
||||||
cacheID := faviconIDFromURL(pageURL) // Simple hash of pageURL
|
return "/static/images/missing.svg"
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheID := faviconIDFromURL(pageURL)
|
||||||
filename := fmt.Sprintf("%s_thumb.webp", cacheID)
|
filename := fmt.Sprintf("%s_thumb.webp", cacheID)
|
||||||
cachedPath := filepath.Join(config.DriveCache.Path, "images", filename)
|
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)
|
return fmt.Sprintf("/image/%s_thumb.webp", cacheID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache miss - resolve favicon URL (may hit network)
|
// Resolve URL (but ignore resolved ID — we always use the one from pageURL)
|
||||||
faviconURL, cacheID := resolveFaviconURL(rawFavicon, pageURL)
|
faviconURL, _ := resolveFaviconURL(rawFavicon, pageURL)
|
||||||
if faviconURL == "" || cacheID == "" {
|
if faviconURL == "" {
|
||||||
|
recordInvalidImageID(cacheID)
|
||||||
return "/static/images/missing.svg"
|
return "/static/images/missing.svg"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recheck cache after resolution (in case another request cached it)
|
// Avoid re-downloading
|
||||||
if _, err := os.Stat(cachedPath); err == nil {
|
|
||||||
return fmt.Sprintf("/image/%s_thumb.webp", cacheID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check download status with lock
|
|
||||||
faviconCache.RLock()
|
faviconCache.RLock()
|
||||||
downloading := faviconCache.m[cacheID]
|
downloading := faviconCache.m[cacheID]
|
||||||
faviconCache.RUnlock()
|
faviconCache.RUnlock()
|
||||||
|
@ -335,7 +335,10 @@ func getFaviconProxyURL(rawFavicon, pageURL string) string {
|
||||||
delete(faviconCache.m, cacheID)
|
delete(faviconCache.m, cacheID)
|
||||||
faviconCache.Unlock()
|
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
|
// Caches favicon, always saving *_thumb.webp
|
||||||
func cacheFavicon(imageURL, imageID string) (string, bool, error) {
|
func cacheFavicon(imageURL, imageID string) (string, bool, error) {
|
||||||
if imageURL == "" {
|
// if imageURL == "" {
|
||||||
recordInvalidImageID(imageID)
|
// recordInvalidImageID(imageID)
|
||||||
return "", false, fmt.Errorf("empty image URL for image ID %s", 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)
|
filename := fmt.Sprintf("%s_thumb.webp", imageID)
|
||||||
imageCacheDir := filepath.Join(config.DriveCache.Path, "images")
|
imageCacheDir := filepath.Join(config.DriveCache.Path, "images")
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
(function() {
|
(function() {
|
||||||
// Add loading effects to image and title
|
// Add loading effects to image and title
|
||||||
function addLoadingEffects(imgElement) {
|
function addLoadingEffects(imgElement) {
|
||||||
|
const container = imgElement.closest('.image');
|
||||||
|
if (!container) return; // avoid null dereference
|
||||||
|
|
||||||
const title = imgElement.closest('.image').querySelector('.img_title');
|
const title = imgElement.closest('.image').querySelector('.img_title');
|
||||||
imgElement.classList.add('loading-image');
|
imgElement.classList.add('loading-image');
|
||||||
title.classList.add('title-loading');
|
title.classList.add('title-loading');
|
||||||
|
|
|
@ -146,7 +146,13 @@
|
||||||
<div class="result_item">
|
<div class="result_item">
|
||||||
<div class="result_header">
|
<div class="result_header">
|
||||||
<div class="favicon-container">
|
<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>
|
||||||
<div class="result-url">
|
<div class="result-url">
|
||||||
{{ .PrettyLink.Domain }}
|
{{ .PrettyLink.Domain }}
|
||||||
|
@ -191,6 +197,7 @@
|
||||||
<script defer src="/static/js/dynamicscrolling.js"></script>
|
<script defer src="/static/js/dynamicscrolling.js"></script>
|
||||||
<script defer src="/static/js/autocomplete.js"></script>
|
<script defer src="/static/js/autocomplete.js"></script>
|
||||||
<script defer src="/static/js/minimenu.js"></script>
|
<script defer src="/static/js/minimenu.js"></script>
|
||||||
|
<script defer src="/static/js/dynamicscrollingimages.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.querySelectorAll('.js-enabled').forEach(el => el.classList.remove('js-enabled'));
|
document.querySelectorAll('.js-enabled').forEach(el => el.classList.remove('js-enabled'));
|
||||||
</script>
|
</script>
|
||||||
|
|
11
text.go
11
text.go
|
@ -56,6 +56,7 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
|
||||||
type DecoratedResult struct {
|
type DecoratedResult struct {
|
||||||
TextSearchResult
|
TextSearchResult
|
||||||
FaviconURL string
|
FaviconURL string
|
||||||
|
FaviconID string
|
||||||
PrettyLink LinkParts
|
PrettyLink LinkParts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +66,16 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First format the link
|
||||||
|
prettyLink := FormatLinkHTML(r.URL)
|
||||||
|
faviconID := faviconIDFromURL(r.URL)
|
||||||
|
faviconURL := getFaviconProxyURL("", r.URL) //string(prettyLink.Domain)
|
||||||
|
|
||||||
decoratedResults = append(decoratedResults, DecoratedResult{
|
decoratedResults = append(decoratedResults, DecoratedResult{
|
||||||
TextSearchResult: r,
|
TextSearchResult: r,
|
||||||
FaviconURL: getFaviconProxyURL("", r.URL),
|
PrettyLink: prettyLink,
|
||||||
PrettyLink: FormatLinkHTML(r.URL),
|
FaviconID: faviconID,
|
||||||
|
FaviconURL: faviconURL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue