ALWAYS_SKIP_IDS -> ALWAYS_SKIP_MAL_IDS

pull/5/head v0.1.1
Gabe Farrell 8 months ago
parent ae664ab6b3
commit 68c6e02618

@ -20,7 +20,7 @@ curl "http://localhost:3333/anime?type=tv&status=airing&order_by=popularity&sort
## Environment ## Environment
One configuration environment variable is supported: One configuration environment variable is supported:
- `ALWAYS_SKIP_IDS`: Comma-separated list of MyAnimeList IDs to always skip. These do not count towards the return limit. - `ALWAYS_SKIP_MAL_IDS`: Comma-separated list of MyAnimeList IDs to always skip. These do not count towards the return limit.
## Docker Compose ## Docker Compose
```yaml ```yaml
@ -31,7 +31,7 @@ services:
ports: ports:
- 3333:3333 - 3333:3333
environment: environment:
- ALWAYS_SKIP_IDS=12345,67890 # Comma-separated - ALWAYS_SKIP_MAL_IDS=12345,67890 # Comma-separated
restart: unless-stopped restart: unless-stopped
``` ```

@ -44,24 +44,24 @@ func main() {
log.Println("Building Anime ID Associations...") log.Println("Building Anime ID Associations...")
var malToTvdb = new(ConcurrentMap) var malToTvdb = new(ConcurrentMap)
buildIdMap(malToTvdb) buildIdMap(malToTvdb)
permaSkipStr := os.Getenv("ALWAYS_SKIP_IDS") permaSkipMalStr := os.Getenv("ALWAYS_SKIP_MAL_IDS")
permaSkipIds := strings.Split(permaSkipStr, ",") permaSkipMalIds := strings.Split(permaSkipMalStr, ",")
if permaSkipStr != "" { if permaSkipMalStr != "" {
log.Printf("Always skipping: %v\n", permaSkipIds) log.Printf("Always skipping: %v\n", permaSkipMalIds)
} }
http.HandleFunc("/anime", handleAnimeSearch(malToTvdb, permaSkipIds)) http.HandleFunc("/anime", handleAnimeSearch(malToTvdb, permaSkipMalIds))
log.Println("Listening on :3333") log.Println("Listening on :3333")
log.Fatal(http.ListenAndServe(":3333", nil)) log.Fatal(http.ListenAndServe(":3333", nil))
} }
func handleAnimeSearch(malToTvdb *ConcurrentMap, permaSkipIds []string) func(w http.ResponseWriter, r *http.Request) { func handleAnimeSearch(malToTvdb *ConcurrentMap, permaSkipMalIds []string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s?%s", r.Method, r.URL.Path, r.URL.RawQuery) log.Printf("%s %s?%s", r.Method, r.URL.Path, r.URL.RawQuery)
if time.Since(lastBuiltAnimeIdList) > 24*time.Hour { if time.Since(lastBuiltAnimeIdList) > 24*time.Hour {
log.Println("Anime ID association table expired, building new table...") log.Println("Anime ID association table expired, building new table...")
buildIdMap(malToTvdb) buildIdMap(malToTvdb)
} }
search, err := getAnimeSearch(malToTvdb, permaSkipIds, r) search, err := getAnimeSearch(malToTvdb, permaSkipMalIds, r)
if err != nil { if err != nil {
w.WriteHeader(500) w.WriteHeader(500)
} else { } else {
@ -70,7 +70,7 @@ func handleAnimeSearch(malToTvdb *ConcurrentMap, permaSkipIds []string) func(w h
} }
} }
func getAnimeSearch(malToTvdb *ConcurrentMap, permaSkipIds []string, r *http.Request) (string, error) { func getAnimeSearch(malToTvdb *ConcurrentMap, permaSkipMalIds []string, r *http.Request) (string, error) {
q := r.URL.Query() q := r.URL.Query()
limit, err := strconv.Atoi(q.Get("limit")) limit, err := strconv.Atoi(q.Get("limit"))
@ -108,7 +108,7 @@ func getAnimeSearch(malToTvdb *ConcurrentMap, permaSkipIds []string, r *http.Req
log.Printf("MyAnimeList ID %d (%s a.k.a. %s) is a duplicate, skipping...\n", item.MalId, item.Title, item.TitleEnglish) log.Printf("MyAnimeList ID %d (%s a.k.a. %s) is a duplicate, skipping...\n", item.MalId, item.Title, item.TitleEnglish)
continue continue
} }
if slices.Contains(permaSkipIds, strconv.Itoa(item.MalId)) { if slices.Contains(permaSkipMalIds, strconv.Itoa(item.MalId)) {
log.Printf("MyAnimeList ID %d (%s a.k.a. %s) is set to always skip, skipping...\n", item.MalId, item.Title, item.TitleEnglish) log.Printf("MyAnimeList ID %d (%s a.k.a. %s) is set to always skip, skipping...\n", item.MalId, item.Title, item.TitleEnglish)
continue continue
} }

Loading…
Cancel
Save