UNPKG

mira-app-server

Version:

Mira Server - standalone server application using mira-app-core

127 lines 4.98 kB
"use strict"; /** * 文件夹模块命令 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.registerFolders = registerFolders; const client_1 = require("../client"); const format_1 = require("../format"); function registerFolders(program) { const folders = program.command('folders').description('文件夹管理'); folders .command('list <libraryId>') .description('获取所有文件夹') .option('--parent-id <id>', '按父文件夹 ID 筛选', parseInt) .action(async (libraryId, options) => { try { const { client } = (0, client_1.getClient)(); let list; if (options.parentId !== undefined) { list = await client.folders().getSubFolders(libraryId, options.parentId); } else { list = await client.folders().getAll(libraryId); } const rows = list.map(f => ({ id: f.id, title: f.title, parent_id: f.parent_id ?? '', color: f.color ?? '', file_count: f.file_count ?? '', })); (0, format_1.output)(rows, () => (0, format_1.formatTable)(rows)); } catch (error) { (0, format_1.fatal)(error); } }); folders .command('create <libraryId> <title>') .description('创建文件夹') .option('--parent-id <id>', '父文件夹 ID', parseInt) .option('--color <color>', '颜色(数字)', parseInt) .option('--desc <desc>', '描述') .action(async (libraryId, title, options) => { try { const { client } = (0, client_1.getClient)(); const res = await client.folders().createFolder(libraryId, title, options.parentId, options.color, options.desc); (0, format_1.success)(`文件夹已创建: ${title}`); (0, format_1.output)(res, () => (0, format_1.formatKeyValue)(res)); } catch (error) { (0, format_1.fatal)(error); } }); folders .command('update <libraryId> <id>') .description('更新文件夹') .option('--title <title>', '标题') .option('--parent-id <id>', '父文件夹 ID', parseInt) .option('--color <color>', '颜色(数字)', parseInt) .option('--desc <desc>', '描述') .action(async (libraryId, id, options) => { try { const { client } = (0, client_1.getClient)(); const updates = {}; if (options.title !== undefined) updates.title = options.title; if (options.parentId !== undefined) updates.parent_id = options.parentId; if (options.color !== undefined) updates.color = options.color; if (options.desc !== undefined) updates.description = options.desc; const res = await client.folders().updateFolder(libraryId, id, updates); (0, format_1.success)(`文件夹 ${id} 已更新`); (0, format_1.output)(res); } catch (error) { (0, format_1.fatal)(error); } }); folders .command('delete <libraryId> <id>') .alias('rm') .description('删除文件夹') .option('--delete-files', '同时删除文件夹内的文件') .action(async (libraryId, id, options) => { try { const { client } = (0, client_1.getClient)(); const res = await client.folders().deleteFolder(libraryId, id, options.deleteFiles); (0, format_1.success)(`文件夹 ${id} 已删除`); (0, format_1.output)(res); } catch (error) { (0, format_1.fatal)(error); } }); folders .command('move <libraryId> <fileId> <folderId>') .description('将文件移动到指定文件夹') .action(async (libraryId, fileId, folderId) => { try { const { client } = (0, client_1.getClient)(); const res = await client.folders().moveFileToFolder(libraryId, fileId, folderId); (0, format_1.success)(`文件 ${fileId} 已移动到文件夹 ${folderId}`); (0, format_1.output)(res); } catch (error) { (0, format_1.fatal)(error); } }); folders .command('remove <libraryId> <fileId>') .description('将文件移出文件夹(移到根目录)') .action(async (libraryId, fileId) => { try { const { client } = (0, client_1.getClient)(); const res = await client.folders().removeFileFromFolder(libraryId, fileId); (0, format_1.success)(`文件 ${fileId} 已移到根目录`); (0, format_1.output)(res); } catch (error) { (0, format_1.fatal)(error); } }); } //# sourceMappingURL=folders.js.map