mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-esm: Fix some more service imports
This commit is contained in:
parent
c5561530ec
commit
bf29b30004
@ -8,6 +8,7 @@ import AbstractBeccaEntity from "./abstract_becca_entity.js";
|
||||
import sql from "../../services/sql.js";
|
||||
import BAttachment from "./battachment.js";
|
||||
import { AttachmentRow, RevisionRow } from './rows';
|
||||
import eraseService from "../../services/erase.js";
|
||||
|
||||
interface ContentOpts {
|
||||
/** will also save this BRevision entity */
|
||||
@ -164,7 +165,9 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
|
||||
* Revisions are not soft-deletable, they are immediately hard-deleted (erased).
|
||||
*/
|
||||
eraseRevision() {
|
||||
require('../../services/erase.js').eraseRevisions([this.revisionId]);
|
||||
if (this.revisionId) {
|
||||
eraseService.eraseRevisions([this.revisionId]);
|
||||
}
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
import imageService from "../../services/image.js";
|
||||
import becca from "../../becca/becca.js";
|
||||
const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR;
|
||||
import fs from "fs";
|
||||
import { Request, Response } from 'express';
|
||||
import BNote from "../../becca/entities/bnote.js";
|
||||
import BRevision from "../../becca/entities/brevision.js";
|
||||
import { AppRequest } from '../route-interface';
|
||||
import resource_dir from "../../services/resource_dir.js";
|
||||
|
||||
function returnImageFromNote(req: Request, res: Response) {
|
||||
const image = becca.getNote(req.params.noteId);
|
||||
@ -24,7 +24,7 @@ function returnImageFromRevision(req: Request, res: Response) {
|
||||
function returnImageInt(image: BNote | BRevision | null, res: Response) {
|
||||
if (!image) {
|
||||
res.set('Content-Type', 'image/png');
|
||||
return res.send(fs.readFileSync(`${RESOURCE_DIR}/db/image-deleted.png`));
|
||||
return res.send(fs.readFileSync(`${resource_dir.RESOURCE_DIR}/db/image-deleted.png`));
|
||||
} else if (!["image", "canvas", "mermaid"].includes(image.type)) {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
@ -68,7 +68,7 @@ function returnAttachedImage(req: Request, res: Response) {
|
||||
|
||||
if (!attachment) {
|
||||
res.set('Content-Type', 'image/png');
|
||||
return res.send(fs.readFileSync(`${RESOURCE_DIR}/db/image-deleted.png`));
|
||||
return res.send(fs.readFileSync(`${resource_dir.RESOURCE_DIR}/db/image-deleted.png`));
|
||||
}
|
||||
|
||||
if (!["image"].includes(attachment.role)) {
|
||||
|
@ -14,6 +14,7 @@ import ws from "../../services/ws.js";
|
||||
import { Request } from 'express';
|
||||
import { EntityChange, EntityChangeRecord } from '../../services/entity_changes_interface';
|
||||
import ValidationError from "../../errors/validation_error.js";
|
||||
import consistencyChecksService from "../../services/consistency_checks.js";
|
||||
|
||||
async function testSync() {
|
||||
try {
|
||||
@ -206,7 +207,7 @@ function queueSector(req: Request) {
|
||||
}
|
||||
|
||||
function checkEntityChanges() {
|
||||
require('../../services/consistency_checks').runEntityChangesChecks();
|
||||
consistencyChecksService.runEntityChangesChecks();
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user