File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "encoding/base64"
66 "encoding/json"
77 "fmt"
8+ "hash/fnv"
89 "io"
910 "math/rand"
1011 "net/http"
@@ -955,10 +956,14 @@ func DeleteHole(c *fiber.Ctx) error {
955956func GenerateSummary (c * fiber.Ctx ) error {
956957 uid , _ := common .GetUserID (c )
957958 if config .Config .WhiteListUserIds != nil && ! slices .Contains (config .Config .WhiteListUserIds , uid ) {
958- return c .Status (404 ).JSON (fiber.Map {
959- "code" : 404 ,
960- "message" : "Cannot GET " + c .Path (),
961- })
959+ h := fnv .New32a ()
960+ h .Write ([]byte (strconv .Itoa (uid )))
961+ if int (h .Sum32 ())% 100 >= int (100 * config .Config .WhiteListRate ) {
962+ return c .Status (404 ).JSON (fiber.Map {
963+ "code" : 404 ,
964+ "message" : "Cannot GET " + c .Path (),
965+ })
966+ }
962967 }
963968 id , _ := c .ParamsInt ("id" )
964969 forceRefresh := c .QueryBool ("force_refresh" )
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ var Config struct {
6464 SummaryReplyBoundary3 int `env:"SUMMARY_REPLY_BOUNDARY_1" envDefault:"1000"`
6565 SummaryLogLimit int `env:"SUMMARY_LOG_LIMIT" envDefault:"1000"`
6666 WhiteListUserIds []int `env:"WHITE_LIST_USER_IDS"`
67+ WhiteListRate float32 `env:"WHITE_LIST_RATE" envDefault:"1"`
6768 MaxSummaryFloors int `env:"MAX_FLOORS_PER_HOLE" envDefault:"50"`
6869}
6970
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package models
22
33import (
44 "fmt"
5+ "strconv"
56 "time"
67
78 "golang.org/x/exp/maps"
@@ -13,6 +14,7 @@ import (
1314 "gorm.io/gorm/clause"
1415 "gorm.io/plugin/dbresolver"
1516
17+ "hash/fnv"
1618 "treehole_next/config"
1719 "treehole_next/utils"
1820)
@@ -293,6 +295,13 @@ func (holes Holes) Preprocess(c *fiber.Ctx) error {
293295
294296 // for users in whitelist or whitelist is empty, AISummaryAvailable is true,
295297 hole .AISummaryAvailable = config .Config .WhiteListUserIds == nil || slices .Contains (config .Config .WhiteListUserIds , uid )
298+ if ! hole .AISummaryAvailable {
299+ h := fnv .New32a ()
300+ h .Write ([]byte (strconv .Itoa (uid )))
301+ if int (h .Sum32 ())% 100 < int (100 * config .Config .WhiteListRate ) {
302+ hole .AISummaryAvailable = true
303+ }
304+ }
296305 hole .AISummaryAvailable = hole .AISummaryAvailable && ! (hole .Locked || hole .Hidden || hole .Frozen )
297306 for _ , tag := range hole .Tags {
298307 if len (tag .Name ) > 0 && tag .Name [0 ] == '*' {
You can’t perform that action at this time.
0 commit comments