mira-app-server
Version:
Mira Server - standalone server application using mira-app-core
64 lines • 3.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagHandler = void 0;
const MessageHandler_1 = require("./MessageHandler");
class TagHandler extends MessageHandler_1.MessageHandler {
constructor(server, dbService, ws, message) {
super(server, dbService, ws, message);
}
async handle() {
try {
const { action, payload } = this.message;
const { data } = payload;
const libraryId = this.dbService.getLibraryId();
let result;
switch (action) {
case 'file_set':
var { fileId, tags } = data;
const tagResult = await this.dbService.setFileTags(fileId, tags);
if (tagResult.success) {
result = { fileId, tags, libraryId, old_data: tagResult.oldData };
this.server.broadcastPluginEvent('file::setTag', result);
this.server.broadcastLibraryEvent(libraryId, 'file::setTag', result);
}
break;
case 'file_get':
var { fileId } = data;
result = { tags: await this.dbService.getFileTags(fileId) };
break;
case 'all':
result = await this.dbService.getAllTags();
break;
case 'read':
result = await this.dbService.queryTag(data.query);
break;
case 'create':
result = await this.dbService.createTag(data);
this.server.broadcastPluginEvent('tag::created', { message: this.message, result, libraryId });
this.server.broadcastLibraryEvent(libraryId, 'tag::created', { result, libraryId });
break;
case 'update':
result = await this.dbService.updateTag(data.id, data);
this.server.broadcastPluginEvent('tag::updated', { message: this.message, result, libraryId });
this.server.broadcastLibraryEvent(libraryId, 'tag::updated', { id: data.id, title: data.title, libraryId });
break;
case 'delete':
var { id } = data;
if (await this.dbService.deleteTag(data.id)) {
result = { id };
this.server.broadcastPluginEvent('tag::deleted', { id, libraryId });
this.server.sendToWebsocket(this.ws, { eventName: 'file::deleted', data: { id, libraryId } });
}
break;
default:
throw new Error(`Unsupported tag action: ${action}`);
}
this.sendResponse(result);
}
catch (err) {
this.sendError(err instanceof Error ? err.message : 'Tag operation failed');
}
}
}
exports.TagHandler = TagHandler;
//# sourceMappingURL=TagHandler.js.map