mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 10:49:21 +00:00
27 lines
814 B
TypeScript
27 lines
814 B
TypeScript
export interface ApiKeyGenerator {
|
|
generateServerApiKey(): string;
|
|
generateReverseProxyApiKey(): string;
|
|
}
|
|
|
|
export class ApiKeyGeneratorImpl implements ApiKeyGenerator {
|
|
private readonly SERVER_PREFIX = "minikura_srv_";
|
|
private readonly REVERSE_PROXY_PREFIX = "minikura_proxy_";
|
|
private readonly TOKEN_LENGTH = 32;
|
|
|
|
generateServerApiKey(): string {
|
|
const token = Buffer.from(crypto.randomUUID())
|
|
.toString("base64")
|
|
.replace(/[^a-zA-Z0-9]/g, "")
|
|
.substring(0, this.TOKEN_LENGTH);
|
|
return `${this.SERVER_PREFIX}${token}`;
|
|
}
|
|
|
|
generateReverseProxyApiKey(): string {
|
|
const token = Buffer.from(crypto.randomUUID())
|
|
.toString("base64")
|
|
.replace(/[^a-zA-Z0-9]/g, "")
|
|
.substring(0, this.TOKEN_LENGTH);
|
|
return `${this.REVERSE_PROXY_PREFIX}${token}`;
|
|
}
|
|
}
|