rename "note revision" to just "revision"

This commit is contained in:
zadam
2023-06-04 23:01:40 +02:00
parent cb9feab7b2
commit 779751a234
46 changed files with 275 additions and 248 deletions

View File

@@ -16,7 +16,7 @@ function updateFile(req) {
const note = becca.getNoteOrThrow(req.params.noteId);
const file = req.file;
note.saveNoteRevision();
note.saveRevision();
note.mime = file.mimetype.toLowerCase();
note.save();
@@ -35,7 +35,7 @@ function updateFile(req) {
function updateAttachment(req) {
const attachment = becca.getAttachmentOrThrow(req.params.attachmentId);
const file = req.file;
attachment.getNote().saveNoteRevision();
attachment.getNote().saveRevision();
attachment.mime = file.mimetype.toLowerCase();
attachment.setContent(file.buffer, {forceSave: true});
@@ -186,7 +186,7 @@ function uploadModifiedFileToNote(req) {
log.info(`Updating note '${noteId}' with content from '${filePath}'`);
note.saveNoteRevision();
note.saveRevision();
const fileContent = fs.readFileSync(filePath);
@@ -205,7 +205,7 @@ function uploadModifiedFileToAttachment(req) {
log.info(`Updating attachment '${attachmentId}' with content from '${filePath}'`);
attachment.getNote().saveNoteRevision();
attachment.getNote().saveRevision();
const fileContent = fs.readFileSync(filePath);

View File

@@ -131,7 +131,7 @@ function changeTitle(req) {
const noteTitleChanged = note.title !== title;
if (noteTitleChanged) {
noteService.saveNoteRevisionIfNeeded(note);
noteService.saveRevisionIfNeeded(note);
}
note.title = title;
@@ -216,7 +216,7 @@ function getDeleteNotesPreview(req) {
};
}
function forceSaveNoteRevision(req) {
function forceSaveRevision(req) {
const {noteId} = req.params;
const note = becca.getNoteOrThrow(noteId);
@@ -224,7 +224,7 @@ function forceSaveNoteRevision(req) {
throw new ValidationError(`Note revision of a protected note cannot be created outside of a protected session.`);
}
note.saveNoteRevision();
note.saveRevision();
}
function convertNoteToAttachment(req) {
@@ -252,6 +252,6 @@ module.exports = {
eraseDeletedNotesNow,
eraseUnusedAttachmentsNow,
getDeleteNotesPreview,
forceSaveNoteRevision,
forceSaveRevision,
convertNoteToAttachment
};

View File

@@ -9,7 +9,7 @@ const ValidationError = require("../../errors/validation_error");
const ALLOWED_OPTIONS = new Set([
'eraseEntitiesAfterTimeInSeconds',
'protectedSessionTimeout',
'noteRevisionSnapshotTimeInterval',
'revisionSnapshotTimeInterval',
'zoomFactor',
'theme',
'syncServerHost',
@@ -28,7 +28,7 @@ const ALLOWED_OPTIONS = new Set([
'noteInfoWidget',
'attributesWidget',
'linkMapWidget',
'noteRevisionsWidget',
'revisionsWidget',
'whatLinksHereWidget',
'similarNotesWidget',
'editedNotesWidget',

View File

@@ -10,25 +10,25 @@ function getRecentChanges(req) {
let recentChanges = [];
const noteRevisionRows = sql.getRows(`
const revisionRows = sql.getRows(`
SELECT
notes.noteId,
notes.isDeleted AS current_isDeleted,
notes.deleteId AS current_deleteId,
notes.title AS current_title,
notes.isProtected AS current_isProtected,
note_revisions.title,
note_revisions.utcDateCreated AS utcDate,
note_revisions.dateCreated AS date
revisions.title,
revisions.utcDateCreated AS utcDate,
revisions.dateCreated AS date
FROM
note_revisions
revisions
JOIN notes USING(noteId)`);
for (const noteRevisionRow of noteRevisionRows) {
const note = becca.getNote(noteRevisionRow.noteId);
for (const revisionRow of revisionRows) {
const note = becca.getNote(revisionRow.noteId);
if (note?.hasAncestor(ancestorNoteId)) {
recentChanges.push(noteRevisionRow);
recentChanges.push(revisionRow);
}
}

View File

@@ -1,7 +1,7 @@
"use strict";
const beccaService = require('../../becca/becca_service');
const noteRevisionService = require('../../services/note_revisions');
const revisionService = require('../../services/revisions.js');
const utils = require('../../services/utils');
const sql = require('../../services/sql');
const cls = require('../../services/cls');
@@ -9,50 +9,50 @@ const path = require('path');
const becca = require("../../becca/becca");
const blobService = require("../../services/blob.js");
function getNoteRevisionBlob(req) {
function getRevisionBlob(req) {
const preview = req.query.preview === 'true';
return blobService.getBlobPojo('note_revisions', req.params.noteRevisionId, { preview });
return blobService.getBlobPojo('revisions', req.params.revisionId, { preview });
}
function getNoteRevisions(req) {
return becca.getNoteRevisionsFromQuery(`
SELECT note_revisions.*,
function getRevisions(req) {
return becca.getRevisionsFromQuery(`
SELECT revisions.*,
LENGTH(blobs.content) AS contentLength
FROM note_revisions
JOIN blobs ON note_revisions.blobId = blobs.blobId
FROM revisions
JOIN blobs ON revisions.blobId = blobs.blobId
WHERE noteId = ?
ORDER BY utcDateCreated DESC`, [req.params.noteId]);
}
function getNoteRevision(req) {
const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);
function getRevision(req) {
const revision = becca.getRevision(req.params.revisionId);
if (noteRevision.type === 'file') {
if (noteRevision.hasStringContent()) {
noteRevision.content = noteRevision.getContent().substr(0, 10000);
if (revision.type === 'file') {
if (revision.hasStringContent()) {
revision.content = revision.getContent().substr(0, 10000);
}
}
else {
noteRevision.content = noteRevision.getContent();
revision.content = revision.getContent();
if (noteRevision.content && noteRevision.type === 'image') {
noteRevision.content = noteRevision.content.toString('base64');
if (revision.content && revision.type === 'image') {
revision.content = revision.content.toString('base64');
}
}
return noteRevision;
return revision;
}
/**
* @param {BNoteRevision} noteRevision
* @param {BRevision} revision
* @returns {string}
*/
function getRevisionFilename(noteRevision) {
let filename = utils.formatDownloadTitle(noteRevision.title, noteRevision.type, noteRevision.mime);
function getRevisionFilename(revision) {
let filename = utils.formatDownloadTitle(revision.title, revision.type, revision.mime);
const extension = path.extname(filename);
const date = noteRevision.dateCreated
const date = revision.dateCreated
.substr(0, 19)
.replace(' ', '_')
.replace(/[^0-9_]/g, '');
@@ -67,50 +67,50 @@ function getRevisionFilename(noteRevision) {
return filename;
}
function downloadNoteRevision(req, res) {
const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);
function downloadRevision(req, res) {
const revision = becca.getRevision(req.params.revisionId);
if (!noteRevision.isContentAvailable()) {
if (!revision.isContentAvailable()) {
return res.setHeader("Content-Type", "text/plain")
.status(401)
.send("Protected session not available");
}
const filename = getRevisionFilename(noteRevision);
const filename = getRevisionFilename(revision);
res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
res.setHeader('Content-Type', noteRevision.mime);
res.setHeader('Content-Type', revision.mime);
res.send(noteRevision.getContent());
res.send(revision.getContent());
}
function eraseAllNoteRevisions(req) {
const noteRevisionIdsToErase = sql.getColumn('SELECT noteRevisionId FROM note_revisions WHERE noteId = ?',
function eraseAllRevisions(req) {
const revisionIdsToErase = sql.getColumn('SELECT revisionId FROM revisions WHERE noteId = ?',
[req.params.noteId]);
noteRevisionService.eraseNoteRevisions(noteRevisionIdsToErase);
revisionService.eraseRevisions(revisionIdsToErase);
}
function eraseNoteRevision(req) {
noteRevisionService.eraseNoteRevisions([req.params.noteRevisionId]);
function eraseRevision(req) {
revisionService.eraseRevisions([req.params.revisionId]);
}
function restoreNoteRevision(req) {
const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);
function restoreRevision(req) {
const revision = becca.getRevision(req.params.revisionId);
if (noteRevision) {
const note = noteRevision.getNote();
if (revision) {
const note = revision.getNote();
sql.transactional(() => {
note.saveNoteRevision();
note.saveRevision();
for (const oldNoteAttachment of note.getAttachments()) {
oldNoteAttachment.markAsDeleted();
}
let revisionContent = noteRevision.getContent();
let revisionContent = revision.getContent();
for (const revisionAttachment of noteRevision.getAttachments()) {
for (const revisionAttachment of revision.getAttachments()) {
const noteAttachment = revisionAttachment.copy();
noteAttachment.parentId = note.noteId;
noteAttachment.setContent(revisionAttachment.getContent(), { forceSave: true });
@@ -119,7 +119,7 @@ function restoreNoteRevision(req) {
revisionContent = revisionContent.replaceAll(`attachments/${revisionAttachment.attachmentId}`, `attachments/${noteAttachment.attachmentId}`);
}
note.title = noteRevision.title;
note.title = revision.title;
note.setContent(revisionContent, { forceSave: true });
});
}
@@ -134,8 +134,8 @@ function getEditedNotesOnDate(req) {
WHERE notes.dateCreated LIKE :date
OR notes.dateModified LIKE :date
UNION ALL
SELECT noteId FROM note_revisions
WHERE note_revisions.dateLastEdited LIKE :date
SELECT noteId FROM revisions
WHERE revisions.dateLastEdited LIKE :date
)
ORDER BY isDeleted
LIMIT 50`, {date: `${req.params.date}%`});
@@ -186,12 +186,12 @@ function getNotePathData(note) {
}
module.exports = {
getNoteRevisionBlob,
getNoteRevisions,
getNoteRevision,
downloadNoteRevision,
getRevisionBlob,
getRevisions,
getRevision,
downloadRevision,
getEditedNotesOnDate,
eraseAllNoteRevisions,
eraseNoteRevision,
restoreNoteRevision
eraseAllRevisions,
eraseRevision,
restoreRevision
};

View File

@@ -9,10 +9,10 @@ function getNoteSize(req) {
FROM blobs
LEFT JOIN notes ON notes.blobId = blobs.blobId AND notes.noteId = ? AND notes.isDeleted = 0
LEFT JOIN attachments ON attachments.blobId = blobs.blobId AND attachments.parentId = ? AND attachments.isDeleted = 0
LEFT JOIN note_revisions ON note_revisions.blobId = blobs.blobId AND note_revisions.noteId = ?
LEFT JOIN revisions ON revisions.blobId = blobs.blobId AND revisions.noteId = ?
WHERE notes.noteId IS NOT NULL
OR attachments.attachmentId IS NOT NULL
OR note_revisions.noteRevisionId IS NOT NULL`, [noteId, noteId, noteId]);
OR revisions.revisionId IS NOT NULL`, [noteId, noteId, noteId]);
const noteSize = Object.values(blobSizes).reduce((acc, blobSize) => acc + blobSize, 0);
@@ -33,8 +33,8 @@ function getSubtreeSize(req) {
FROM param_list
JOIN notes ON notes.noteId = param_list.paramId AND notes.isDeleted = 0
LEFT JOIN attachments ON attachments.parentId = param_list.paramId AND attachments.isDeleted = 0
LEFT JOIN note_revisions ON note_revisions.noteId = param_list.paramId
JOIN blobs ON blobs.blobId = notes.blobId OR blobs.blobId = attachments.blobId OR blobs.blobId = note_revisions.blobId`);
LEFT JOIN revisions ON revisions.noteId = param_list.paramId
JOIN blobs ON blobs.blobId = notes.blobId OR blobs.blobId = attachments.blobId OR blobs.blobId = revisions.blobId`);
const subTreeSize = Object.values(blobSizes).reduce((acc, blobSize) => acc + blobSize, 0);

View File

@@ -108,9 +108,9 @@ function forceNoteSync(req) {
entityChangesService.moveEntityChangeToTop('attributes', attributeId);
}
for (const noteRevisionId of sql.getColumn("SELECT noteRevisionId FROM note_revisions WHERE noteId = ?", [noteId])) {
sql.execute(`UPDATE note_revisions SET utcDateModified = ? WHERE noteRevisionId = ?`, [now, noteRevisionId]);
entityChangesService.moveEntityChangeToTop('note_revisions', noteRevisionId);
for (const revisionId of sql.getColumn("SELECT revisionId FROM revisions WHERE noteId = ?", [noteId])) {
sql.execute(`UPDATE revisions SET utcDateModified = ? WHERE revisionId = ?`, [now, revisionId]);
entityChangesService.moveEntityChangeToTop('revisions', revisionId);
}
for (const attachmentId of sql.getColumn("SELECT attachmentId FROM attachments WHERE noteId = ?", [noteId])) {