mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
simplified new entity ID allocation
This commit is contained in:
parent
e2921a648d
commit
277368ab43
@ -8,9 +8,7 @@ class ApiToken extends Entity {
|
|||||||
static get primaryKeyName() { return "apiTokenId"; }
|
static get primaryKeyName() { return "apiTokenId"; }
|
||||||
|
|
||||||
beforeSaving() {
|
beforeSaving() {
|
||||||
if (!this.apiTokenId) {
|
super.beforeSaving();
|
||||||
this.apiTokenId = utils.newApiTokenId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isDeleted) {
|
if (!this.isDeleted) {
|
||||||
this.isDeleted = false;
|
this.isDeleted = false;
|
||||||
|
@ -13,9 +13,7 @@ class Branch extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeSaving() {
|
beforeSaving() {
|
||||||
if (!this.branchId) {
|
super.beforeSaving();
|
||||||
this.branchId = utils.newBranchId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isDeleted) {
|
if (!this.isDeleted) {
|
||||||
this.isDeleted = false;
|
this.isDeleted = false;
|
||||||
|
@ -12,6 +12,12 @@ class Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeSaving() {
|
||||||
|
if (!this[this.constructor.primaryKeyName]) {
|
||||||
|
this[this.constructor.primaryKeyName] = utils.newEntityId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
await repository.updateEntity(this);
|
await repository.updateEntity(this);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,7 @@ class Image extends Entity {
|
|||||||
static get primaryKeyName() { return "imageId"; }
|
static get primaryKeyName() { return "imageId"; }
|
||||||
|
|
||||||
beforeSaving() {
|
beforeSaving() {
|
||||||
if (!this.imageId) {
|
super.beforeSaving();
|
||||||
this.imageId = utils.newImageId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isDeleted) {
|
if (!this.isDeleted) {
|
||||||
this.isDeleted = false;
|
this.isDeleted = false;
|
||||||
|
@ -14,9 +14,7 @@ class Label extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async beforeSaving() {
|
async beforeSaving() {
|
||||||
if (!this.labelId) {
|
super.beforeSaving();
|
||||||
this.labelId = utils.newLabelId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.value) {
|
if (!this.value) {
|
||||||
// null value isn't allowed
|
// null value isn't allowed
|
||||||
|
@ -131,9 +131,7 @@ class Note extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeSaving() {
|
beforeSaving() {
|
||||||
if (!this.noteId) {
|
super.beforeSaving();
|
||||||
this.noteId = utils.newNoteId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isJson()) {
|
if (this.isJson()) {
|
||||||
this.content = JSON.stringify(this.jsonContent, null, '\t');
|
this.content = JSON.stringify(this.jsonContent, null, '\t');
|
||||||
|
@ -17,9 +17,7 @@ class NoteImage extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeSaving() {
|
beforeSaving() {
|
||||||
if (!this.noteImageId) {
|
super.beforeSaving();
|
||||||
this.noteImageId = utils.newNoteImageId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isDeleted) {
|
if (!this.isDeleted) {
|
||||||
this.isDeleted = false;
|
this.isDeleted = false;
|
||||||
|
@ -22,9 +22,7 @@ class NoteRevision extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeSaving() {
|
beforeSaving() {
|
||||||
if (!this.noteRevisionId) {
|
super.beforeSaving();
|
||||||
this.noteRevisionId = utils.newNoteRevisionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isProtected) {
|
if (this.isProtected) {
|
||||||
protected_session.encryptNoteRevision(this);
|
protected_session.encryptNoteRevision(this);
|
||||||
|
@ -4,31 +4,7 @@ const crypto = require('crypto');
|
|||||||
const randtoken = require('rand-token').generator({source: 'crypto'});
|
const randtoken = require('rand-token').generator({source: 'crypto'});
|
||||||
const unescape = require('unescape');
|
const unescape = require('unescape');
|
||||||
|
|
||||||
function newNoteId() {
|
function newEntityId() {
|
||||||
return randomString(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
function newBranchId() {
|
|
||||||
return randomString(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
function newNoteRevisionId() {
|
|
||||||
return randomString(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
function newImageId() {
|
|
||||||
return randomString(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
function newNoteImageId() {
|
|
||||||
return randomString(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
function newLabelId() {
|
|
||||||
return randomString(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
function newApiTokenId() {
|
|
||||||
return randomString(12);
|
return randomString(12);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,13 +130,7 @@ module.exports = {
|
|||||||
dateStr,
|
dateStr,
|
||||||
parseDate,
|
parseDate,
|
||||||
parseDateTime,
|
parseDateTime,
|
||||||
newNoteId,
|
newEntityId,
|
||||||
newBranchId,
|
|
||||||
newNoteRevisionId,
|
|
||||||
newImageId,
|
|
||||||
newNoteImageId,
|
|
||||||
newLabelId,
|
|
||||||
newApiTokenId,
|
|
||||||
toBase64,
|
toBase64,
|
||||||
fromBase64,
|
fromBase64,
|
||||||
hmac,
|
hmac,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user