@@ -11,14 +11,15 @@ var imgHost = "https://raw.githubusercontent.com/Cheshire-Nya/easy-random-image-
1111//用github作为图库应按照此格式"https://raw.githubusercontent.com/<github用户名>/<仓库名>/<分支名>"
1212var defaultPath = '/' ; //现在是仓库根目录(换其他文件夹格式`'/<文件夹名>'`)
1313//访问的url路径为`/api`或`/api/`时抽图的文件夹
14- var redirectProxy = 2 ;
14+ var redirectProxy = 1 ;
1515//type=302时返回的链接是否是经过代理的,0 不代理(返回github原链接),1 worker代理,2 ghproxy代理
1616var maxValues = {
1717 "/" : 2 , //(defaultPath和对应图片数)现在是仓库根目录,对应2张图,前部需要有`/`
18- "示例图 " : 10 , //示例图
19- //中文路径
18+ "demoimg1 " : 10 , //示例图
19+ //路径1
2020 "demoimg" : 5 , //demoimg
21- //英文路径
21+ //路径2
22+ //文件夹名需为纯英文字符,中文在链接中会被转码然后出奇奇怪怪的问题
2223 //其他要抽图的文件夹和对应图片数,不用在名称前加`/`
2324 //其他路径下同理,只需要这样相同格式多写一条键值对即可`'<文件夹名>': <数值>,`
2425}
@@ -79,7 +80,7 @@ function extractSearch(urlSearch, request) {
7980 else return error ( ) ;
8081 }
8182 else if ( cats ) {
82- let allCatsValid = true ;
83+ /*多余的错误逻辑
8384 for (let i = 0; i < cats.length; i++) {
8485 if (!(cats[i] in maxValues) || maxValues[cats[i]] < 1) {
8586 allCatsValid = false;
@@ -88,38 +89,36 @@ function extractSearch(urlSearch, request) {
8889 maxValues[cats[i]]--;
8990 }
9091 }
91- if ( allCatsValid ) {
92- if ( id ) {
93- let imgName = id ;
94- let imgPath = cats [ Math . floor ( Math . random ( ) * cats . length ) ] ;
95- if ( type === 'json' ) {
96- return typejson ( imgPath , imgName , request ) ;
97- }
98- else if ( ! searchParams . has ( 'type' ) ) {
99- return prescriptive ( imgPath , imgName ) ;
100- }
101- else {
102- return error ( ) ;
103- }
92+ */
93+ if ( id ) {
94+ let imgName = id ;
95+ let imgPath = cats ;
96+ if ( type === 'json' ) {
97+ return typejson ( imgPath , imgName , request ) ;
98+ }
99+ else if ( ! searchParams . has ( 'type' ) ) {
100+ return prescriptive ( imgPath , imgName ) ;
101+ }
102+ else {
103+ return error ( ) ;
104+ }
105+ }
106+ else if ( ! searchParams . has ( 'id' ) ) {
107+ let imgPath = cats [ Math . floor ( Math . random ( ) * cats . length ) ] ;
108+ if ( type === '302' ) {
109+ return redirect ( imgPath , request ) ;
104110 }
105- else if ( ! searchParams . has ( 'id' ) ) {
106- let imgPath = cats [ Math . floor ( Math . random ( ) * cats . length ) ] ;
107- if ( type === '302' ) {
108- return redirect ( imgPath , request ) ;
109- }
110- else if ( type === 'json' ) {
111- let max = maxValues [ imgPath ] ;
112- let imgName = Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ;
113- return typejson ( imgPath , imgName , request ) ;
114- }
115- else if ( ! searchParams . has ( 'type' ) ) {
116- return random ( imgPath ) ;
117- }
118- else return error ( ) ;
119- }
111+ else if ( type === 'json' ) {
112+ let max = maxValues [ imgPath ] ;
113+ let imgName = Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ;
114+ return typejson ( imgPath , imgName , request ) ;
115+ }
116+ else if ( ! searchParams . has ( 'type' ) ) {
117+ return random ( imgPath ) ;
118+ }
120119 else return error ( ) ;
121- }
122- else return error ( ) ; //不支持的分类
120+ }
121+ else return error ( ) ;
123122 }
124123 else return error ( ) ;
125124}
0 commit comments