mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	shortening of noteIds to 12 characters
This commit is contained in:
		
							
								
								
									
										6
									
								
								migrations/0016__trim_note_ids2.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								migrations/0016__trim_note_ids2.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| UPDATE notes SET note_id = substr(note_id, 0, 13); | ||||
| UPDATE notes_tree SET note_id = substr(note_id, 0, 13), note_pid = substr(note_pid, 0, 13); | ||||
| UPDATE notes_history SET note_id = substr(note_id, 0, 13); | ||||
| UPDATE audit_log SET note_id = substr(note_id, 0, 13); | ||||
| UPDATE links SET note_id = substr(note_id, 0, 13); | ||||
| UPDATE images SET note_id = substr(note_id, 0, 13); | ||||
| @@ -90,7 +90,7 @@ function goToInternalNote(e, callback) { | ||||
| } | ||||
|  | ||||
| function getNoteIdFromLink(url) { | ||||
|     const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(url); | ||||
|     const noteIdMatch = /app#([A-Za-z0-9]{12})/.exec(url); | ||||
|  | ||||
|     if (noteIdMatch === null) { | ||||
|         return null; | ||||
| @@ -101,7 +101,7 @@ function getNoteIdFromLink(url) { | ||||
| } | ||||
|  | ||||
| function getNodeIdFromLabel(label) { | ||||
|     const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(label); | ||||
|     const noteIdMatch = / \(([A-Za-z0-9]{12})\)/.exec(label); | ||||
|  | ||||
|     if (noteIdMatch !== null) { | ||||
|         return noteIdMatch[1]; | ||||
|   | ||||
| @@ -51,7 +51,7 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => { | ||||
|         'password_derived_key_salt': await sql.getOption('password_derived_key_salt'), | ||||
|         'encrypted_data_key': await sql.getOption('encrypted_data_key'), | ||||
|         'encryption_session_timeout': await sql.getOption('encryption_session_timeout'), | ||||
|         'browser_id': utils.randomToken(8), | ||||
|         'browser_id': utils.randomString(12), | ||||
|         'full_load_time': utils.nowTimestamp() | ||||
|     }); | ||||
| }); | ||||
|   | ||||
| @@ -3,7 +3,7 @@ const sql = require('./sql'); | ||||
| const fs = require('fs-extra'); | ||||
| const log = require('./log'); | ||||
|  | ||||
| const APP_DB_VERSION = 15; | ||||
| const APP_DB_VERSION = 16; | ||||
| const MIGRATIONS_DIR = "./migrations"; | ||||
|  | ||||
| async function migrate() { | ||||
|   | ||||
| @@ -82,7 +82,7 @@ async function addAudit(category, req=null, noteId=null, changeFrom=null, change | ||||
|     log.info("audit: " + category + ", browserId=" + browserId + ", noteId=" + noteId + ", from=" + changeFrom | ||||
|         + ", to=" + changeTo + ", comment=" + comment); | ||||
|  | ||||
|     const id = utils.randomToken(14); | ||||
|     const id = utils.randomString(14); | ||||
|  | ||||
|     await execute("INSERT INTO audit_log (id, date_modified, category, browser_id, note_id, change_from, change_to, comment)" | ||||
|            + " VALUES (?, ?, ?, ?, ?, ?, ?, ?)", [id, now, category, browserId, noteId, changeFrom, changeTo, comment]); | ||||
|   | ||||
| @@ -1,20 +1,16 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const crypto = require('crypto'); | ||||
|  | ||||
| function randomToken(length) { | ||||
|     return crypto.randomBytes(length).toString('base64'); | ||||
| } | ||||
|  | ||||
| function newNoteId() { | ||||
|     return randomString(22, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); | ||||
|     return randomString(12); | ||||
| } | ||||
|  | ||||
| const ALPHA_NUMERIC = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||||
|  | ||||
| function randomString(length, chars) { | ||||
|     let result = ''; | ||||
|  | ||||
|     for (let i = length; i > 0; --i) { | ||||
|         result += chars[Math.floor(Math.random() * chars.length)]; | ||||
|         result += ALPHA_NUMERIC[Math.floor(Math.random() * ALPHA_NUMERIC.length)]; | ||||
|     } | ||||
|  | ||||
|     return result; | ||||
| @@ -33,7 +29,7 @@ function fromBase64(encodedText) { | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
|     randomToken, | ||||
|     randomString, | ||||
|     nowTimestamp, | ||||
|     newNoteId, | ||||
|     toBase64, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user