mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
- Introduced `CloudflareStreamPlayer` React component for embedding streams - Updated `package.json` with new dependencies: `@cloudflare/stream-react` and `stripe` - Extended database schema with user tiers, Stripe billing, storage, and archive management - Added access control logic in `access.ts` for user tiers and feature permissions - Enhanced billing logic with archive storage limits and subscription checks
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import Stripe from "stripe"
|
|
|
|
type StripeEnv = {
|
|
STRIPE_SECRET_KEY?: string
|
|
STRIPE_WEBHOOK_SECRET?: string
|
|
STRIPE_ARCHIVE_PRICE_ID?: string // Archive subscription price
|
|
}
|
|
|
|
const getEnv = (): StripeEnv => {
|
|
let STRIPE_SECRET_KEY: string | undefined
|
|
let STRIPE_WEBHOOK_SECRET: string | undefined
|
|
let STRIPE_ARCHIVE_PRICE_ID: string | undefined
|
|
|
|
try {
|
|
const { getServerContext } = require("@tanstack/react-start/server") as {
|
|
getServerContext: () => { cloudflare?: { env?: StripeEnv } } | null
|
|
}
|
|
const ctx = getServerContext()
|
|
STRIPE_SECRET_KEY = ctx?.cloudflare?.env?.STRIPE_SECRET_KEY
|
|
STRIPE_WEBHOOK_SECRET = ctx?.cloudflare?.env?.STRIPE_WEBHOOK_SECRET
|
|
STRIPE_ARCHIVE_PRICE_ID = ctx?.cloudflare?.env?.STRIPE_ARCHIVE_PRICE_ID
|
|
} catch {
|
|
// Not in server context
|
|
}
|
|
|
|
STRIPE_SECRET_KEY = STRIPE_SECRET_KEY ?? process.env.STRIPE_SECRET_KEY
|
|
STRIPE_WEBHOOK_SECRET =
|
|
STRIPE_WEBHOOK_SECRET ?? process.env.STRIPE_WEBHOOK_SECRET
|
|
STRIPE_ARCHIVE_PRICE_ID =
|
|
STRIPE_ARCHIVE_PRICE_ID ?? process.env.STRIPE_ARCHIVE_PRICE_ID
|
|
|
|
return { STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, STRIPE_ARCHIVE_PRICE_ID }
|
|
}
|
|
|
|
export const getStripe = (): Stripe | null => {
|
|
const env = getEnv()
|
|
|
|
if (!env.STRIPE_SECRET_KEY) {
|
|
return null
|
|
}
|
|
|
|
return new Stripe(env.STRIPE_SECRET_KEY)
|
|
}
|
|
|
|
export const getStripeConfig = () => {
|
|
const env = getEnv()
|
|
return {
|
|
webhookSecret: env.STRIPE_WEBHOOK_SECRET,
|
|
archivePriceId: env.STRIPE_ARCHIVE_PRICE_ID,
|
|
}
|
|
}
|