This commit is contained in:
WJQSERVER 2024-10-12 03:50:34 +08:00
parent e3d56ae9b7
commit 824656f9d0
10 changed files with 191 additions and 75 deletions

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"ghproxy/config"
"os"
"strings"
)
type WhitelistConfig struct {
@ -21,12 +22,12 @@ func LoadWhitelist(cfg *config.Config) {
data, err := os.ReadFile(whitelistfile)
if err != nil {
logw("Failed to read whitelist file: %v", err)
logError("Failed to read whitelist file: %v", err)
}
err = json.Unmarshal(data, whitelist)
if err != nil {
logw("Failed to unmarshal whitelist JSON: %v", err)
logError("Failed to unmarshal whitelist JSON: %v", err)
}
}
@ -34,9 +35,18 @@ func CheckWhitelist(fullrepo string) bool {
return forRangeCheckWhitelist(whitelist.Whitelist, fullrepo)
}
func forRangeCheckWhitelist(blist []string, fullrepo string) bool {
for _, blocked := range blist {
if blocked == fullrepo {
func sliceRepoName_Whitelist(fullrepo string) (string, string) {
s := strings.Split(fullrepo, "/")
if len(s) != 2 {
return "", ""
}
return s[0], s[1]
}
func forRangeCheckWhitelist(wlist []string, fullrepo string) bool {
repoUser, _ := sliceRepoName_Whitelist(fullrepo)
for _, blocked := range wlist {
if blocked == fullrepo || (strings.HasSuffix(blocked, "/*") && strings.HasPrefix(repoUser, blocked[:len(blocked)-2])) {
return true
}
}