-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
68 lines (60 loc) · 1.66 KB
/
Copy pathmain.js
File metadata and controls
68 lines (60 loc) · 1.66 KB
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
66
67
68
const { parseCliArgs, printUsage } = require("./src/cli");
const { loadConfig } = require("./src/config");
const {
getTenantAccessToken,
getFilesInFolder,
} = require("./src/feishu-client");
const { batchProcessFiles } = require("./src/export-service");
const {
buildRunSummary,
printFileList,
printRunSummary,
} = require("./src/reporting");
async function main() {
try {
const options = parseCliArgs(process.argv.slice(2));
if (options.help) {
printUsage();
return;
}
const config = loadConfig();
console.log("正在获取 tenant_access_token...");
console.log("APP_ID:", config.appId ? "已设置" : "未设置");
console.log("APP_SECRET:", config.appSecret ? "已设置" : "未设置");
const tenantAccessToken = await getTenantAccessToken(
config.appId,
config.appSecret,
);
console.log("获取 tenant_access_token 成功");
console.log("开始获取文件清单...");
const files = await getFilesInFolder(tenantAccessToken, config.folderToken);
if (options.listOnly) {
printFileList(files);
printRunSummary(
buildRunSummary({
files,
results: [],
downloadPath: config.downloadPath,
}),
);
return;
}
const results = await batchProcessFiles({
tenantAccessToken,
files,
downloadPath: config.downloadPath,
pollIntervalMs: config.pollIntervalMs,
});
printRunSummary(
buildRunSummary({
files,
results,
downloadPath: config.downloadPath,
}),
);
} catch (error) {
console.error("执行失败:", error.message);
process.exitCode = 1;
}
}
main();