mirror of
https://github.com/zadam/trilium.git
synced 2026-08-26 21:55:46 +02:00
chore(import): integrate import route into core
This commit is contained in:
@@ -25,7 +25,6 @@ import etapiTokensApiRoutes from "./api/etapi_tokens.js";
|
||||
import exportRoute from "./api/export.js";
|
||||
import filesRoute from "./api/files.js";
|
||||
import fontsRoute from "./api/fonts.js";
|
||||
import importRoute from "./api/import.js";
|
||||
import loginApiRoute from "./api/login.js";
|
||||
import metricsRoute from "./api/metrics.js";
|
||||
import otherRoute from "./api/other.js";
|
||||
@@ -130,8 +129,6 @@ function register(app: express.Application) {
|
||||
// route(GET, "/api/revisions/:revisionId/download", [auth.checkApiAuthOrElectron], revisionsApiRoute.downloadRevision);
|
||||
|
||||
route(GET, "/api/branches/:branchId/export/:type/:format/:version/:taskId", [auth.checkApiAuthOrElectron], exportRoute.exportBranch);
|
||||
asyncRoute(PST, "/api/notes/:parentNoteId/notes-import", [auth.checkApiAuthOrElectron, uploadMiddlewareWithErrorHandling, csrfMiddleware], importRoute.importNotesToBranch, apiResultHandler);
|
||||
route(PST, "/api/notes/:parentNoteId/attachments-import", [auth.checkApiAuthOrElectron, uploadMiddlewareWithErrorHandling, csrfMiddleware], importRoute.importAttachmentsToNote, apiResultHandler);
|
||||
|
||||
// :filename is not used by trilium, but instead used for "save as" to assign a human-readable filename
|
||||
|
||||
|
||||
@@ -46,10 +46,6 @@ function putEntityChange(entityChange: EntityChange) {
|
||||
cls.putEntityChange(entityChange);
|
||||
}
|
||||
|
||||
function ignoreEntityChangeIds() {
|
||||
cls.getContext().set("ignoreEntityChangeIds", true);
|
||||
}
|
||||
|
||||
function get(key: string) {
|
||||
return cls.getContext().get(key);
|
||||
}
|
||||
@@ -62,7 +58,10 @@ function reset() {
|
||||
cls.getContext().reset();
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export const wrap = cls.wrap;
|
||||
/** @deprecated */
|
||||
export const ignoreEntityChangeIds = cls.ignoreEntityChangeIds;
|
||||
|
||||
export default {
|
||||
init,
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { becca_loader, ValidationError } from "@triliumnext/core";
|
||||
import type { Request } from "express";
|
||||
import path from "path";
|
||||
|
||||
import becca from "../../becca/becca.js";
|
||||
import type BNote from "../../becca/entities/bnote.js";
|
||||
import cls from "../../services/cls.js";
|
||||
import enexImportService from "../../services/import/enex.js";
|
||||
import opmlImportService from "../../services/import/opml.js";
|
||||
import singleImportService from "../../services/import/single.js";
|
||||
import zipImportService from "../../services/import/zip.js";
|
||||
import log from "../../services/log.js";
|
||||
import log, { getLog } from "../../services/log.js";
|
||||
import TaskContext from "../../services/task_context.js";
|
||||
import { safeExtractMessageAndStackFromError } from "../../services/utils.js";
|
||||
import { safeExtractMessageAndStackFromError } from "../../services/utils/index.js";
|
||||
import * as cls from "../../services/context.js";
|
||||
import { ValidationError } from "../../errors.js";
|
||||
import becca_loader from "../../becca/becca_loader.js";
|
||||
|
||||
async function importNotesToBranch(req: Request<{ parentNoteId: string }>) {
|
||||
const { parentNoteId } = req.params;
|
||||
@@ -72,7 +73,7 @@ async function importNotesToBranch(req: Request<{ parentNoteId: string }>) {
|
||||
const message = `Import failed with following error: '${errMessage}'. More details might be in the logs.`;
|
||||
taskContext.reportError(message);
|
||||
|
||||
log.error(message + errStack);
|
||||
getLog().error(message + errStack);
|
||||
|
||||
return [500, message];
|
||||
}
|
||||
@@ -126,7 +127,7 @@ function importAttachmentsToNote(req: Request<{ parentNoteId: string }>) {
|
||||
const message = `Import failed with following error: '${errMessage}'. More details might be in the logs.`;
|
||||
taskContext.reportError(message);
|
||||
|
||||
log.error(message + errStack);
|
||||
getLog().error(message + errStack);
|
||||
|
||||
return [500, message];
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import similarNotesRoute from "./api/similar_notes";
|
||||
import imageRoute from "./api/image";
|
||||
import setupApiRoute from "./api/setup";
|
||||
import filesRoute from "./api/files";
|
||||
import importRoute from "./api/import";
|
||||
|
||||
// TODO: Deduplicate with routes.ts
|
||||
const GET = "get",
|
||||
@@ -136,6 +137,9 @@ export function buildSharedApiRoutes({ route, asyncRoute, apiRoute, asyncApiRout
|
||||
route(PST, "/api/sync/queue-sector/:entityName/:sector", [checkApiAuth], syncApiRoute.queueSector, apiResultHandler);
|
||||
route(GET, "/api/sync/stats", [], syncApiRoute.getStats, apiResultHandler);
|
||||
|
||||
asyncRoute(PST, "/api/notes/:parentNoteId/notes-import", [checkApiAuthOrElectron, uploadMiddlewareWithErrorHandling, csrfMiddleware], importRoute.importNotesToBranch, apiResultHandler);
|
||||
route(PST, "/api/notes/:parentNoteId/attachments-import", [checkApiAuthOrElectron, uploadMiddlewareWithErrorHandling, csrfMiddleware], importRoute.importAttachmentsToNote, apiResultHandler);
|
||||
|
||||
apiRoute(GET, "/api/quick-search/:searchString", searchRoute.quickSearch);
|
||||
apiRoute(GET, "/api/search-note/:noteId", searchRoute.searchFromNote);
|
||||
apiRoute(PST, "/api/search-and-execute-note/:noteId", searchRoute.searchAndExecute);
|
||||
|
||||
@@ -77,3 +77,7 @@ export function getAndClearEntityChangeIds() {
|
||||
|
||||
return entityChangeIds;
|
||||
}
|
||||
|
||||
export function ignoreEntityChangeIds() {
|
||||
getContext().set("ignoreEntityChangeIds", true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user