diff --git a/components/FilterSearchDropdown.tsx b/components/FilterSearchDropdown.tsx index 2c835ab..181febb 100644 --- a/components/FilterSearchDropdown.tsx +++ b/components/FilterSearchDropdown.tsx @@ -1,12 +1,16 @@ import React, { SetStateAction } from "react"; import ClickAwayHandler from "./ClickAwayHandler"; import Checkbox from "./Checkbox"; -import { LinkSearchFilter } from "@/types/global"; type Props = { setFilterDropdown: (value: SetStateAction) => void; setSearchFilter: Function; - searchFilter: LinkSearchFilter; + searchFilter: { + name: boolean; + url: boolean; + description: boolean; + tags: boolean; + }; }; export default function FilterSearchDropdown({ diff --git a/components/Modal/Link/AddOrEditLink.tsx b/components/Modal/Link/AddOrEditLink.tsx index dcdf422..201b3d0 100644 --- a/components/Modal/Link/AddOrEditLink.tsx +++ b/components/Modal/Link/AddOrEditLink.tsx @@ -46,6 +46,8 @@ export default function AddOrEditLink({ url: "", description: "", tags: [], + screenshotPath: "", + pdfPath: "", collection: { name: "", ownerId: data?.user.id as number, diff --git a/lib/api/controllers/migration/exportData.ts b/lib/api/controllers/migration/exportData.ts index 49a25b4..2776d85 100644 --- a/lib/api/controllers/migration/exportData.ts +++ b/lib/api/controllers/migration/exportData.ts @@ -18,7 +18,7 @@ export default async function exportData(userId: number) { if (!user) return { response: "User not found.", status: 404 }; - const { password, id, image, ...userData } = user; + const { password, id, ...userData } = user; function redactIds(obj: any) { if (Array.isArray(obj)) { diff --git a/lib/api/migration/migrateToV2.js b/lib/api/migration/migrateToV2.js index aeb07fb..29c7e17 100644 --- a/lib/api/migration/migrateToV2.js +++ b/lib/api/migration/migrateToV2.js @@ -1,83 +1,124 @@ +const { S3 } = require("@aws-sdk/client-s3"); const { PrismaClient } = require("@prisma/client"); const axios = require("axios"); const { existsSync } = require("fs"); +const util = require("util"); const prisma = new PrismaClient(); const STORAGE_FOLDER = process.env.STORAGE_FOLDER || "data"; +const s3Client = + process.env.SPACES_ENDPOINT && + process.env.SPACES_REGION && + process.env.SPACES_KEY && + process.env.SPACES_SECRET + ? new S3({ + forcePathStyle: false, + endpoint: process.env.SPACES_ENDPOINT, + region: process.env.SPACES_REGION, + credentials: { + accessKeyId: process.env.SPACES_KEY, + secretAccessKey: process.env.SPACES_SECRET, + }, + }) + : undefined; + async function checkFileExistence(path) { - try { - if (existsSync(path)) { - return true; - } else return false; - } catch (err) { - console.log(err); + if (s3Client) { + const bucketParams = { + Bucket: process.env.BUCKET_NAME, + Key: path, + }; + + console.log(path); + try { + const headObjectAsync = util.promisify( + s3Client.headObject.bind(s3Client) + ); + + try { + await headObjectAsync(bucketParams); + return true; + } catch (err) { + return false; + } + } catch (err) { + console.log("Error:", err); + + return false; + } + } else { + try { + if (existsSync(STORAGE_FOLDER + "/" + path)) { + return true; + } else return false; + } catch (err) { + console.log(err); + } } } // Avatars -async function migrateAvatars() { +async function migrateToV2() { const users = await prisma.user.findMany(); for (let user of users) { - const path = STORAGE_FOLDER + `/uploads/avatar/${user.id}.jpg`; + const path = `uploads/avatar/${user.id}.jpg`; const res = await checkFileExistence(path); if (res) { - // await prisma.user.update({ - // where: { id: user.id }, - // data: { image: "avatar/" + user.id }, - // }); - console.log(`Updated avatar for user ${user.id}`); + await prisma.user.update({ + where: { id: user.id }, + data: { imagePath: path }, + }); + console.log(`Updated avatar for avatar ${user.id}`); } else { - console.log(`No avatar found for user ${user.id}`); + console.log(`No avatar found for avatar ${user.id}`); } } const links = await prisma.link.findMany(); - // Screenshots + // PDFs for (let link of links) { - const path = - STORAGE_FOLDER + `/archives/${link.collectionId}/${link.id}.pdf`; + const path = `archives/${link.collectionId}/${link.id}.pdf`; const res = await checkFileExistence(path); if (res) { - // await prisma.user.update({ - // where: { id: user.id }, - // data: { image: "avatar/" + user.id }, - // }); - console.log(`Updated capture for link ${link.id}`); + await prisma.link.update({ + where: { id: link.id }, + data: { pdfPath: path }, + }); + console.log(`Updated capture for pdf ${link.id}`); } else { - console.log(`No capture found for link ${link.id}`); + console.log(`No capture found for pdf ${link.id}`); } } - // PDFs + // Screenshots for (let link of links) { - const path = - STORAGE_FOLDER + `/archives/${link.collectionId}/${link.id}.png`; + const path = `archives/${link.collectionId}/${link.id}.png`; const res = await checkFileExistence(path); if (res) { - // await prisma.user.update({ - // where: { id: user.id }, - // data: { image: "avatar/" + user.id }, - // }); - console.log(`Updated capture for link ${link.id}`); + await prisma.link.update({ + where: { id: link.id }, + data: { screenshotPath: path }, + }); + console.log(`Updated capture for screenshot ${link.id}`); } else { - console.log(`No capture found for link ${link.id}`); + console.log(`No capture found for screenshot ${link.id}`); } } await prisma.$disconnect(); } -migrateAvatars().catch((e) => { +migrateToV2().catch((e) => { console.error(e); process.exit(1); }); diff --git a/pages/api/v1/getToken.ts b/pages/api/v1/getToken.ts index c767075..e51c4bb 100644 --- a/pages/api/v1/getToken.ts +++ b/pages/api/v1/getToken.ts @@ -14,3 +14,5 @@ // } // res.end(); // }; + +export {}; diff --git a/pages/collections/index.tsx b/pages/collections/index.tsx index 0df0588..1f81285 100644 --- a/pages/collections/index.tsx +++ b/pages/collections/index.tsx @@ -154,7 +154,7 @@ export default function Collections() {

- Shared collections you're a member of + Shared collections you're a member of

diff --git a/pages/settings/delete.tsx b/pages/settings/delete.tsx index e072ab1..6a293af 100644 --- a/pages/settings/delete.tsx +++ b/pages/settings/delete.tsx @@ -119,7 +119,8 @@ export default function Password() {

- More information (the more details, the more helpful it'd be) + More information (the more details, the more helpful it'd + be)