added new api route + fixed dropdown
This commit is contained in:
+19
-3
@@ -14,13 +14,29 @@ export default async function archive(
|
||||
},
|
||||
});
|
||||
|
||||
// const checkExistingLink = await prisma.link.findFirst({
|
||||
// where: {
|
||||
// id: linkId,
|
||||
// OR: [
|
||||
// {
|
||||
// screenshotPath: "pending",
|
||||
// },
|
||||
// {
|
||||
// pdfPath: "pending",
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (checkExistingLink) return "A request has already been made.";
|
||||
|
||||
const link = await prisma.link.update({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
data: {
|
||||
screenshotPath: "pending",
|
||||
pdfPath: "pending",
|
||||
screenshotPath: user?.archiveAsScreenshot ? "pending" : null,
|
||||
pdfPath: user?.archiveAsPDF ? "pending" : null,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -88,8 +104,8 @@ export default async function archive(
|
||||
|
||||
await browser.close();
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
await browser.close();
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { Collection, Link, UsersAndCollections } from "@prisma/client";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
|
||||
export default async function getLinkById(userId: number, linkId: number) {
|
||||
if (!linkId)
|
||||
return {
|
||||
response: "Please choose a valid link.",
|
||||
status: 401,
|
||||
};
|
||||
|
||||
const collectionIsAccessible = (await getPermission({ userId, linkId })) as
|
||||
| (Collection & {
|
||||
members: UsersAndCollections[];
|
||||
})
|
||||
| null;
|
||||
|
||||
const memberHasAccess = collectionIsAccessible?.members.some(
|
||||
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
|
||||
);
|
||||
|
||||
const isCollectionOwner = collectionIsAccessible?.ownerId === userId;
|
||||
|
||||
if (collectionIsAccessible?.ownerId !== userId && !memberHasAccess)
|
||||
return {
|
||||
response: "Collection is not accessible.",
|
||||
status: 401,
|
||||
};
|
||||
else {
|
||||
const updatedLink = await prisma.link.findUnique({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
include: {
|
||||
tags: true,
|
||||
collection: true,
|
||||
pinnedBy: isCollectionOwner
|
||||
? {
|
||||
where: { id: userId },
|
||||
select: { id: true },
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
return { response: updatedLink, status: 200 };
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { Collection, Link, UsersAndCollections } from "@prisma/client";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
import moveFile from "@/lib/api/storage/moveFile";
|
||||
|
||||
export default async function updateLink(
|
||||
export default async function updateLinkById(
|
||||
userId: number,
|
||||
linkId: number,
|
||||
data: LinkIncludingShortenedCollectionAndTags
|
||||
|
||||
Reference in New Issue
Block a user