mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
Move publicID
creation to Note.create
Before this commit, `Note.create()` did not return a complete object, as the `publicId` property was missing. This adds the generation of the property to the `create` method and moves the actual generation code from the `NotesService` to a utility method. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
0aa27e01b0
commit
9e5d95657d
3 changed files with 19 additions and 10 deletions
|
@ -94,7 +94,6 @@ export class NotesService {
|
|||
newNote.revisions = Promise.resolve([
|
||||
Revision.create(noteContent, noteContent),
|
||||
]);
|
||||
newNote.publicId = this.generatePublicId();
|
||||
if (alias) {
|
||||
newNote.alias = alias;
|
||||
this.checkNoteIdOrAlias(alias);
|
||||
|
@ -213,15 +212,6 @@ export class NotesService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate publicId for a note.
|
||||
* This is a randomly generated 128-bit value encoded with base32-encode using the crockford variant and converted to lowercase.
|
||||
*/
|
||||
generatePublicId(): string {
|
||||
const randomId = randomBytes(128);
|
||||
return base32Encode(randomId, 'Crockford').toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Delete a note
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue