updated 'config.ini'
This commit is contained in:
parent
28f71271d7
commit
be4f86580e
13 changed files with 635 additions and 208 deletions
43
images.go
43
images.go
|
@ -54,7 +54,7 @@ func handleImageSearch(w http.ResponseWriter, r *http.Request, settings UserSett
|
|||
"Theme": settings.Theme,
|
||||
"Safe": settings.SafeSearch,
|
||||
"IsThemeDark": settings.IsThemeDark,
|
||||
"HardCacheEnabled": config.HardCacheEnabled,
|
||||
"HardCacheEnabled": config.DriveCacheEnabled,
|
||||
"JsDisabled": jsDisabled,
|
||||
}
|
||||
|
||||
|
@ -75,10 +75,10 @@ func getImageResultsFromCacheOrFetch(cacheKey CacheKey, query, safe, lang string
|
|||
go func() {
|
||||
results, exists := resultsCache.Get(cacheKey)
|
||||
if exists {
|
||||
printInfo("Cache hit")
|
||||
printDebug("Cache hit")
|
||||
cacheChan <- results
|
||||
} else {
|
||||
printInfo("Cache miss")
|
||||
printDebug("Cache miss")
|
||||
cacheChan <- nil
|
||||
}
|
||||
}()
|
||||
|
@ -86,21 +86,29 @@ func getImageResultsFromCacheOrFetch(cacheKey CacheKey, query, safe, lang string
|
|||
select {
|
||||
case results := <-cacheChan:
|
||||
if results == nil {
|
||||
combinedResults = fetchImageResults(query, safe, lang, page, synchronous)
|
||||
if len(combinedResults) > 0 {
|
||||
combinedResults = filterValidImages(combinedResults)
|
||||
resultsCache.Set(cacheKey, convertToSearchResults(combinedResults))
|
||||
if config.CrawlerEnabled {
|
||||
combinedResults = fetchImageResults(query, safe, lang, page, synchronous)
|
||||
if len(combinedResults) > 0 {
|
||||
combinedResults = filterValidImages(combinedResults)
|
||||
resultsCache.Set(cacheKey, convertToSearchResults(combinedResults))
|
||||
}
|
||||
} else {
|
||||
printDebug("Crawler disabled; skipping fetching from image search engines.")
|
||||
}
|
||||
} else {
|
||||
_, _, imageResults := convertToSpecificResults(results)
|
||||
combinedResults = filterValidImages(imageResults)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
printInfo("Cache check timeout")
|
||||
combinedResults = fetchImageResults(query, safe, lang, page, synchronous)
|
||||
if len(combinedResults) > 0 {
|
||||
combinedResults = filterValidImages(combinedResults)
|
||||
resultsCache.Set(cacheKey, convertToSearchResults(combinedResults))
|
||||
printDebug("Cache check timeout")
|
||||
if config.CrawlerEnabled {
|
||||
combinedResults = fetchImageResults(query, safe, lang, page, synchronous)
|
||||
if len(combinedResults) > 0 {
|
||||
combinedResults = filterValidImages(combinedResults)
|
||||
resultsCache.Set(cacheKey, convertToSearchResults(combinedResults))
|
||||
}
|
||||
} else {
|
||||
printDebug("Crawler disabled; skipping fetching from image search engines.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,6 +117,13 @@ func getImageResultsFromCacheOrFetch(cacheKey CacheKey, query, safe, lang string
|
|||
|
||||
func fetchImageResults(query, safe, lang string, page int, synchronous bool) []ImageSearchResult {
|
||||
var results []ImageSearchResult
|
||||
|
||||
// Check if CrawlerEnabled is false
|
||||
if !config.CrawlerEnabled {
|
||||
printDebug("Crawler is disabled; skipping image search engine fetching.")
|
||||
return results
|
||||
}
|
||||
|
||||
engineCount := len(imageSearchEngines)
|
||||
|
||||
// Determine the engine to use based on the page number
|
||||
|
@ -145,7 +160,7 @@ func fetchImageResults(query, safe, lang string, page int, synchronous bool) []I
|
|||
imageURLMapMu.Unlock()
|
||||
|
||||
// Set ProxyFull and ProxyThumb
|
||||
if config.HardCacheEnabled {
|
||||
if config.DriveCacheEnabled {
|
||||
// Cache the thumbnail image asynchronously
|
||||
go func(imgResult ImageSearchResult) {
|
||||
_, success, err := cacheImage(imgResult.Thumb, imgResult.ID, true)
|
||||
|
@ -204,7 +219,7 @@ func fetchImageResults(query, safe, lang string, page int, synchronous bool) []I
|
|||
imageURLMap[fmt.Sprintf("%s_thumb", hash)] = imageResult.Thumb
|
||||
imageURLMapMu.Unlock()
|
||||
|
||||
if config.HardCacheEnabled {
|
||||
if config.DriveCacheEnabled {
|
||||
// Cache the thumbnail image asynchronously
|
||||
go func(imgResult ImageSearchResult) {
|
||||
_, success, err := cacheImage(imgResult.Thumb, imgResult.ID, true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue