@@ -31,10 +31,10 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
.status(401)
|
||||
.json({ response: "You don't have access to this collection." });
|
||||
|
||||
const { file, contentType } = await readFile({
|
||||
filePath: `archives/${collectionId}/${linkId}`,
|
||||
});
|
||||
res.setHeader("Content-Type", contentType).status(200);
|
||||
const { file, contentType, status } = await readFile(
|
||||
`archives/${collectionId}/${linkId}`
|
||||
);
|
||||
res.setHeader("Content-Type", contentType).status(status as number);
|
||||
|
||||
return res.send(file);
|
||||
}
|
||||
|
||||
+16
-16
@@ -13,7 +13,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
if (!userId || !username)
|
||||
return res
|
||||
.setHeader("Content-Type", "text/plain")
|
||||
.setHeader("Content-Type", "text/html")
|
||||
.status(401)
|
||||
.send("You must be logged in.");
|
||||
else if (session?.user?.isSubscriber === false)
|
||||
@@ -24,7 +24,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
if (!queryId)
|
||||
return res
|
||||
.setHeader("Content-Type", "text/plain")
|
||||
.setHeader("Content-Type", "text/html")
|
||||
.status(401)
|
||||
.send("Invalid parameters.");
|
||||
|
||||
@@ -34,27 +34,27 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
id: queryId,
|
||||
},
|
||||
include: {
|
||||
whitelistedUsers: true
|
||||
}
|
||||
whitelistedUsers: true,
|
||||
},
|
||||
});
|
||||
|
||||
const whitelistedUsernames = targetUser?.whitelistedUsers.map(whitelistedUsername => whitelistedUsername.username);
|
||||
const whitelistedUsernames = targetUser?.whitelistedUsers.map(
|
||||
(whitelistedUsername) => whitelistedUsername.username
|
||||
);
|
||||
|
||||
if (
|
||||
targetUser?.isPrivate &&
|
||||
!whitelistedUsernames?.includes(username)
|
||||
) {
|
||||
if (targetUser?.isPrivate && !whitelistedUsernames?.includes(username)) {
|
||||
return res
|
||||
.setHeader("Content-Type", "text/plain")
|
||||
.setHeader("Content-Type", "text/html")
|
||||
.send("This profile is private.");
|
||||
}
|
||||
}
|
||||
|
||||
const { file, contentType } = await readFile({
|
||||
filePath: `uploads/avatar/${queryId}.jpg`,
|
||||
});
|
||||
const { file, contentType, status } = await readFile(
|
||||
`uploads/avatar/${queryId}.jpg`
|
||||
);
|
||||
|
||||
res.setHeader("Content-Type", contentType);
|
||||
|
||||
return res.send(file);
|
||||
return res
|
||||
.setHeader("Content-Type", contentType)
|
||||
.status(status as number)
|
||||
.send(file);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
||||
import getData from "@/lib/api/controllers/data/getData";
|
||||
import postData from "@/lib/api/controllers/data/postData";
|
||||
|
||||
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);
|
||||
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") {
|
||||
console.log(JSON.parse(req.body));
|
||||
const data = await postData(session.user.id, JSON.parse(req.body));
|
||||
return res.status(data.status).json({ response: data.response });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user