mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 09:05:36 +01:00
- Add support for multiple share URLs per website with server-generated slugs - Create shares API endpoint for listing and creating website shares - Add SharesTable, ShareEditButton, ShareDeleteButton components - Move share management to website settings, remove header share button - Remove shareId from website update API (now uses separate share table) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
import { z } from 'zod';
|
|
import { ENTITY_TYPE } from '@/lib/constants';
|
|
import { uuid } from '@/lib/crypto';
|
|
import { getRandomChars } from '@/lib/generate';
|
|
import { parseRequest } from '@/lib/request';
|
|
import { json, unauthorized } from '@/lib/response';
|
|
import { anyObjectParam, filterParams, pagingParams } from '@/lib/schema';
|
|
import { canUpdateWebsite, canViewWebsite } from '@/permissions';
|
|
import { createShare, getSharesByEntityId } from '@/queries/prisma';
|
|
|
|
export async function GET(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ websiteId: string }> },
|
|
) {
|
|
const schema = z.object({
|
|
...filterParams,
|
|
...pagingParams,
|
|
});
|
|
|
|
const { auth, query, error } = await parseRequest(request, schema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const { websiteId } = await params;
|
|
const { page, pageSize, search } = query;
|
|
|
|
if (!(await canViewWebsite(auth, websiteId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const data = await getSharesByEntityId(websiteId, {
|
|
page,
|
|
pageSize,
|
|
search,
|
|
});
|
|
|
|
return json(data);
|
|
}
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ websiteId: string }> },
|
|
) {
|
|
const schema = z.object({
|
|
parameters: anyObjectParam.optional(),
|
|
});
|
|
|
|
const { auth, body, error } = await parseRequest(request, schema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const { websiteId } = await params;
|
|
const { parameters = {} } = body;
|
|
|
|
if (!(await canUpdateWebsite(auth, websiteId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const slug = getRandomChars(16);
|
|
|
|
const share = await createShare({
|
|
id: uuid(),
|
|
entityId: websiteId,
|
|
shareType: ENTITY_TYPE.website,
|
|
slug,
|
|
parameters,
|
|
});
|
|
|
|
return json(share);
|
|
}
|