mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-28 14:14:34 +00:00
feat(notes): Use publicId in notes service
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
e1ac2cfa69
commit
b7e52f8166
1 changed files with 14 additions and 3 deletions
|
@ -32,6 +32,8 @@ import { NoteGroupPermission } from '../permissions/note-group-permission.entity
|
|||
import { GroupsService } from '../groups/groups.service';
|
||||
import { checkArrayForDuplicates } from '../utils/arrayDuplicatCheck';
|
||||
import appConfiguration, { AppConfig } from '../config/app.config';
|
||||
import base32Encode from 'base32-encode';
|
||||
import { randomBytes } from 'crypto';
|
||||
|
||||
@Injectable()
|
||||
export class NotesService {
|
||||
|
@ -92,6 +94,7 @@ export class NotesService {
|
|||
newNote.revisions = Promise.resolve([
|
||||
Revision.create(noteContent, noteContent),
|
||||
]);
|
||||
newNote.publicId = this.generatePublicId();
|
||||
if (alias) {
|
||||
newNote.alias = alias;
|
||||
this.checkNoteIdOrAlias(alias);
|
||||
|
@ -164,7 +167,7 @@ export class NotesService {
|
|||
const note = await this.noteRepository.findOne({
|
||||
where: [
|
||||
{
|
||||
id: noteIdOrAlias,
|
||||
publicId: noteIdOrAlias,
|
||||
},
|
||||
{
|
||||
alias: noteIdOrAlias,
|
||||
|
@ -210,6 +213,15 @@ 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
|
||||
|
@ -358,8 +370,7 @@ export class NotesService {
|
|||
async toNoteMetadataDto(note: Note): Promise<NoteMetadataDto> {
|
||||
const updateUser = await this.calculateUpdateUser(note);
|
||||
return {
|
||||
// TODO: Convert DB UUID to base64
|
||||
id: note.id,
|
||||
id: note.publicId,
|
||||
alias: note.alias ?? null,
|
||||
title: note.title ?? '',
|
||||
createTime: (await this.getFirstRevision(note)).createdAt,
|
||||
|
|
Loading…
Reference in a new issue