Merge remote-tracking branch 'upstream/master' into feature/port_0.63.7

; Conflicts:
;	package-lock.json
;	src/routes/api/files.ts
;	src/services/build.js
;	src/services/notes.ts
This commit is contained in:
Elian Doran
2024-07-13 18:36:04 +03:00
15 changed files with 74 additions and 31 deletions

View File

@@ -169,6 +169,8 @@ function saveAttachmentToTmpDir(req: Request) {
return saveToTmpDir(fileName, content, 'attachments', attachment.attachmentId);
}
const createdTemporaryFiles = new Set<string>();
function saveToTmpDir(fileName: string, content: string | Buffer, entityType: string, entityId: string) {
const tmpObj = tmp.fileSync({ postfix: fileName });
@@ -180,6 +182,8 @@ function saveToTmpDir(fileName: string, content: string | Buffer, entityType: st
fs.closeSync(tmpObj.fd);
createdTemporaryFiles.add(tmpObj.name);
log.info(`Saved temporary file ${tmpObj.name}`);
if (utils.isElectron()) {
@@ -203,6 +207,10 @@ function uploadModifiedFileToNote(req: Request) {
const noteId = req.params.noteId;
const {filePath} = req.body;
if (!createdTemporaryFiles.has(filePath)) {
throw new ValidationError(`File '${filePath}' is not a temporary file.`);
}
const note = becca.getNoteOrThrow(noteId);
log.info(`Updating note '${noteId}' with content from '${filePath}'`);