mirror of
https://github.com/umami-software/umami.git
synced 2026-02-16 02:25:35 +01:00
Initial Typescript models.
This commit is contained in:
parent
04e9f06e93
commit
0aaba8cbd1
74 changed files with 1144 additions and 768 deletions
37
pages/api/share/[id].ts
Normal file
37
pages/api/share/[id].ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue