mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
24w15c
This commit is contained in:
parent
e3d56ae9b7
commit
824656f9d0
10 changed files with 191 additions and 75 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue