mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 18:50:41 +01:00
server-esm: Fix some more service imports
This commit is contained in:
@@ -8,6 +8,7 @@ import becca from "../becca/becca.js";
|
||||
import blobService from "../services/blob.js";
|
||||
import { EntityChange } from './entity_changes_interface';
|
||||
import type { Blob } from "./blob-interface";
|
||||
import eventService from "./events.js";
|
||||
|
||||
let maxEntityChangeId = 0;
|
||||
|
||||
@@ -57,8 +58,6 @@ function putNoteReorderingEntityChange(parentNoteId: string, componentId?: strin
|
||||
instanceId
|
||||
});
|
||||
|
||||
const eventService = require('./events');
|
||||
|
||||
eventService.emit(eventService.ENTITY_CHANGED, {
|
||||
entityName: 'note_reordering',
|
||||
entity: sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [parentNoteId])
|
||||
|
||||
@@ -11,7 +11,6 @@ import protectedSessionService from "../protected_session.js";
|
||||
import sanitize from "sanitize-filename";
|
||||
import fs from "fs";
|
||||
import becca from "../../becca/becca.js";
|
||||
const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR;
|
||||
import archiver from "archiver";
|
||||
import log from "../log.js";
|
||||
import TaskContext from "../task_context.js";
|
||||
@@ -21,6 +20,7 @@ import AttachmentMeta from "../meta/attachment_meta.js";
|
||||
import AttributeMeta from "../meta/attribute_meta.js";
|
||||
import BBranch from "../../becca/entities/bbranch.js";
|
||||
import { Response } from 'express';
|
||||
import resource_dir from "../resource_dir.js";
|
||||
|
||||
async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "html" | "markdown", res: Response | fs.WriteStream, setHeaders = true) {
|
||||
if (!['html', 'markdown'].includes(format)) {
|
||||
@@ -473,7 +473,7 @@ ${markdownContent}`;
|
||||
}
|
||||
|
||||
function saveCss(rootMeta: NoteMeta, cssMeta: NoteMeta) {
|
||||
const cssContent = fs.readFileSync(`${RESOURCE_DIR}/libraries/ckeditor/ckeditor-content.css`);
|
||||
const cssContent = fs.readFileSync(`${resource_dir.RESOURCE_DIR}/libraries/ckeditor/ckeditor-content.css`);
|
||||
|
||||
archive.append(cssContent, { name: cssMeta.dataFileName });
|
||||
}
|
||||
|
||||
@@ -156,7 +156,6 @@ function saveImageToAttachment(noteId: string, uploadBuffer: Buffer, originalNam
|
||||
setTimeout(() => {
|
||||
sql.transactional(() => {
|
||||
const note = becca.getNoteOrThrow(noteId);
|
||||
const noteService = require('../services/notes');
|
||||
noteService.asyncPostProcessContent(note, note.getContent()); // to mark an unused attachment for deletion
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
@@ -26,6 +26,7 @@ import html2plaintext from "html2plaintext";
|
||||
import { AttachmentRow, AttributeRow, BranchRow, NoteRow, NoteType } from '../becca/entities/rows';
|
||||
import TaskContext from "./task_context.js";
|
||||
import { NoteParams } from './note-interface';
|
||||
import imageService from "./image.js";
|
||||
|
||||
interface FoundLink {
|
||||
name: "imageLink" | "internalLink" | "includeNoteLink" | "relationMapLink",
|
||||
@@ -466,7 +467,7 @@ async function downloadImage(noteId: string, imageUrl: string) {
|
||||
const unescapedUrl = utils.unescapeHtml(imageUrl);
|
||||
|
||||
try {
|
||||
let imageBuffer;
|
||||
let imageBuffer: Buffer;
|
||||
|
||||
if (imageUrl.toLowerCase().startsWith("file://")) {
|
||||
imageBuffer = await new Promise((res, rej) => {
|
||||
@@ -487,10 +488,13 @@ async function downloadImage(noteId: string, imageUrl: string) {
|
||||
const parsedUrl = url.parse(unescapedUrl);
|
||||
const title = path.basename(parsedUrl.pathname || "");
|
||||
|
||||
const imageService = require('../services/image');
|
||||
const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, title, true, true);
|
||||
|
||||
imageUrlToAttachmentIdMapping[imageUrl] = attachment.attachmentId;
|
||||
|
||||
if (attachment.attachmentId) {
|
||||
imageUrlToAttachmentIdMapping[imageUrl] = attachment.attachmentId;
|
||||
} else {
|
||||
log.error(`Download of '${imageUrl}' due to no attachment ID.`);
|
||||
}
|
||||
|
||||
log.info(`Download of '${imageUrl}' succeeded and was saved as image attachment '${attachment.attachmentId}' of note '${noteId}'`);
|
||||
}
|
||||
@@ -520,7 +524,6 @@ function downloadImages(noteId: string, content: string) {
|
||||
const imageBase64 = url.substr(inlineImageMatch[0].length);
|
||||
const imageBuffer = Buffer.from(imageBase64, 'base64');
|
||||
|
||||
const imageService = require('../services/image');
|
||||
const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, "inline image", true, true);
|
||||
|
||||
const encodedTitle = encodeURIComponent(attachment.title);
|
||||
|
||||
@@ -137,7 +137,7 @@ function exec<T>(opts: ExecOpts): Promise<T> {
|
||||
});
|
||||
}
|
||||
|
||||
function getImage(imageUrl: string) {
|
||||
function getImage(imageUrl: string): Promise<Buffer> {
|
||||
const proxyConf = syncOptions.getSyncProxy();
|
||||
const opts: ClientOpts = {
|
||||
method: 'GET',
|
||||
@@ -149,7 +149,7 @@ function getImage(imageUrl: string) {
|
||||
const proxyAgent = getProxyAgent(opts);
|
||||
const parsedTargetUrl = url.parse(opts.url);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise<Buffer>((resolve, reject) => {
|
||||
try {
|
||||
const request = client.request({
|
||||
method: opts.method,
|
||||
@@ -181,8 +181,7 @@ function getImage(imageUrl: string) {
|
||||
});
|
||||
|
||||
request.end(undefined);
|
||||
}
|
||||
catch (e: any) {
|
||||
} catch (e: any) {
|
||||
reject(generateError(opts, e.message));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,6 +11,9 @@ import migrationService from "./migration.js";
|
||||
import cls from "./cls.js";
|
||||
import config from "./config.js";
|
||||
import { OptionRow } from '../becca/entities/rows';
|
||||
import optionsInitService from "./options_init.js";
|
||||
import BNote from "../becca/entities/bnote.js";
|
||||
import BBranch from "../becca/entities/bbranch.js";
|
||||
|
||||
const dbReady = utils.deferred<void>();
|
||||
|
||||
@@ -63,9 +66,6 @@ async function createInitialDatabase() {
|
||||
|
||||
require('../becca/becca_loader').load();
|
||||
|
||||
const BNote = require('../becca/entities/bnote');
|
||||
const BBranch = require('../becca/entities/bbranch');
|
||||
|
||||
log.info("Creating root note ...");
|
||||
|
||||
rootNote = new BNote({
|
||||
@@ -84,8 +84,6 @@ async function createInitialDatabase() {
|
||||
notePosition: 10
|
||||
}).save();
|
||||
|
||||
const optionsInitService = require('./options_init');
|
||||
|
||||
optionsInitService.initDocumentOptions();
|
||||
optionsInitService.initNotSyncedOptions(true, {});
|
||||
optionsInitService.initStartupOptions();
|
||||
|
||||
Reference in New Issue
Block a user