Skip to content

Commit

Permalink
feature/legacy random_release wrapper (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
MindHunter86 authored Aug 11, 2024
2 parents f5d8bac + e58a2e3 commit 8ba5c7e
Show file tree
Hide file tree
Showing 14 changed files with 534 additions and 34 deletions.
74 changes: 74 additions & 0 deletions cmd/alice/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func flagsInitialization() []cli.Flag {
Category: "Syslog settings",
Usage: "optional setting; more information in syslog RFC",
Value: "",
Hidden: true,
},

// fiber-server settings
Expand All @@ -63,6 +64,7 @@ func flagsInitialization() []cli.Flag {
if enabled, the application will need to be ran
through a shell because prefork mode sets environment variables;
EXPERIMENTAL! USE CAREFULLY!`,
Hidden: true,
DisableDefaultText: true,
},
&cli.DurationFlag{
Expand Down Expand Up @@ -103,28 +105,33 @@ func flagsInitialization() []cli.Flag {
&cli.BoolFlag{
Name: "limiter-enable",
Category: "Limiter settings",
Hidden: true,
DisableDefaultText: true,
},
&cli.BoolFlag{
Name: "limiter-use-bbolt",
Category: "Limiter settings",
Usage: "use bbolt key\value file database instead of memory database",
Hidden: true,
DisableDefaultText: true,
},
&cli.BoolFlag{
Name: "limiter-bbolt-reset",
Category: "Limiter settings",
Usage: "if bbolt used as storage, reset all limited IPs on startup",
Hidden: true,
DisableDefaultText: true,
},
&cli.IntFlag{
Name: "limiter-max-req",
Category: "Limiter settings",
Hidden: true,
Value: 200,
},
&cli.DurationFlag{
Name: "limiter-records-duration",
Category: "Limiter settings",
Hidden: true,
Value: 5 * time.Minute,
},

Expand Down Expand Up @@ -262,6 +269,7 @@ func flagsInitialization() []cli.Flag {
Category: "GeoIP",
Usage: `sha256 helps to check database contents of the mmdb database
and avoid unnecessary requests to MaxMind CDN`,
DisableDefaultText: true,
},
&cli.DurationFlag{
Name: "geoip-update-frequency",
Expand All @@ -283,11 +291,77 @@ func flagsInitialization() []cli.Flag {
DisableDefaultText: true,
},

// anilibria release randomizer
&cli.BoolFlag{
Name: "randomizer-enable",
Category: "Release randomizer",
Usage: `alice has its own function for randomizing releases; it optimizes random_release (apiv1)
and public/random.php (www site), ensuring the high performance of these methods;
if disabled, all reuqests will be cached in shared cache pool with another methods`,
},
&cli.StringFlag{
Name: "randomizer-redis-host",
Category: "Release randomizer",
Value: "127.0.0.1:6279",
},
&cli.StringFlag{
Name: "randomizer-redis-password",
Category: "Release randomizer",
Value: "",
},
&cli.IntFlag{
Name: "randomizer-redis-database",
Category: "Release randomizer",
Value: 0,
},
&cli.StringFlag{
Name: "randomizer-releaseskey",
Category: "Release randomizer",
Usage: "the feature of the legacy",
Value: "apiInfo",
},
&cli.DurationFlag{
Name: "randomizer-update-frequency",
Category: "Release randomizer",
Value: 1 * time.Minute,
},
&cli.DurationFlag{
Name: "randomizer-update-frequency-onerror",
Category: "Release randomizer",
Value: 1 * time.Minute,
Hidden: true,
},
&cli.IntFlag{
Name: "redis-client-maxretries",
Category: "Release randomizer",
Hidden: true,
Value: 3,
},
&cli.DurationFlag{
Name: "redis-client-dialtimeout",
Category: "Release randomizer",
Hidden: true,
Value: 5 * time.Second,
},
&cli.DurationFlag{
Name: "redis-client-readtimeout",
Category: "Release randomizer",
Hidden: true,
Value: 3 * time.Second,
},
&cli.DurationFlag{
Name: "redis-client-writetimeout",
Category: "Release randomizer",
Hidden: true,
Value: 3 * time.Second,
},

// custom settings
&cli.BoolFlag{
Name: "anilibrix-cmpb-mode",
Category: "Feature flags",
Usage: "avoiding 'Cannot POST //public/api/index.php' errors with req rewrite",
Hidden: true,
DisableDefaultText: true,
},
}
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/klauspost/compress v1.17.9
github.com/mailru/easyjson v0.7.7
github.com/oschwald/maxminddb-golang v1.13.1
github.com/redis/go-redis/v9 v9.6.1
github.com/rs/zerolog v1.33.0
github.com/urfave/cli/v2 v2.27.3
github.com/valyala/bytebufferpool v1.0.0
Expand All @@ -18,7 +19,9 @@ require (

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.3 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3b
github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
Expand Down Expand Up @@ -37,6 +43,8 @@ github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
Expand Down
16 changes: 16 additions & 0 deletions internal/anilibria/anilibria.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package anilibria

type (
Releases map[string]*Release
Release struct {
Id uint
Code string
BlockedInfo *ReleaseBlockedInfo `json:"blockedInfo"`
}
ReleaseBlockedInfo struct {
Blocked bool
Reason string
IsBlockedInGeo []string `json:"is_blocked_in_geo"`
IsBlockedByCopyrights bool `json:"is_blocked_by_copyrights"`
}
)
Loading

0 comments on commit 8ba5c7e

Please sign in to comment.