Added website check for cloud.
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run
Create docker images / Build, push, and deploy (push) Has been cancelled

This commit is contained in:
Mike Cao 2025-10-04 00:38:10 -07:00
parent ed013d5d58
commit 03adb6b7e1
4 changed files with 32 additions and 65 deletions

View file

@ -4,9 +4,11 @@ import { json, unauthorized } from '@/lib/response';
import { uuid } from '@/lib/crypto';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { pagingParams, searchParams } from '@/lib/schema';
import { createWebsite } from '@/queries/prisma';
import { createWebsite, getWebsiteCount } from '@/queries/prisma';
import { getAllUserWebsitesIncludingTeamOwner, getUserWebsites } from '@/queries/prisma/website';
const CLOUD_WEBSITE_LIMIT = 3;
export async function GET(request: Request) {
const schema = z.object({
...pagingParams,
@ -36,7 +38,7 @@ export async function POST(request: Request) {
name: z.string().max(100),
domain: z.string().max(500),
shareId: z.string().max(50).nullable().optional(),
teamId: z.string().nullable().optional(),
teamId: z.uuid().nullable().optional(),
id: z.uuid().nullable().optional(),
});
@ -48,6 +50,14 @@ export async function POST(request: Request) {
const { id, name, domain, shareId, teamId } = body;
if (process.env.CLOUD_MODE && !teamId && !auth.user.hasSubscription) {
const count = await getWebsiteCount(auth.user.id);
if (count >= CLOUD_WEBSITE_LIMIT) {
return unauthorized({ message: 'Website limit reached.' });
}
}
if ((teamId && !(await canCreateTeamWebsite(auth, teamId))) || !(await canCreateWebsite(auth))) {
return unauthorized();
}