chore(prettier): fix all files

This commit is contained in:
Elian Doran
2025-01-09 18:07:02 +02:00
parent 19ee861699
commit 4cbb529fd4
571 changed files with 23226 additions and 23940 deletions

View File

@@ -6,12 +6,12 @@ import log from "../../services/log.js";
import noteService from "../../services/notes.js";
import tmp from "tmp";
import fs from "fs";
import { Readable } from 'stream';
import { Readable } from "stream";
import chokidar from "chokidar";
import ws from "../../services/ws.js";
import becca from "../../becca/becca.js";
import ValidationError from "../../errors/validation_error.js";
import { Request, Response } from 'express';
import { Request, Response } from "express";
import BNote from "../../becca/entities/bnote.js";
import BAttachment from "../../becca/entities/battachment.js";
@@ -33,7 +33,7 @@ function updateFile(req: Request) {
note.setContent(file.buffer);
note.setLabel('originalFileName', file.originalname);
note.setLabel("originalFileName", file.originalname);
noteService.asyncPostProcessContent(note, file.buffer);
@@ -55,7 +55,7 @@ function updateAttachment(req: Request) {
attachment.getNote().saveRevision();
attachment.mime = file.mimetype.toLowerCase();
attachment.setContent(file.buffer, {forceSave: true});
attachment.setContent(file.buffer, { forceSave: true });
return {
uploaded: true
@@ -70,11 +70,11 @@ function downloadData(noteOrAttachment: BNote | BAttachment, res: Response, cont
if (contentDisposition) {
const fileName = noteOrAttachment.getFileName();
res.setHeader('Content-Disposition', utils.getContentDisposition(fileName));
res.setHeader("Content-Disposition", utils.getContentDisposition(fileName));
}
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader('Content-Type', noteOrAttachment.mime);
res.setHeader("Content-Type", noteOrAttachment.mime);
res.send(noteOrAttachment.getContent());
}
@@ -83,9 +83,7 @@ function downloadNoteInt(noteId: string, res: Response, contentDisposition = tru
const note = becca.getNote(noteId);
if (!note) {
return res.setHeader("Content-Type", "text/plain")
.status(404)
.send(`Note '${noteId}' doesn't exist.`);
return res.setHeader("Content-Type", "text/plain").status(404).send(`Note '${noteId}' doesn't exist.`);
}
return downloadData(note, res, contentDisposition);
@@ -95,9 +93,7 @@ function downloadAttachmentInt(attachmentId: string, res: Response, contentDispo
const attachment = becca.getAttachment(attachmentId);
if (!attachment) {
return res.setHeader("Content-Type", "text/plain")
.status(404)
.send(`Attachment '${attachmentId}' doesn't exist.`);
return res.setHeader("Content-Type", "text/plain").status(404).send(`Attachment '${attachmentId}' doesn't exist.`);
}
return downloadData(attachment, res, contentDisposition);
@@ -125,21 +121,21 @@ function attachmentContentProvider(req: Request) {
async function streamContent(content: string | Buffer, fileName: string, mimeType: string) {
if (typeof content === "string") {
content = Buffer.from(content, 'utf8');
content = Buffer.from(content, "utf8");
}
const totalSize = content.byteLength;
const getStream = (range: { start: number, end: number }) => {
const getStream = (range: { start: number; end: number }) => {
if (!range) {
// Request if for complete content.
return Readable.from(content);
}
// Partial content request.
const {start, end} = range;
const { start, end } = range;
return Readable.from(content.slice(start, end + 1));
}
};
return {
fileName,
@@ -154,7 +150,7 @@ function saveNoteToTmpDir(req: Request) {
const fileName = note.getFileName();
const content = note.getContent();
return saveToTmpDir(fileName, content, 'notes', note.noteId);
return saveToTmpDir(fileName, content, "notes", note.noteId);
}
function saveAttachmentToTmpDir(req: Request) {
@@ -165,7 +161,7 @@ function saveAttachmentToTmpDir(req: Request) {
if (!attachment.attachmentId) {
throw new ValidationError("Missing attachment ID.");
}
return saveToTmpDir(fileName, content, 'attachments', attachment.attachmentId);
return saveToTmpDir(fileName, content, "attachments", attachment.attachmentId);
}
const createdTemporaryFiles = new Set<string>();
@@ -186,9 +182,9 @@ function saveToTmpDir(fileName: string, content: string | Buffer, entityType: st
log.info(`Saved temporary file ${tmpObj.name}`);
if (utils.isElectron()) {
chokidar.watch(tmpObj.name).on('change', (path, stats) => {
chokidar.watch(tmpObj.name).on("change", (path, stats) => {
ws.sendMessageToAllClients({
type: 'openedFileUpdated',
type: "openedFileUpdated",
entityType: entityType,
entityId: entityId,
lastModifiedMs: stats?.atimeMs,
@@ -204,7 +200,7 @@ function saveToTmpDir(fileName: string, content: string | Buffer, entityType: st
function uploadModifiedFileToNote(req: Request) {
const noteId = req.params.noteId;
const {filePath} = req.body;
const { filePath } = req.body;
if (!createdTemporaryFiles.has(filePath)) {
throw new ValidationError(`File '${filePath}' is not a temporary file.`);
@@ -226,8 +222,8 @@ function uploadModifiedFileToNote(req: Request) {
}
function uploadModifiedFileToAttachment(req: Request) {
const {attachmentId} = req.params;
const {filePath} = req.body;
const { attachmentId } = req.params;
const { filePath } = req.body;
const attachment = becca.getAttachmentOrThrow(attachmentId);