Files
songs2vid/lib/quota.ts
T
Atakan Doğan Özban d9cdaff521 Strip Songs2VID to a payment-free self-hosted OSS core.
Remove Stripe/billing/pricing/marketing, simplify schema and entitlements for unlimited self-host use, and keep auth, encode, and YouTube upload.
2026-08-03 06:52:00 +02:00

40 lines
1.2 KiB
TypeScript

import { prisma } from "./db";
import { APP_LIMITS } from "./plans";
export async function getQuotaInfo(userId: string) {
const user = await prisma.user.findUniqueOrThrow({ where: { id: userId } });
return {
used: user.createdVideoCount,
createdVideoCount: user.createdVideoCount,
maxBatchSize: APP_LIMITS.maxBatchSize,
maxResolutionHeight: APP_LIMITS.maxResolutionHeight,
watermarkOptional: true,
customWatermark: true,
perItemImages: true,
artTrackLayouts: true,
selfHosted: true,
unlimited: true,
};
}
export async function checkQuota(userId: string, requestedCount: number) {
const info = await getQuotaInfo(userId);
if (requestedCount > info.maxBatchSize) {
return {
ok: false as const,
error: `Batch limit exceeded. Max ${info.maxBatchSize} files per batch.`,
...info,
};
}
return { ok: true as const, ...info };
}
export async function reserveQuota(userId: string, count: number) {
if (count > APP_LIMITS.maxBatchSize) {
throw new Error(`Batch limit exceeded. Max ${APP_LIMITS.maxBatchSize} files per batch.`);
}
await prisma.user.findUniqueOrThrow({ where: { id: userId } });
}