mirror of https://github.com/sylv/micro.git
17 lines
557 B
TypeScript
17 lines
557 B
TypeScript
import { customAlphabet } from "nanoid";
|
|
import blocklist from "../blocklist.json";
|
|
|
|
// note: changing this will require changes to the file.service.ts regex
|
|
export const contentIdLength = 6;
|
|
export const contentIdAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
export const contentIdGenerator = customAlphabet(contentIdAlphabet, contentIdLength);
|
|
|
|
export function generateContentId(): string {
|
|
const id = contentIdGenerator();
|
|
if (blocklist.includes(id.toLowerCase())) {
|
|
return generateContentId();
|
|
}
|
|
|
|
return id;
|
|
}
|