mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port services/export/single
This commit is contained in:
parent
cfeb0cc6f7
commit
1728365fa1
13
package-lock.json
generated
13
package-lock.json
generated
@ -92,6 +92,7 @@
|
||||
"@types/better-sqlite3": "^7.6.9",
|
||||
"@types/escape-html": "^1.0.4",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/html": "^1.0.4",
|
||||
"@types/ini": "^4.1.0",
|
||||
"@types/jsdom": "^21.1.6",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
@ -1484,6 +1485,12 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/html": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/html/-/html-1.0.4.tgz",
|
||||
"integrity": "sha512-Wb1ymSAftCLxhc3D6vS0Ike/0xg7W6c+DQxAkerU6pD7C8CMzTYwvrwnlcrTfsVO/nMelB9KOKIT7+N5lOeQUg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/http-cache-semantics": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz",
|
||||
@ -16229,6 +16236,12 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/html": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/html/-/html-1.0.4.tgz",
|
||||
"integrity": "sha512-Wb1ymSAftCLxhc3D6vS0Ike/0xg7W6c+DQxAkerU6pD7C8CMzTYwvrwnlcrTfsVO/nMelB9KOKIT7+N5lOeQUg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/http-cache-semantics": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz",
|
||||
|
@ -115,6 +115,7 @@
|
||||
"@types/better-sqlite3": "^7.6.9",
|
||||
"@types/escape-html": "^1.0.4",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/html": "^1.0.4",
|
||||
"@types/ini": "^4.1.0",
|
||||
"@types/jsdom": "^21.1.6",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const zipExportService = require('../../services/export/zip.js');
|
||||
const singleExportService = require('../../services/export/single.js');
|
||||
const singleExportService = require('../../services/export/single');
|
||||
const opmlExportService = require('../../services/export/opml');
|
||||
const becca = require('../../becca/becca');
|
||||
const TaskContext = require('../../services/task_context');
|
||||
|
@ -3,7 +3,7 @@
|
||||
const enexImportService = require('../../services/import/enex.js');
|
||||
const opmlImportService = require('../../services/import/opml');
|
||||
const zipImportService = require('../../services/import/zip.js');
|
||||
const singleImportService = require('../../services/import/single.js');
|
||||
const singleImportService = require('../../services/import/single');
|
||||
const cls = require('../../services/cls');
|
||||
const path = require('path');
|
||||
const becca = require('../../becca/becca');
|
||||
|
@ -1,12 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
const mimeTypes = require('mime-types');
|
||||
const html = require('html');
|
||||
const utils = require('../utils');
|
||||
const mdService = require('./md');
|
||||
const becca = require('../../becca/becca');
|
||||
import mimeTypes = require('mime-types');
|
||||
import html = require('html');
|
||||
import utils = require('../utils');
|
||||
import mdService = require('./md');
|
||||
import becca = require('../../becca/becca');
|
||||
import TaskContext = require('../task_context');
|
||||
import BBranch = require('../../becca/entities/bbranch');
|
||||
import { Response } from 'express';
|
||||
|
||||
function exportSingleNote(taskContext, branch, format, res) {
|
||||
function exportSingleNote(taskContext: TaskContext, branch: BBranch, format: "html" | "markdown", res: Response) {
|
||||
const note = branch.getNote();
|
||||
|
||||
if (note.type === 'image' || note.type === 'file') {
|
||||
@ -20,6 +23,9 @@ function exportSingleNote(taskContext, branch, format, res) {
|
||||
let payload, extension, mime;
|
||||
|
||||
let content = note.getContent();
|
||||
if (typeof content !== "string") {
|
||||
throw new Error("Unsupported context type for export.");
|
||||
}
|
||||
|
||||
if (note.type === 'text') {
|
||||
if (format === 'html') {
|
||||
@ -64,7 +70,7 @@ function exportSingleNote(taskContext, branch, format, res) {
|
||||
taskContext.taskSucceeded();
|
||||
}
|
||||
|
||||
function inlineAttachments(content) {
|
||||
function inlineAttachments(content: string) {
|
||||
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9_]+)\/?[^"]+"/g, (match, noteId) => {
|
||||
const note = becca.getNote(noteId);
|
||||
if (!note || !note.mime.startsWith('image/')) {
|
Loading…
x
Reference in New Issue
Block a user