small improvement
This commit is contained in:
parent
3628d4281a
commit
5b0e0b4208
|
@ -155,9 +155,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
|||
<div className="relative">
|
||||
<div className="flex flex-col items-end justify-center gap-1">
|
||||
<a
|
||||
href={`/api/archives/${
|
||||
link.collectionId
|
||||
}/${encodeURIComponent(link.screenshotPath)}`}
|
||||
href={`/api/archives/${link.collectionId}/${link.id}.png`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
title="Screenshot"
|
||||
|
@ -168,9 +166,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
|||
/>
|
||||
</a>
|
||||
<a
|
||||
href={`/api/archives/${
|
||||
link.collectionId
|
||||
}/${encodeURIComponent(link.pdfPath)}`}
|
||||
href={`/api/archives/${link.collectionId}/${link.id}.pdf`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
title="PDF"
|
||||
|
|
|
@ -80,7 +80,7 @@ export default function ProfileSettings({
|
|||
<div className="w-28 h-28 flex items-center justify-center border border-sky-100 rounded-full relative">
|
||||
<ProfilePhoto
|
||||
src={user.profilePic}
|
||||
className="h-auto aspect-square w-28 border-[0px]"
|
||||
className="h-auto aspect-square w-28 border-[1px]"
|
||||
status={handleProfileStatus}
|
||||
/>
|
||||
{profileStatus && (
|
||||
|
|
|
@ -3,7 +3,6 @@ import { LinkIncludingCollectionAndTags } from "@/types/global";
|
|||
import getTitle from "../../getTitle";
|
||||
import archive from "../../archive";
|
||||
import { Link, UsersAndCollections } from "@prisma/client";
|
||||
import AES from "crypto-js/aes";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
|
||||
|
@ -77,31 +76,14 @@ export default async function postLink(
|
|||
screenshotPath: "",
|
||||
pdfPath: "",
|
||||
},
|
||||
});
|
||||
|
||||
const AES_SECRET = process.env.AES_SECRET as string;
|
||||
|
||||
const screenshotHashedPath = AES.encrypt(
|
||||
`data/archives/${newLink.collectionId}/${newLink.id}.png`,
|
||||
AES_SECRET
|
||||
).toString();
|
||||
|
||||
const pdfHashedPath = AES.encrypt(
|
||||
`data/archives/${newLink.collectionId}/${newLink.id}.pdf`,
|
||||
AES_SECRET
|
||||
).toString();
|
||||
|
||||
const updatedLink = await prisma.link.update({
|
||||
where: { id: newLink.id },
|
||||
data: { screenshotPath: screenshotHashedPath, pdfPath: pdfHashedPath },
|
||||
include: { tags: true, collection: true },
|
||||
});
|
||||
|
||||
const collectionPath = `data/archives/${updatedLink.collection.id}`;
|
||||
const collectionPath = `data/archives/${newLink.collectionId}`;
|
||||
if (!existsSync(collectionPath))
|
||||
mkdirSync(collectionPath, { recursive: true });
|
||||
|
||||
archive(updatedLink.url, updatedLink.collectionId, updatedLink.id);
|
||||
archive(newLink.url, newLink.collectionId, newLink.id);
|
||||
|
||||
return { response: updatedLink, status: 200 };
|
||||
return { response: newLink, status: 200 };
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "pages/api/auth/[...nextauth]";
|
||||
import AES from "crypto-js/aes";
|
||||
import enc from "crypto-js/enc-utf8";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
|
@ -12,6 +10,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
|||
return res.status(401).json({ response: "Invalid parameters." });
|
||||
|
||||
const collectionId = req.query.params[0];
|
||||
const linkId = req.query.params[1];
|
||||
|
||||
const session = await getServerSession(req, res, authOptions);
|
||||
|
||||
|
@ -28,11 +27,10 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
|||
.status(401)
|
||||
.json({ response: "You don't have access to this collection." });
|
||||
|
||||
const AES_SECRET = process.env.AES_SECRET as string;
|
||||
const encryptedPath = decodeURIComponent(req.query.params[1]) as string;
|
||||
const decryptedPath = AES.decrypt(encryptedPath, AES_SECRET).toString(enc);
|
||||
const requestedPath = `data/archives/${collectionId}/${linkId}`;
|
||||
|
||||
const filePath = path.join(process.cwd(), requestedPath);
|
||||
|
||||
const filePath = path.join(process.cwd(), decryptedPath);
|
||||
const file = fs.existsSync(filePath)
|
||||
? fs.readFileSync(filePath)
|
||||
: "File not found, it's possible that the file you're looking for either doesn't exist or hasn't been created yet.";
|
||||
|
|
|
@ -69,8 +69,6 @@ CREATE TABLE "Link" (
|
|||
"url" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"collectionId" INTEGER NOT NULL,
|
||||
"screenshotPath" TEXT NOT NULL,
|
||||
"pdfPath" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Link_pkey" PRIMARY KEY ("id")
|
|
@ -93,8 +93,6 @@ model Link {
|
|||
collectionId Int
|
||||
tags Tag[]
|
||||
pins PinnedLinks[]
|
||||
screenshotPath String
|
||||
pdfPath String
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue