el.xwx.moe/pages/api/v1/collections/index.ts

31 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-02-06 11:59:23 -06:00
import type { NextApiRequest, NextApiResponse } from "next";
2023-02-18 21:32:02 -06:00
import getCollections from "@/lib/api/controllers/collections/getCollections";
import postCollection from "@/lib/api/controllers/collections/postCollection";
import verifyUser from "@/lib/api/verifyUser";
2023-02-06 11:59:23 -06:00
export default async function collections(
req: NextApiRequest,
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
if (!user) return;
2023-02-06 11:59:23 -06:00
2023-03-28 02:31:50 -05:00
if (req.method === "GET") {
2023-11-02 13:59:31 -05:00
const collections = await getCollections(user.id);
2023-03-28 02:31:50 -05:00
return res
.status(collections.status)
.json({ response: collections.response });
} else if (req.method === "POST") {
2024-07-18 15:29:59 -05:00
if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
});
2023-11-02 13:59:31 -05:00
const newCollection = await postCollection(req.body, user.id);
2023-03-28 02:31:50 -05:00
return res
.status(newCollection.status)
.json({ response: newCollection.response });
}
2023-02-06 11:59:23 -06:00
}