mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
00fb4d1af7
- crypto → node:crypto - fs → node:fs - fs/promises → node:fs/promises - path → node:path - http → node:http - https → node:https - stream → node:stream - buffer → node:buffer - url → node:url - os → node:os - net → node:net - dns → node:dns - events → node:events - readline → node:readline - querystring → node:querystring - util → node:util
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import crypto from "node:crypto";
|
|
import queryString from "query-string";
|
|
import env from "@server/env";
|
|
|
|
/**
|
|
* Helper class for working with subscription settings
|
|
*/
|
|
export default class SubscriptionHelper {
|
|
/**
|
|
* Get the unsubscribe URL for a user and document. This url allows the user
|
|
* to unsubscribe from a specific document without being signed in, for one-click
|
|
* links in emails.
|
|
*
|
|
* @param userId The user ID to unsubscribe
|
|
* @param documentId The document ID to unsubscribe from
|
|
* @returns The unsubscribe URL
|
|
*/
|
|
public static unsubscribeUrl(userId: string, documentId: string) {
|
|
const token = this.unsubscribeToken(userId, documentId);
|
|
|
|
return `${env.URL}/api/subscriptions.delete?${queryString.stringify({
|
|
token,
|
|
userId,
|
|
documentId,
|
|
})}`;
|
|
}
|
|
|
|
/**
|
|
* Generate a token for unsubscribing a user from a document or collection.
|
|
*
|
|
* @param userId The user ID to unsubscribe
|
|
* @param documentId The document ID to unsubscribe from
|
|
* @returns The unsubscribe token
|
|
*/
|
|
public static unsubscribeToken(userId: string, documentId: string) {
|
|
const hash = crypto.createHash("sha256");
|
|
hash.update(`${userId}-${env.SECRET_KEY}-${documentId}`);
|
|
return hash.digest("hex");
|
|
}
|
|
}
|