-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_aliyun_auto_clear.js
65 lines (58 loc) · 1.91 KB
/
s_aliyun_auto_clear.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
阿里云盘清空转存目录
cron 4 38 5 * * * s_aliyun_auto_clear.js
*/
/**
*
* Created by wxun on 2023/3/17 18:00.
* description: s_aliyun_auto_clear 阿里云盘自动清空指定目录, 用于xiaoya laist转存观看清空
*/
const { Env } = require("./utils/ql");
const $ = new Env("阿里云盘清空转存目录");
const notify = $.isNode() ? require("./utils/sendNotify") : "";
const { AliyunDrive } = require("./utils/aliyun");
const { fileSizeUnit } = require("./utils/utils");
(async () => {
const client = new AliyunDrive();
const refreshTokenArray = await client.getRefreshToken();
const folderIds = await client.getQlEnvs("aliyunClearFolder");
const message = [];
let index = 1;
for (const info of refreshTokenArray) {
let remarks = info.remarks || `账号${index}`;
try {
const { nick_name, refresh_token } = await client.updateAccesssToken(
info.value || info,
remarks
);
if (nick_name && nick_name !== remarks)
remarks = `${nick_name}(${remarks})`;
await client.updateQlEnv(info, refresh_token, remarks);
let sendMessage = remarks + "\n";
const cc = async (id) => {
const clearRes = await client.clearFolder(id);
const rt = `已删除目录【${id}】的${
clearRes.responses?.length || 0
}个文件, 共${
fileSizeUnit(client.sumFilesSize(clearRes.files))
}\n`;
sendMessage = sendMessage + rt;
};
for (const o of folderIds) {
const ids = String(o.value || o).split(",");
for (let i = 0; i < ids.length; i++) {
await cc(ids[i]);
}
}
console.log(sendMessage);
console.log("\n");
message.push(sendMessage);
} catch (e) {
console.log(e);
console.log("\n");
message.push(e);
}
index++;
}
await notify.sendNotify(`阿里云盘alist转存目录清空`, message.join("\n"));
})();