diff --git a/config.go b/config.go index ab83b48..4ec0272 100644 --- a/config.go +++ b/config.go @@ -2,14 +2,11 @@ package main import ( "bufio" - "log" "os" "strconv" "strings" - "sync" "time" - "github.com/fsnotify/fsnotify" "gopkg.in/ini.v1" ) @@ -158,44 +155,8 @@ func loadConfig() Config { WebsiteEnabled: websiteEnabled, LogLevel: logLevel, HardCacheDuration: hardCacheDuration, + HardCacheEnabled: hardCacheDuration != 0, } return config } - -var configLock sync.RWMutex - -func startFileWatcher() { - watcher, err := fsnotify.NewWatcher() - if err != nil { - printErr("%v", err) - } - - go func() { - defer watcher.Close() - for { - select { - case event, ok := <-watcher.Events: - if !ok { - return - } - if event.Op&fsnotify.Write == fsnotify.Write { - printInfo("Modified file: %v", event.Name) - configLock.Lock() - config = loadConfig() - configLock.Unlock() - } - case err, ok := <-watcher.Errors: - if !ok { - return - } - printWarn("Error watching configuration file: %v", err) - } - } - }() - - err = watcher.Add(configFilePath) - if err != nil { - log.Fatal(err) - } -} diff --git a/files.go b/files.go index 3f7847b..43ab607 100755 --- a/files.go +++ b/files.go @@ -30,7 +30,7 @@ var ( var fileResultsChan = make(chan []TorrentResult) -func initializeTorrentSites() { +func init() { torrentGalaxy = NewTorrentGalaxy() // nyaa = NewNyaa() thePirateBay = NewThePirateBay() diff --git a/images.go b/images.go index eb9bc35..0f5b87d 100755 --- a/images.go +++ b/images.go @@ -29,18 +29,19 @@ func handleImageSearch(w http.ResponseWriter, settings UserSettings, query strin // Prepare the data to pass to the template data := map[string]interface{}{ - "Results": combinedResults, - "Query": query, - "Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")), // Time for fetching - "Page": page, - "HasPrevPage": page > 1, - "HasNextPage": len(combinedResults) >= 50, - "NoResults": len(combinedResults) == 0, - "LanguageOptions": languageOptions, - "CurrentLang": settings.SearchLanguage, - "Theme": settings.Theme, - "Safe": settings.SafeSearch, - "IsThemeDark": settings.IsThemeDark, + "Results": combinedResults, + "Query": query, + "Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")), // Time for fetching + "Page": page, + "HasPrevPage": page > 1, + "HasNextPage": len(combinedResults) >= 50, + "NoResults": len(combinedResults) == 0, + "LanguageOptions": languageOptions, + "CurrentLang": settings.SearchLanguage, + "Theme": settings.Theme, + "Safe": settings.SafeSearch, + "IsThemeDark": settings.IsThemeDark, + "HardCacheEnabled": config.HardCacheEnabled, } // Render the template without measuring the time @@ -98,7 +99,8 @@ func fetchImageResults(query, safe, lang string, page int) []ImageSearchResult { for _, result := range searchResults { imageResult := result.(ImageSearchResult) - if config.HardCacheDuration > 0 { + if config.HardCacheEnabled == true { + // Generate hash from the original full-size image URL hasher := md5.New() hasher.Write([]byte(imageResult.Full)) diff --git a/init.go b/init.go index 43d6d56..584b6b8 100644 --- a/init.go +++ b/init.go @@ -1,6 +1,7 @@ package main import ( + "log" "time" ) @@ -43,8 +44,7 @@ func main() { } loadNodeConfig() - go startFileWatcher() - go checkMasterHeartbeat() + // go checkMasterHeartbeat() // Not currently used if config.AuthCode == "" { config.AuthCode = generateStrongRandomString(64) @@ -59,14 +59,17 @@ func main() { } config.PeerID = hostID - if len(config.Peers) > 0 { - time.Sleep(2 * time.Second) // Give some time for connections to establish - startElection() - } + // if len(config.Peers) > 0 { + // time.Sleep(2 * time.Second) // Give some time for connections to establish + // startElection() + // } - if config.HardCacheDuration > 0 { - config.HardCacheEnabled = true - } + // Start automatic update checker, not used now + //go checkForUpdates() + + generateOpenSearchXML(config) + + log.Println("Hard cache:", config.HardCacheEnabled) go startNodeClient() diff --git a/main.go b/main.go index 98d3d45..138f279 100755 --- a/main.go +++ b/main.go @@ -210,14 +210,7 @@ func runServer() { w.Header().Set("Content-Type", "application/opensearchdescription+xml") http.ServeFile(w, r, "static/opensearch.xml") }) - initializeTorrentSites() - - config := loadConfig() - generateOpenSearchXML(config) printMessage("Server is listening on http://localhost:%d", config.Port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", config.Port), nil)) - - // Start automatic update checker - go checkForUpdates() } diff --git a/node.go b/node.go index 43960a3..5fd247a 100644 --- a/node.go +++ b/node.go @@ -24,7 +24,6 @@ type Message struct { } func loadNodeConfig() { - config := loadConfig() authCode = config.AuthCode peers = config.Peers } diff --git a/templates/images.html b/templates/images.html index c290575..13280fd 100755 --- a/templates/images.html +++ b/templates/images.html @@ -117,7 +117,7 @@
- + @@ -228,6 +228,26 @@ + +