2929 regexp .MustCompile (`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+$` ),
3030 regexp .MustCompile (`^(?:https?://)?gist\.github(?:usercontent|)\.com/([^/]+)/.+?/.+` ),
3131 regexp .MustCompile (`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*` ),
32+ regexp .MustCompile (`^(?:https?://)?huggingface\.co/spaces/([^/]+)/([^/]+).*` ),
33+ regexp .MustCompile (`^(?:https?://)?cdn-lfs\.hf\.co/repos/.+` ),
34+ regexp .MustCompile (`^(?:https?://)?download\.docker\.com/.+\.(tgz|zip)$` ),
3235 }
3336 httpClient * http.Client
3437 config * Config
@@ -66,7 +69,7 @@ func main() {
6669 loadConfig ()
6770 }
6871 }()
69- // 前端访问路径,默认根路径
72+ // 前端访问路径,默认根路径
7073 router .Static ("/" , "./public" )
7174 router .NoRoute (handler )
7275
@@ -84,22 +87,22 @@ func handler(c *gin.Context) {
8487 }
8588
8689 if ! strings .HasPrefix (rawPath , "http" ) {
87- c .String (http .StatusForbidden , "Invalid input. " )
90+ c .String (http .StatusForbidden , "无效输入 " )
8891 return
8992 }
9093
9194 matches := checkURL (rawPath )
9295 if matches != nil {
9396 if len (config .WhiteList ) > 0 && ! checkList (matches , config .WhiteList ) {
94- c .String (http .StatusForbidden , "Forbidden by white list. " )
97+ c .String (http .StatusForbidden , "不在白名单内,限制访问。 " )
9598 return
9699 }
97100 if len (config .BlackList ) > 0 && checkList (matches , config .BlackList ) {
98- c .String (http .StatusForbidden , "Forbidden by black list. " )
101+ c .String (http .StatusForbidden , "黑名单限制访问 " )
99102 return
100103 }
101104 } else {
102- c .String (http .StatusForbidden , "Invalid input. " )
105+ c .String (http .StatusForbidden , "无效输入 " )
103106 return
104107 }
105108
@@ -202,9 +205,10 @@ func checkURL(u string) []string {
202205 return nil
203206}
204207
208+ // 匹配用户名、仓库名,或者用户名/仓库名
205209func checkList (matches , list []string ) bool {
206210 for _ , item := range list {
207- if strings .HasPrefix (matches [0 ], item ) {
211+ if strings .HasPrefix (matches [0 ], item ) || strings . HasPrefix ( matches [ 1 ], item ) || strings . HasPrefix ( matches [ 0 ] + "/" + matches [ 1 ], item ) {
208212 return true
209213 }
210214 }
0 commit comments