7c373ddad6
* Configure biome * Fix companion build * fix: remove generated files from formatter ignore list to enable proper formatting Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: add explicit stripe dependency to @calcom/features to fix type resolution Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: rename const require to nodeRequire in generate-swagger.ts to avoid TypeScript reserved identifier conflict Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: add guard for document in makeBodyVisible to prevent test environment teardown errors Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: replace ESLint with Biome CLI in embed-code-generator.e2e.ts Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: address cubic review comments - Fix invalid --reporter-path Biome CLI option by using shell redirection - Fix packages/lib lint report filename (app-store.json -> lib.json) - Add typescript-eslint and eslint back to companion for lint:react-compiler - Add missing restricted import rules to biome.json: - packages/lib: add ../trpc/** and @trpc/server restrictions - packages/trpc: add ../apps/web/** restriction Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * chore: regenerate companion bun.lock after adding eslint dependencies Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * Remove remaining eslint things * add tailwind directives --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { createHmac } from "node:crypto";
|
|
|
|
// 262992 minutes is 6 months
|
|
export function generateVideoToken(
|
|
recordingId: string,
|
|
expiresInMinutes = 262992
|
|
) {
|
|
const secret =
|
|
process.env.CAL_VIDEO_RECORDING_TOKEN_SECRET || "default-secret-change-me";
|
|
const expires = Date.now() + expiresInMinutes * 60 * 1000;
|
|
|
|
const payload = `${recordingId}:${expires}`;
|
|
const hmac = createHmac("sha256", secret).update(payload).digest("hex");
|
|
|
|
return `${payload}:${hmac}`;
|
|
}
|
|
|
|
export function verifyVideoToken(token: string): {
|
|
valid: boolean;
|
|
recordingId?: string;
|
|
} {
|
|
try {
|
|
const [recordingId, expires, receivedHmac] = token.split(":");
|
|
const secret =
|
|
process.env.CAL_VIDEO_RECORDING_TOKEN_SECRET ||
|
|
"default-secret-change-me";
|
|
|
|
if (Date.now() > parseInt(expires, 10)) {
|
|
return { valid: false };
|
|
}
|
|
|
|
// Verify HMAC
|
|
const payload = `${recordingId}:${expires}`;
|
|
const expectedHmac = createHmac("sha256", secret)
|
|
.update(payload)
|
|
.digest("hex");
|
|
|
|
if (receivedHmac !== expectedHmac) {
|
|
return { valid: false };
|
|
}
|
|
|
|
return { valid: true, recordingId };
|
|
} catch {
|
|
return { valid: false };
|
|
}
|
|
}
|