mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
38 lines
858 B
TypeScript
38 lines
858 B
TypeScript
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
|
import { secret } from 'lib/crypto';
|
|
import { NextApiResponse } from 'next';
|
|
import { createToken, methodNotAllowed, notFound, ok } from 'next-basics';
|
|
import { getWebsite } from 'queries';
|
|
|
|
export interface ShareRequestQuery {
|
|
id: string;
|
|
}
|
|
|
|
export interface ShareResponse {
|
|
id: string;
|
|
token: string;
|
|
}
|
|
|
|
export default async (
|
|
req: NextApiRequestQueryBody<ShareRequestQuery>,
|
|
res: NextApiResponse<ShareResponse>,
|
|
) => {
|
|
const { id: shareId } = req.query;
|
|
|
|
if (req.method === 'GET') {
|
|
const website = await getWebsite({ shareId });
|
|
|
|
if (website) {
|
|
const { id } = website;
|
|
const data = { id };
|
|
const token = createToken(data, secret());
|
|
|
|
return ok(res, { ...data, token });
|
|
}
|
|
|
|
return notFound(res);
|
|
}
|
|
|
|
return methodNotAllowed(res);
|
|
};
|