mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 03:58:02 -05:00
Merge pull request #1319 from hedgedoc/fix/note_create_publicid
Move publicId creation to Note.create
This commit is contained in:
commit
04e590c9fd
3 changed files with 19 additions and 10 deletions
|
@ -21,6 +21,7 @@ import { AuthorColor } from './author-color.entity';
|
|||
import { Tag } from './tag.entity';
|
||||
import { HistoryEntry } from '../history/history-entry.entity';
|
||||
import { MediaUpload } from '../media/media-upload.entity';
|
||||
import { generatePublicId } from './utils';
|
||||
|
||||
@Entity()
|
||||
export class Note {
|
||||
|
@ -85,6 +86,7 @@ export class Note {
|
|||
|
||||
public static create(owner?: User, alias?: string): Note {
|
||||
const newNote = new Note();
|
||||
newNote.publicId = generatePublicId();
|
||||
newNote.alias = alias ?? null;
|
||||
newNote.viewCount = 0;
|
||||
newNote.owner = owner ?? null;
|
||||
|
|
|
@ -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
|
||||
|
|
17
src/notes/utils.ts
Normal file
17
src/notes/utils.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import base32Encode from 'base32-encode';
|
||||
import { randomBytes } from 'crypto';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export function generatePublicId(): string {
|
||||
const randomId = randomBytes(128);
|
||||
return base32Encode(randomId, 'Crockford').toLowerCase();
|
||||
}
|
Loading…
Reference in a new issue