feat: Anilist support

This commit is contained in:
Gabe Farrell 2025-04-04 20:54:47 -04:00
parent ec6c1cc0e0
commit cdd7b67003
8 changed files with 541 additions and 143 deletions

26
middleware.go Normal file
View file

@ -0,0 +1,26 @@
package main
import (
"log"
"net/http"
"time"
)
func newRebuildStaleIdMapMiddleware(idMap *ConcurrentMap) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if time.Since(lastBuiltAnimeIdList) > 24*time.Hour {
log.Println("Anime ID association table expired, building new table...")
buildIdMap(idMap)
}
next.ServeHTTP(w, r)
})
}
}
func loggerMiddleware(next http.Handler) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s?%s", r.Method, r.URL.Path, r.URL.RawQuery)
next.ServeHTTP(w, r)
})
}