Skip to content

Commit ed2b08f

Browse files
committed
update:更新alist
1 parent d43d8bb commit ed2b08f

File tree

4 files changed

+132
-110
lines changed

4 files changed

+132
-110
lines changed

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ yarn build
4343

4444
# 更新记录
4545

46+
### 20250224
47+
48+
1.alist更新如下:
49+
增加账号密码登录
50+
sort赋值为true时强制按名称排序
51+
去除login部分,login赋值{} ,
52+
login.username赋值""或"guest"(不区分大小写)都可表示游客登录
53+
4654
### 20250123
4755

4856
1. alist支持带密码目录

Diff for: nodejs/source/ds-cat.20250224.7z

501 KB
Binary file not shown.

Diff for: nodejs/src/index.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
"server": "http://localhost:5244",
2323
"startPage": "/",
2424
"showAll": false,
25-
"search": true,
25+
"sort": true,
2626
"login": {
2727
"username": "admin",
2828
"password": "admin",

Diff for: nodejs/src/spider/pan/alist.js

+123-109
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const suffix = '-https://github.com/alist-org/alist'
66
const http = async function (url, options = {}) {
77
if (options.method == 'POST' && options.data) {
88
options.body = JSON.stringify(options.data);
9-
options.headers = Object.assign({ 'content-type': 'application/json' }, options.headers);
9+
options.headers = Object.assign({'content-type': 'application/json'}, options.headers);
1010
}
1111
const res = await req(url, options);
1212
res.json = () => (res.data ? res.data : null);
@@ -15,7 +15,7 @@ const http = async function (url, options = {}) {
1515
};
1616
['get', 'post'].forEach((method) => {
1717
http[method] = function (url, options = {}) {
18-
return http(url, Object.assign(options, { method: method.toUpperCase() }));
18+
return http(url, Object.assign(options, {method: method.toUpperCase()}));
1919
};
2020
});
2121

@@ -26,11 +26,11 @@ async function get_drives_path(tid) {
2626
const index = tid.indexOf('/', 1);
2727
const name = tid.substring(1, index);
2828
const path = tid.substring(index);
29-
return { drives: await get_drives(name), path };
29+
return {drives: await get_drives(name), path};
3030
}
3131

3232
async function get_drives(name) {
33-
const { settings, api, server } = __drives[name];
33+
const {settings, api, server} = __drives[name];
3434
if (settings.v3 == null) {
3535
//获取 设置
3636
settings.v3 = false;
@@ -59,102 +59,102 @@ async function get_drives(name) {
5959
async function init(inReq, _outResp) {
6060
inReq.server.config.alist.forEach(
6161
(item) =>
62-
(__drives[item.name] = {
63-
name: item.name,
64-
server: item.server.endsWith('/') ? item.server.substring(0, item.server.length - 1) : item.server,
65-
startPage: item.startPage || '/', //首页
66-
showAll: item.showAll === true, //默认只显示 视频和文件夹,如果想显示全部 showAll 设置true
67-
login: item.login || {},
68-
params: item.params || {},
69-
_path_param: item.params
70-
? Object.keys(item.params).sort(function (x, y) {
71-
return y.length - x.length;
72-
})
73-
: [],
74-
settings: {},
75-
api: {},
76-
getLogin() {
77-
const pass = CryptoJS.SHA256(this.login.password + suffix).toString(CryptoJS.enc.Hex);
78-
const res = {
79-
"username": this.login.username,
80-
"password": pass,
81-
"otp_code": this.login.otp_code
82-
}
83-
return res;
84-
},
85-
getParams(path) {
86-
const key = this._path_param.find((x) => path.startsWith(x));
87-
return Object.assign({}, this.params[key], { path });
88-
},
89-
async getHeaders() {
90-
const res = (await http.post(this.server + this.api.login, { data: this.getLogin() })).json();
91-
return { "Authorization": res.data.token };
92-
},
93-
async getRes(api, path) {
94-
let re;
95-
if (JSON.stringify(this.login) === "{}") re = (await http.post(this.server + api, { data: this.getParams(path) })).json();
96-
else re = (await http.post(this.server + api, { data: this.getParams(path), headers: await this.getHeaders() })).json();
97-
return re;
98-
},
99-
async getPath(path) {
100-
const res = await this.getRes(this.api.path, path);
101-
return this.settings.v3 ? res.data.content : res.data.files;
102-
},
103-
async getFile(path) {
104-
const res = await this.getRes(this.api.file, path);
105-
const data = this.settings.v3 ? res.data : res.data.files[0];
106-
if (!this.settings.v3) data.raw_url = data.url; //v2 的url和v3不一样
107-
return data;
108-
},
109-
async getOther(method, path) {
110-
const data = this.getParams(path);
111-
data.method = method;
112-
const res = await this.getRes(this.api.other, path);
113-
return res;
114-
},
115-
isFolder(data) {
116-
return data.type == 1;
117-
},
118-
isVideo(data) {
119-
//判断是否是 视频文件
120-
return this.settings.v3 ? data.type == 2 : data.type == 3;
121-
},
122-
isSubtitle(data) {
123-
if (data.type == 1) return false;
124-
const ext = ['.srt', '.ass', '.scc', '.stl', '.ttml'];
125-
return ext.some((x) => data.name.endsWith(x));
126-
},
127-
getType(data) {
128-
const isVideo = this.isVideo(data);
129-
return this.isFolder(data) ? 0 : isVideo ? 10 : 1;
130-
},
131-
getPic(data) {
132-
let pic = this.settings.v3 ? data.thumb : data.thumbnail;
133-
return pic || (this.isFolder(data) ? 'http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png' : '');
134-
},
135-
getSize(data) {
136-
let sz = data.size || 0;
137-
if (sz <= 0) return '';
138-
let filesize = '';
139-
if (sz > 1024 * 1024 * 1024 * 1024.0) {
140-
sz /= 1024 * 1024 * 1024 * 1024.0;
141-
filesize = 'TB';
142-
} else if (sz > 1024 * 1024 * 1024.0) {
143-
sz /= 1024 * 1024 * 1024.0;
144-
filesize = 'GB';
145-
} else if (sz > 1024 * 1024.0) {
146-
sz /= 1024 * 1024.0;
147-
filesize = 'MB';
148-
} else {
149-
sz /= 1024.0;
150-
filesize = 'KB';
151-
}
152-
return sz.toFixed(2) + filesize;
153-
},
154-
getRemark(_data) {
155-
return '';
156-
},
157-
})
62+
(__drives[item.name] = {
63+
name: item.name,
64+
server: item.server.endsWith('/') ? item.server.substring(0, item.server.length - 1) : item.server,
65+
startPage: item.startPage || '/', //首页
66+
showAll: item.showAll === true, //默认只显示 视频和文件夹,如果想显示全部 showAll 设置true
67+
sort: item.sort === true,
68+
login: item.login || {},
69+
params: item.params || {},
70+
_path_param: item.params
71+
? Object.keys(item.params).sort(function (x, y) {
72+
return y.length - x.length;
73+
})
74+
: [],
75+
settings: {},
76+
api: {},
77+
getLogin() {
78+
return {
79+
username: this.login.username,
80+
password: CryptoJS.SHA256(this.login.password + suffix).toString(CryptoJS.enc.Hex),
81+
otp_code: this.login.otp_code
82+
};
83+
},
84+
getParams(path) {
85+
const key = this._path_param.find((x) => path.startsWith(x));
86+
return Object.assign({}, this.params[key], {path});
87+
},
88+
async getHeaders() {
89+
return this.login.username && this.login.username.toLowerCase() !== 'guest'
90+
? {Authorization: (await http.post(this.server + this.api.login, {data: this.getLogin()})).json().data.token}
91+
: {};
92+
},
93+
async getRes(api, path) {
94+
return (await http.post(this.server + api, {
95+
data: this.getParams(path),
96+
headers: Object.keys(this.login).length ? await this.getHeaders() : {}
97+
})).json();
98+
},
99+
async getPath(path) {
100+
const res = await this.getRes(this.api.path, path);
101+
return this.settings.v3 ? res.data.content : res.data.files;
102+
},
103+
async getFile(path) {
104+
const res = await this.getRes(this.api.file, path);
105+
const data = this.settings.v3 ? res.data : res.data.files[0];
106+
if (!this.settings.v3) data.raw_url = data.url; //v2 的url和v3不一样
107+
return data;
108+
},
109+
async getOther(method, path) {
110+
const data = this.getParams(path);
111+
data.method = method;
112+
const res = await this.getRes(this.api.other, path);
113+
return res;
114+
},
115+
isFolder(data) {
116+
return data.type == 1;
117+
},
118+
isVideo(data) {
119+
//判断是否是 视频文件
120+
return this.settings.v3 ? data.type == 2 : data.type == 3;
121+
},
122+
isSubtitle(data) {
123+
if (data.type == 1) return false;
124+
const ext = ['.srt', '.ass', '.scc', '.stl', '.ttml'];
125+
return ext.some((x) => data.name.endsWith(x));
126+
},
127+
getType(data) {
128+
const isVideo = this.isVideo(data);
129+
return this.isFolder(data) ? 0 : isVideo ? 10 : 1;
130+
},
131+
getPic(data) {
132+
let pic = this.settings.v3 ? data.thumb : data.thumbnail;
133+
return pic || (this.isFolder(data) ? 'http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png' : '');
134+
},
135+
getSize(data) {
136+
let sz = data.size || 0;
137+
if (sz <= 0) return '';
138+
let filesize = '';
139+
if (sz > 1024 * 1024 * 1024 * 1024.0) {
140+
sz /= 1024 * 1024 * 1024 * 1024.0;
141+
filesize = 'TB';
142+
} else if (sz > 1024 * 1024 * 1024.0) {
143+
sz /= 1024 * 1024 * 1024.0;
144+
filesize = 'GB';
145+
} else if (sz > 1024 * 1024.0) {
146+
sz /= 1024 * 1024.0;
147+
filesize = 'MB';
148+
} else {
149+
sz /= 1024.0;
150+
filesize = 'KB';
151+
}
152+
return sz.toFixed(2) + filesize;
153+
},
154+
getRemark(_data) {
155+
return '';
156+
},
157+
})
158158
);
159159
// const deviceKey = inReq.server.prefix + '/device';
160160
// device = await inReq.server.db.getObjectDefault(deviceKey, {});
@@ -178,7 +178,7 @@ async function dir(inReq, _outResp) {
178178
if (dir === '/' || dir === '') {
179179
const result = Object.keys(__drives).map(function (n) {
180180
const d = __drives[n];
181-
return { name: d.name, path: '/' + d.name + d.startPage, type: 0, thumb: '' };
181+
return {name: d.name, path: '/' + d.name + d.startPage, type: 0, thumb: ''};
182182
});
183183
return {
184184
parent: '',
@@ -187,13 +187,24 @@ async function dir(inReq, _outResp) {
187187
list: result,
188188
};
189189
}
190-
191-
let { drives, path } = await get_drives_path(dir);
190+
let {drives, path} = await get_drives_path(dir);
192191
const id = dir.endsWith('/') ? dir : dir + '/';
193192
const list = await drives.getPath(path);
194193
let subtList = [];
195194
let videos = [];
196195
let allList = [];
196+
if (drives.sort) {
197+
list.sort((a, b) => {
198+
const numA = parseInt(a.name.match(/^\d+/) || 0);
199+
const numB = parseInt(b.name.match(/^\d+/) || 0);
200+
if (numA && numB) {
201+
return numA - numB;
202+
}
203+
if (numA) return -1;
204+
if (numB) return 1;
205+
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
206+
});
207+
}
197208
list.forEach((item) => {
198209
if (drives.isSubtitle(item)) subtList.push(item.name);
199210
const isVideo = drives.isVideo(item);
@@ -225,7 +236,7 @@ async function dir(inReq, _outResp) {
225236

226237
async function file(inReq, _outResp) {
227238
const file = inReq.body.path;
228-
let { drives, path } = await get_drives_path(file);
239+
let {drives, path} = await get_drives_path(file);
229240
const item = await drives.getFile(path);
230241
const subs = [];
231242
if (__subtitle_cache[file]) {
@@ -234,7 +245,8 @@ async function file(inReq, _outResp) {
234245
let subP = await get_drives_path(sub);
235246
const subItem = await drives.getFile(subP.path);
236247
subs.push(subItem.raw_url);
237-
} catch (error) { }
248+
} catch (error) {
249+
}
238250
}
239251
}
240252
if ((item.provider === 'AliyundriveShare2Open' || item.provider == 'AliyundriveOpen') && drives.api.other) {
@@ -247,7 +259,8 @@ async function file(inReq, _outResp) {
247259
urls.push(live.url);
248260
}
249261
}
250-
} catch (error) { }
262+
} catch (error) {
263+
}
251264
const result = {
252265
name: item.name,
253266
url: urls,
@@ -263,7 +276,8 @@ async function file(inReq, _outResp) {
263276
let url = item.raw_url;
264277
try {
265278
url = (await http.get(url)).json().data.redirect_url;
266-
} catch (error) { }
279+
} catch (error) {
280+
}
267281
const result = {
268282
name: item.name,
269283
url: url,
@@ -309,15 +323,15 @@ async function test(inReq, outResp) {
309323
dataResult.dir = resp.json();
310324
printErr(resp.json());
311325
resp = await inReq.server.inject().post(`${prefix}/file`).payload({
312-
path: '/🐉神族九帝/天翼云盘/音乐/周杰伦 - 七里香.flac',
326+
path: '/短剧/迟到的正义(39集)/23.mp4',
313327
});
314328
dataResult.file = resp.json();
315329
printErr(resp.json());
316330
return dataResult;
317331
} catch (err) {
318332
console.error(err);
319333
outResp.code(500);
320-
return { err: err.message, tip: 'check debug console output' };
334+
return {err: err.message, tip: 'check debug console output'};
321335
}
322336
}
323337

0 commit comments

Comments
 (0)