You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
592 B
17 lines
592 B
import { randomBytes } from "crypto";
|
|
import type { Visibility } from "#server/constants/visibility";
|
|
|
|
/** URL-safe token, ~43 chars */
|
|
export function newShareToken(): string {
|
|
return randomBytes(32).toString("base64url");
|
|
}
|
|
|
|
/**
|
|
* `unlisted` 需要 token;切回 public/private 时清空 token(分享链失效)。
|
|
*/
|
|
export function visibilityShareToken(visibility: Visibility, previousToken: string | null | undefined): string | null {
|
|
if (visibility === "unlisted") {
|
|
return previousToken && previousToken.length > 0 ? previousToken : newShareToken();
|
|
}
|
|
return null;
|
|
}
|
|
|