9a42dd2ab1
- Remove global ProxyEnabled() logic from httpclient - Each source now explicitly chooses client at import time: - flare client: for JS-rendering/cloudflare sources - normal httpclient: for REST API sources - Updated 29 base sources based on Kotlin reference (network.cloudflareClient)
86 lines
2.1 KiB
Go
Executable File
86 lines
2.1 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"goyomi/internal/config"
|
|
"goyomi/internal/db"
|
|
_ "goyomi/internal/registry"
|
|
_ "goyomi/sources/all/hentaihand"
|
|
_ "goyomi/sources/all/kemono"
|
|
_ "goyomi/sources/all/mangataro"
|
|
_ "goyomi/sources/en/bakkin"
|
|
_ "goyomi/sources/en/divascans"
|
|
_ "goyomi/sources/en/guya"
|
|
_ "goyomi/sources/en/hijalascans"
|
|
_ "goyomi/sources/en/kaizenscan"
|
|
_ "goyomi/sources/en/kewnscans"
|
|
_ "goyomi/sources/en/lunatoons"
|
|
_ "goyomi/sources/en/mistscans"
|
|
_ "goyomi/sources/en/necroscans"
|
|
_ "goyomi/sources/en/nyanukafe"
|
|
_ "goyomi/sources/en/nyxscans"
|
|
_ "goyomi/sources/en/orionscans"
|
|
_ "goyomi/sources/en/renascans"
|
|
_ "goyomi/sources/en/sanascans"
|
|
_ "goyomi/sources/en/sirenscans"
|
|
_ "goyomi/sources/en/vanillascans"
|
|
)
|
|
|
|
func main() {
|
|
cfg := config.Load()
|
|
|
|
ctx := context.Background()
|
|
database, err := db.Open(ctx)
|
|
if err != nil {
|
|
log.Fatalf("db: %v", err)
|
|
}
|
|
defer database.Close()
|
|
|
|
// Initialize config manager
|
|
config.InitConfigManager(database.Queries)
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintln(w, "ok")
|
|
})
|
|
|
|
// Config endpoints
|
|
mux.HandleFunc("/api/config/flaresolverr", handleFlareSolverrConfig)
|
|
|
|
log.Printf("listening on %s", cfg.Addr)
|
|
if err := http.ListenAndServe(cfg.Addr, mux); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func handleFlareSolverrConfig(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
switch r.Method {
|
|
case "GET":
|
|
enabled := config.IsFlareSolverrProxyEnabled()
|
|
json.NewEncoder(w).Encode(map[string]bool{"flaresolverr_proxy": enabled})
|
|
|
|
case "POST":
|
|
var req struct {
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
http.Error(w, "invalid request", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if err := config.SetFlareSolverrProxyEnabled(ctx, req.Enabled); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
json.NewEncoder(w).Encode(map[string]bool{"flaresolverr_proxy": req.Enabled})
|
|
|
|
default:
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
}
|
|
} |