mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Convert routes/api/export
This commit is contained in:
parent
e451237361
commit
952c3cc12f
@ -1,14 +1,16 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const zipExportService = require('../../services/export/zip');
|
import zipExportService = require('../../services/export/zip');
|
||||||
const singleExportService = require('../../services/export/single');
|
import singleExportService = require('../../services/export/single');
|
||||||
const opmlExportService = require('../../services/export/opml');
|
import opmlExportService = require('../../services/export/opml');
|
||||||
const becca = require('../../becca/becca');
|
import becca = require('../../becca/becca');
|
||||||
const TaskContext = require('../../services/task_context');
|
import TaskContext = require('../../services/task_context');
|
||||||
const log = require('../../services/log');
|
import log = require('../../services/log');
|
||||||
const NotFoundError = require('../../errors/not_found_error');
|
import NotFoundError = require('../../errors/not_found_error');
|
||||||
|
import { Request, Response } from 'express';
|
||||||
|
import ValidationError = require('../../errors/validation_error');
|
||||||
|
|
||||||
function exportBranch(req, res) {
|
function exportBranch(req: Request, res: Response) {
|
||||||
const {branchId, type, format, version, taskId} = req.params;
|
const {branchId, type, format, version, taskId} = req.params;
|
||||||
const branch = becca.getBranch(branchId);
|
const branch = becca.getBranch(branchId);
|
||||||
|
|
||||||
@ -29,6 +31,9 @@ function exportBranch(req, res) {
|
|||||||
zipExportService.exportToZip(taskContext, branch, format, res);
|
zipExportService.exportToZip(taskContext, branch, format, res);
|
||||||
}
|
}
|
||||||
else if (type === 'single') {
|
else if (type === 'single') {
|
||||||
|
if (format !== "html" && format !== "markdown") {
|
||||||
|
throw new ValidationError("Invalid export type.");
|
||||||
|
}
|
||||||
singleExportService.exportSingleNote(taskContext, branch, format, res);
|
singleExportService.exportSingleNote(taskContext, branch, format, res);
|
||||||
}
|
}
|
||||||
else if (format === 'opml') {
|
else if (format === 'opml') {
|
||||||
@ -38,7 +43,7 @@ function exportBranch(req, res) {
|
|||||||
throw new NotFoundError(`Unrecognized export format '${format}'`);
|
throw new NotFoundError(`Unrecognized export format '${format}'`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e: any) {
|
||||||
const message = `Export failed with following error: '${e.message}'. More details might be in the logs.`;
|
const message = `Export failed with following error: '${e.message}'. More details might be in the logs.`;
|
||||||
taskContext.reportError(message);
|
taskContext.reportError(message);
|
||||||
|
|
@ -36,7 +36,7 @@ const syncApiRoute = require('./api/sync');
|
|||||||
const loginApiRoute = require('./api/login.js');
|
const loginApiRoute = require('./api/login.js');
|
||||||
const recentNotesRoute = require('./api/recent_notes.js');
|
const recentNotesRoute = require('./api/recent_notes.js');
|
||||||
const appInfoRoute = require('./api/app_info');
|
const appInfoRoute = require('./api/app_info');
|
||||||
const exportRoute = require('./api/export.js');
|
const exportRoute = require('./api/export');
|
||||||
const importRoute = require('./api/import.js');
|
const importRoute = require('./api/import.js');
|
||||||
const setupApiRoute = require('./api/setup.js');
|
const setupApiRoute = require('./api/setup.js');
|
||||||
const sqlRoute = require('./api/sql');
|
const sqlRoute = require('./api/sql');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user