mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 09:45:37 -04:00

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>
17 lines
523 B
TypeScript
17 lines
523 B
TypeScript
/*
|
|
* 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();
|
|
}
|