mira-app-server
Version:
Mira Server - standalone server application using mira-app-core
118 lines • 4.41 kB
JavaScript
;
/**
* 标签模块命令
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerTags = registerTags;
const client_1 = require("../client");
const format_1 = require("../format");
function registerTags(program) {
const tags = program.command('tags').description('标签管理');
tags
.command('list <libraryId>')
.description('获取所有标签')
.action(async (libraryId) => {
try {
const { client } = (0, client_1.getClient)();
const list = await client.tags().getAll(libraryId);
const rows = list.map(t => ({
id: t.id,
title: t.title,
parent_id: t.parent_id ?? '',
color: t.color ?? '',
file_count: t.file_count ?? '',
}));
(0, format_1.output)(rows, () => (0, format_1.formatTable)(rows));
}
catch (error) {
(0, format_1.fatal)(error);
}
});
tags
.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.tags().createTag(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);
}
});
tags
.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.tags().updateTag(libraryId, id, updates);
(0, format_1.success)(`标签 ${id} 已更新`);
(0, format_1.output)(res);
}
catch (error) {
(0, format_1.fatal)(error);
}
});
tags
.command('delete <libraryId> <id>')
.alias('rm')
.description('删除标签')
.action(async (libraryId, id) => {
try {
const { client } = (0, client_1.getClient)();
const res = await client.tags().deleteTag(libraryId, id);
(0, format_1.success)(`标签 ${id} 已删除`);
(0, format_1.output)(res);
}
catch (error) {
(0, format_1.fatal)(error);
}
});
tags
.command('file-set <libraryId> <fileId> <tags...>')
.description('为文件设置标签(tags 为名称或 ID)')
.action(async (libraryId, fileId, tagList) => {
try {
const { client } = (0, client_1.getClient)();
const res = await client.tags().addTagsToFile(libraryId, fileId, tagList);
(0, format_1.success)(`文件 ${fileId} 标签已设置: ${tagList.join(', ')}`);
(0, format_1.output)(res);
}
catch (error) {
(0, format_1.fatal)(error);
}
});
tags
.command('file-get <libraryId> <fileId>')
.description('获取文件的标签')
.action(async (libraryId, fileId) => {
try {
const { client } = (0, client_1.getClient)();
const res = await client.tags().getFileTagList(libraryId, fileId);
(0, format_1.output)(res);
}
catch (error) {
(0, format_1.fatal)(error);
}
});
}
//# sourceMappingURL=tags.js.map