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

@@ -9,10 +9,10 @@ import path from "path";
import becca from "../../becca/becca.js";
import blobService from "../../services/blob.js";
import eraseService from "../../services/erase.js";
import { Request, Response } from 'express';
import { Request, Response } from "express";
import BRevision from "../../becca/entities/brevision.js";
import BNote from "../../becca/entities/bnote.js";
import { NotePojo } from '../../becca/becca-interface.js';
import { NotePojo } from "../../becca/becca-interface.js";
interface NotePath {
noteId: string;
@@ -27,34 +27,36 @@ interface NotePojoWithNotePath extends NotePojo {
}
function getRevisionBlob(req: Request) {
const preview = req.query.preview === 'true';
const preview = req.query.preview === "true";
return blobService.getBlobPojo('revisions', req.params.revisionId, { preview });
return blobService.getBlobPojo("revisions", req.params.revisionId, { preview });
}
function getRevisions(req: Request) {
return becca.getRevisionsFromQuery(`
return becca.getRevisionsFromQuery(
`
SELECT revisions.*,
LENGTH(blobs.content) AS contentLength
FROM revisions
JOIN blobs ON revisions.blobId = blobs.blobId
WHERE revisions.noteId = ?
ORDER BY revisions.utcDateCreated DESC`, [req.params.noteId]);
ORDER BY revisions.utcDateCreated DESC`,
[req.params.noteId]
);
}
function getRevision(req: Request) {
const revision = becca.getRevisionOrThrow(req.params.revisionId);
if (revision.type === 'file') {
if (revision.type === "file") {
if (revision.hasStringContent()) {
revision.content = (revision.getContent() as string).substr(0, 10000);
}
}
else {
} else {
revision.content = revision.getContent();
if (revision.content && revision.type === 'image') {
revision.content = revision.content.toString('base64');
if (revision.content && revision.type === "image") {
revision.content = revision.content.toString("base64");
}
}
@@ -71,13 +73,12 @@ function getRevisionFilename(revision: BRevision) {
const extension = path.extname(filename);
const date = revision.dateCreated
.substr(0, 19)
.replace(' ', '_')
.replace(/[^0-9_]/g, '');
.replace(" ", "_")
.replace(/[^0-9_]/g, "");
if (extension) {
filename = `${filename.substr(0, filename.length - extension.length)}-${date}${extension}`;
}
else {
} else {
filename += `-${date}`;
}
@@ -88,22 +89,19 @@ function downloadRevision(req: Request, res: Response) {
const revision = becca.getRevisionOrThrow(req.params.revisionId);
if (!revision.isContentAvailable()) {
return res.setHeader("Content-Type", "text/plain")
.status(401)
.send("Protected session not available");
return res.setHeader("Content-Type", "text/plain").status(401).send("Protected session not available");
}
const filename = getRevisionFilename(revision);
res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
res.setHeader('Content-Type', revision.mime);
res.setHeader("Content-Disposition", utils.getContentDisposition(filename));
res.setHeader("Content-Type", revision.mime);
res.send(revision.getContent());
}
function eraseAllRevisions(req: Request) {
const revisionIdsToErase = sql.getColumn<string>('SELECT revisionId FROM revisions WHERE noteId = ?',
[req.params.noteId]);
const revisionIdsToErase = sql.getColumn<string>("SELECT revisionId FROM revisions WHERE noteId = ?", [req.params.noteId]);
eraseService.eraseRevisions(revisionIdsToErase);
}
@@ -114,8 +112,8 @@ function eraseRevision(req: Request) {
function eraseAllExcessRevisions() {
let allNoteIds = sql.getRows("SELECT noteId FROM notes WHERE SUBSTRING(noteId, 1, 1) != '_'") as { noteId: string }[];
allNoteIds.forEach(row => {
becca.getNote(row.noteId)?.eraseExcessRevisionSnapshots()
allNoteIds.forEach((row) => {
becca.getNote(row.noteId)?.eraseExcessRevisionSnapshots();
});
}
@@ -154,7 +152,8 @@ function restoreRevision(req: Request) {
}
function getEditedNotesOnDate(req: Request) {
const noteIds = sql.getColumn<string>(`
const noteIds = sql.getColumn<string>(
`
SELECT notes.*
FROM notes
WHERE noteId IN (
@@ -166,17 +165,19 @@ function getEditedNotesOnDate(req: Request) {
WHERE revisions.dateLastEdited LIKE :date
)
ORDER BY isDeleted
LIMIT 50`, {date: `${req.params.date}%`});
LIMIT 50`,
{ date: `${req.params.date}%` }
);
let notes = becca.getNotes(noteIds, true);
// Narrow down the results if a note is hoisted, similar to "Jump to note".
const hoistedNoteId = cls.getHoistedNoteId();
if (hoistedNoteId !== 'root') {
notes = notes.filter(note => note.hasAncestor(hoistedNoteId));
if (hoistedNoteId !== "root") {
notes = notes.filter((note) => note.hasAncestor(hoistedNoteId));
}
return notes.map(note => {
return notes.map((note) => {
const notePath = getNotePathData(note);
const notePojo: NotePojoWithNotePath = note.getPojo();
@@ -184,7 +185,6 @@ function getEditedNotesOnDate(req: Request) {
return notePojo;
});
}
function getNotePathData(note: BNote): NotePath | undefined {
@@ -196,9 +196,8 @@ function getNotePathData(note: BNote): NotePath | undefined {
let branchId;
if (note.isRoot()) {
branchId = 'none_root';
}
else {
branchId = "none_root";
} else {
const parentNote = note.parents[0];
branchId = becca.getBranchFromChildAndParent(note.noteId, parentNote.noteId)?.branchId;
}
@@ -208,7 +207,7 @@ function getNotePathData(note: BNote): NotePath | undefined {
branchId: branchId,
title: noteTitle,
notePath: retPath,
path: retPath.join('/')
path: retPath.join("/")
};
}
}