mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
smaller refactorings continued
This commit is contained in:
25
src/entities/api_token.js
Normal file
25
src/entities/api_token.js
Normal file
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
const utils = require('../services/utils');
|
||||
|
||||
class ApiToken extends Entity {
|
||||
static get tableName() { return "api_tokens"; }
|
||||
static get primaryKeyName() { return "apiTokenId"; }
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.apiTokenId) {
|
||||
this.apiTokenId = utils.newApiTokenId();
|
||||
}
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = utils.nowDate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ApiToken;
|
||||
@@ -13,6 +13,14 @@ class Branch extends Entity {
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.branchId) {
|
||||
this.branchId = utils.newBranchId();
|
||||
}
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
this.dateModified = utils.nowDate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ const NoteImage = require('../entities/note_image');
|
||||
const Branch = require('../entities/branch');
|
||||
const Label = require('../entities/label');
|
||||
const RecentNote = require('../entities/recent_note');
|
||||
const ApiToken = require('../entities/api_token');
|
||||
const repository = require('../services/repository');
|
||||
|
||||
function createEntityFromRow(row) {
|
||||
@@ -25,6 +26,9 @@ function createEntityFromRow(row) {
|
||||
else if (row.branchId && row.notePath) {
|
||||
entity = new RecentNote(row);
|
||||
}
|
||||
else if (row.apiTokenId) {
|
||||
entity = new ApiToken(row);
|
||||
}
|
||||
else if (row.branchId) {
|
||||
entity = new Branch(row);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,14 @@ class Image extends Entity {
|
||||
static get primaryKeyName() { return "imageId"; }
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.imageId) {
|
||||
this.imageId = utils.newImageId();
|
||||
}
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = utils.nowDate();
|
||||
}
|
||||
|
||||
@@ -131,6 +131,10 @@ class Note extends Entity {
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.noteId) {
|
||||
this.noteId = utils.newNoteId();
|
||||
}
|
||||
|
||||
if (this.isJson()) {
|
||||
this.content = JSON.stringify(this.jsonContent, null, '\t');
|
||||
}
|
||||
@@ -139,6 +143,10 @@ class Note extends Entity {
|
||||
protected_session.encryptNote(this);
|
||||
}
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = utils.nowDate();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,14 @@ class NoteImage extends Entity {
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.noteImageId) {
|
||||
this.noteImageId = utils.newNoteImageId();
|
||||
}
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = utils.nowDate();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const Entity = require('./entity');
|
||||
const protected_session = require('../services/protected_session');
|
||||
const utils = require('../services/utils');
|
||||
const repository = require('../services/repository');
|
||||
|
||||
class NoteRevision extends Entity {
|
||||
@@ -21,6 +22,10 @@ class NoteRevision extends Entity {
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.noteRevisionId) {
|
||||
this.noteRevisionId = utils.newNoteRevisionId();
|
||||
}
|
||||
|
||||
if (this.isProtected) {
|
||||
protected_session.encryptNoteRevision(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user