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
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import crypto from "node:crypto";
|
|
import type { NotificationEventType } from "@shared/types";
|
|
import { NotificationEventDefaults } from "@shared/types";
|
|
import env from "@server/env";
|
|
|
|
/**
|
|
* Helper class for working with notification settings
|
|
*/
|
|
export default class NotificationSettingsHelper {
|
|
/**
|
|
* Get the default notification settings for a user
|
|
*
|
|
* @returns The default notification settings
|
|
*/
|
|
public static getDefaults() {
|
|
return NotificationEventDefaults;
|
|
}
|
|
|
|
/**
|
|
* Get the unsubscribe URL for a user and event type. This url allows the user
|
|
* to unsubscribe from a specific event without being signed in, for one-click
|
|
* links in emails.
|
|
*
|
|
* @param userId The user ID to unsubscribe
|
|
* @param eventType The event type to unsubscribe from
|
|
* @returns The unsubscribe URL
|
|
*/
|
|
public static unsubscribeUrl(
|
|
userId: string,
|
|
eventType: NotificationEventType
|
|
) {
|
|
return `${
|
|
env.URL
|
|
}/api/notifications.unsubscribe?token=${this.unsubscribeToken(
|
|
userId,
|
|
eventType
|
|
)}&userId=${userId}&eventType=${eventType}`;
|
|
}
|
|
|
|
public static unsubscribeToken(
|
|
userId: string,
|
|
eventType: NotificationEventType
|
|
) {
|
|
const hash = crypto.createHash("sha256");
|
|
hash.update(`${userId}-${env.SECRET_KEY}-${eventType}`);
|
|
return hash.digest("hex");
|
|
}
|
|
}
|