2023-08-10 11:16:44 -05:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { getServerSession } from "next-auth/next";
|
|
|
|
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
2023-10-01 11:33:40 -05:00
|
|
|
import getData from "@/lib/api/controllers/migration/getData";
|
|
|
|
import postData from "@/lib/api/controllers/migration/postData";
|
2023-08-10 11:16:44 -05:00
|
|
|
|
|
|
|
export default async function users(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
const session = await getServerSession(req, res, authOptions);
|
|
|
|
|
|
|
|
if (!session?.user.id) {
|
|
|
|
return res.status(401).json({ response: "You must be logged in." });
|
|
|
|
} else if (session?.user?.isSubscriber === false)
|
|
|
|
res.status(401).json({
|
|
|
|
response:
|
|
|
|
"You are not a subscriber, feel free to reach out to us at support@linkwarden.app in case of any issues.",
|
|
|
|
});
|
|
|
|
|
|
|
|
if (req.method === "GET") {
|
|
|
|
const data = await getData(session.user.id);
|
2023-10-01 11:33:40 -05:00
|
|
|
|
2023-08-10 11:16:44 -05:00
|
|
|
if (data.status === 200)
|
|
|
|
return res
|
|
|
|
.setHeader("Content-Type", "application/json")
|
|
|
|
.setHeader("Content-Disposition", "attachment; filename=backup.json")
|
|
|
|
.status(data.status)
|
|
|
|
.json(data.response);
|
|
|
|
} else if (req.method === "POST") {
|
2023-10-01 11:33:40 -05:00
|
|
|
const data = await postData(session.user.id, req.body);
|
2023-08-10 11:16:44 -05:00
|
|
|
return res.status(data.status).json({ response: data.response });
|
|
|
|
}
|
|
|
|
}
|