⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
small improvement
Daniel5b0e0b42082e
diff --git a/components/LinkCard.tsx b/components/LinkCard.tsxindex 0d49d7b4..9140216c 100644--- a/components/LinkCard.tsx+++ b/components/LinkCard.tsx@@ -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"diff --git a/components/Modal/User/ProfileSettings.tsx b/components/Modal/User/ProfileSettings.tsxindex b229375c..030a4a61 100644--- a/components/Modal/User/ProfileSettings.tsx+++ b/components/Modal/User/ProfileSettings.tsx@@ -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"><ProfilePhotosrc={user.profilePic}- className="h-auto aspect-square w-28 border-[0px]"+ className="h-auto aspect-square w-28 border-[1px]"status={handleProfileStatus}/>{profileStatus && (diff --git a/lib/api/controllers/links/postLink.ts b/lib/api/controllers/links/postLink.tsindex 85cbe46e..6d079328 100644--- a/lib/api/controllers/links/postLink.ts+++ b/lib/api/controllers/links/postLink.ts@@ -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 };}diff --git a/pages/api/archives/[...params].ts b/pages/api/archives/[...params].tsindex 3a2c2a08..cae74251 100644--- a/pages/api/archives/[...params].ts+++ b/pages/api/archives/[...params].ts@@ -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.";diff --git a/prisma/migrations/20230612181740_init/migration.sql b/prisma/migrations/20230613142801_init/migration.sqlsimilarity index 98%rename from prisma/migrations/20230612181740_init/migration.sqlrename to prisma/migrations/20230613142801_init/migration.sqlindex 602ce218..8f5a1afd 100644--- a/prisma/migrations/20230612181740_init/migration.sql+++ b/prisma/migrations/20230613142801_init/migration.sql@@ -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")diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex b3bf3b66..37503c78 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -93,8 +93,6 @@ model Link {collectionId Inttags Tag[]pins PinnedLinks[]- screenshotPath String- pdfPath StringcreatedAt DateTime @default(now())}