mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +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>
39 lines
988 B
TypeScript
39 lines
988 B
TypeScript
import z from 'zod';
|
|
import { uuid } from '@/lib/crypto';
|
|
import { getRandomChars } from '@/lib/generate';
|
|
import { parseRequest } from '@/lib/request';
|
|
import { json, unauthorized } from '@/lib/response';
|
|
import { anyObjectParam } from '@/lib/schema';
|
|
import { canUpdateEntity } from '@/permissions';
|
|
import { createShare } from '@/queries/prisma';
|
|
|
|
export async function POST(request: Request) {
|
|
const schema = z.object({
|
|
entityId: z.uuid(),
|
|
shareType: z.coerce.number().int(),
|
|
slug: z.string().max(100).optional(),
|
|
parameters: anyObjectParam,
|
|
});
|
|
|
|
const { auth, body, error } = await parseRequest(request, schema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const { entityId, shareType, slug, parameters } = body;
|
|
|
|
if (!(await canUpdateEntity(auth, entityId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const share = await createShare({
|
|
id: uuid(),
|
|
entityId,
|
|
shareType,
|
|
slug: slug || getRandomChars(16),
|
|
parameters,
|
|
});
|
|
|
|
return json(share);
|
|
}
|