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