mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Added website check for cloud.
This commit is contained in:
parent
ed013d5d58
commit
03adb6b7e1
4 changed files with 32 additions and 65 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue