mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-17 08:38:24 +00:00
fix: add user to blacklist when it's banned or deleted, and make deletion soft (close #473, close #791)
This commit is contained in:
29
common/blacklist/main.go
Normal file
29
common/blacklist/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package blacklist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var blackList sync.Map
|
||||
|
||||
func init() {
|
||||
blackList = sync.Map{}
|
||||
}
|
||||
|
||||
func userId2Key(id int) string {
|
||||
return fmt.Sprintf("userid_%d", id)
|
||||
}
|
||||
|
||||
func BanUser(id int) {
|
||||
blackList.Store(userId2Key(id), true)
|
||||
}
|
||||
|
||||
func UnbanUser(id int) {
|
||||
blackList.Delete(userId2Key(id))
|
||||
}
|
||||
|
||||
func IsUserBanned(id int) bool {
|
||||
_, ok := blackList.Load(userId2Key(id))
|
||||
return ok
|
||||
}
|
Reference in New Issue
Block a user