add sync download

This commit is contained in:
2025-05-12 04:30:17 +08:00
parent 4aec2bc231
commit eaccbf5ada
14 changed files with 219 additions and 32 deletions

33
src/command/sync/sync.ts Normal file
View File

@@ -0,0 +1,33 @@
import { program as app, Command } from '@/program.ts';
import { SyncBase } from './modules/base.ts';
import { baseURL } from '@/module/query.ts';
import { fetchLink } from '@/module/download/install.ts';
import fs from 'node:fs';
const command = new Command('sync')
.option('-d --dir <dir>')
.description('同步项目')
.action(() => {
console.log('同步项目');
});
const syncUpload = new Command('upload').description('上传项目').action(() => {
console.log('上传项目');
});
const syncDownload = new Command('download')
.option('-d --dir <dir>', '配置目录')
.description('下载项目')
.action(async () => {
console.log('下载项目');
const sync = new SyncBase({ baseURL: baseURL });
const syncList = await sync.getSyncList();
console.log(syncList);
for (const item of syncList) {
const { content } = await fetchLink(item.url, { setToken: item.auth, returnContent: true });
await sync.getDir(item.filepath, true);
fs.writeFileSync(item.filepath, content);
}
});
command.addCommand(syncUpload);
command.addCommand(syncDownload);
app.addCommand(command);