cleanup
This commit is contained in:
parent
3d47c80446
commit
49f613ddeb
15 changed files with 98 additions and 234 deletions
23
images.go
23
images.go
|
@ -12,9 +12,9 @@ var imageSearchEngines []SearchEngine
|
|||
|
||||
func init() {
|
||||
imageSearchEngines = []SearchEngine{
|
||||
{Name: "Qwant", Func: wrapImageSearchFunc(PerformQwantImageSearch), Weight: 1},
|
||||
{Name: "Bing", Func: wrapImageSearchFunc(PerformBingImageSearch), Weight: 2},
|
||||
{Name: "DeviantArt", Func: wrapImageSearchFunc(PerformDeviantArtImageSearch), Weight: 3},
|
||||
{Name: "Qwant", Func: wrapImageSearchFunc(PerformQwantImageSearch)},
|
||||
{Name: "Bing", Func: wrapImageSearchFunc(PerformBingImageSearch)},
|
||||
{Name: "DeviantArt", Func: wrapImageSearchFunc(PerformDeviantArtImageSearch)},
|
||||
//{Name: "Imgur", Func: wrapImageSearchFunc(PerformImgurImageSearch), Weight: 4}, // Image proxy not working
|
||||
}
|
||||
}
|
||||
|
@ -90,8 +90,7 @@ func fetchImageResults(query, safe, lang string, page int) []ImageSearchResult {
|
|||
for _, engine := range imageSearchEngines {
|
||||
printInfo("Using image search engine: %s", engine.Name)
|
||||
|
||||
searchResults, duration, err := engine.Func(query, safe, lang, page)
|
||||
updateEngineMetrics(&engine, duration, err == nil)
|
||||
searchResults, _, err := engine.Func(query, safe, lang, page)
|
||||
if err != nil {
|
||||
printWarn("Error performing image search with %s: %v", engine.Name, err)
|
||||
continue
|
||||
|
@ -100,19 +99,15 @@ func fetchImageResults(query, safe, lang string, page int) []ImageSearchResult {
|
|||
for _, result := range searchResults {
|
||||
imageResult := result.(ImageSearchResult)
|
||||
if config.HardCacheDuration > 0 {
|
||||
// Save the original Media URL before overwriting
|
||||
originalMediaURL := imageResult.Media
|
||||
|
||||
// Generate hash from the original media URL
|
||||
// Generate hash from the original full-size image URL
|
||||
hasher := md5.New()
|
||||
hasher.Write([]byte(originalMediaURL))
|
||||
hasher.Write([]byte(imageResult.Full))
|
||||
hash := hex.EncodeToString(hasher.Sum(nil))
|
||||
filename := hash + ".webp"
|
||||
|
||||
// Set the Media URL to point to the cached image path
|
||||
// Set the Full URL to point to the cached image path
|
||||
cacheURL := "/image_cache/" + filename
|
||||
imageResult.Media = cacheURL
|
||||
imageResult.ThumbProxy = cacheURL
|
||||
imageResult.ProxyFull = cacheURL
|
||||
|
||||
// Assign the ID
|
||||
imageResult.ID = hash
|
||||
|
@ -123,7 +118,7 @@ func fetchImageResults(query, safe, lang string, page int) []ImageSearchResult {
|
|||
if err != nil {
|
||||
printWarn("Failed to cache image %s: %v", originalURL, err)
|
||||
}
|
||||
}(originalMediaURL, filename)
|
||||
}(imageResult.Full, filename)
|
||||
}
|
||||
results = append(results, imageResult)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue