bugs fixed

This commit is contained in:
daniel31x13 2023-10-26 18:49:46 -04:00
parent 966136dab6
commit ea86737835
7 changed files with 88 additions and 38 deletions

View File

@ -1,12 +1,16 @@
import React, { SetStateAction } from "react"; import React, { SetStateAction } from "react";
import ClickAwayHandler from "./ClickAwayHandler"; import ClickAwayHandler from "./ClickAwayHandler";
import Checkbox from "./Checkbox"; import Checkbox from "./Checkbox";
import { LinkSearchFilter } from "@/types/global";
type Props = { type Props = {
setFilterDropdown: (value: SetStateAction<boolean>) => void; setFilterDropdown: (value: SetStateAction<boolean>) => void;
setSearchFilter: Function; setSearchFilter: Function;
searchFilter: LinkSearchFilter; searchFilter: {
name: boolean;
url: boolean;
description: boolean;
tags: boolean;
};
}; };
export default function FilterSearchDropdown({ export default function FilterSearchDropdown({

View File

@ -46,6 +46,8 @@ export default function AddOrEditLink({
url: "", url: "",
description: "", description: "",
tags: [], tags: [],
screenshotPath: "",
pdfPath: "",
collection: { collection: {
name: "", name: "",
ownerId: data?.user.id as number, ownerId: data?.user.id as number,

View File

@ -18,7 +18,7 @@ export default async function exportData(userId: number) {
if (!user) return { response: "User not found.", status: 404 }; if (!user) return { response: "User not found.", status: 404 };
const { password, id, image, ...userData } = user; const { password, id, ...userData } = user;
function redactIds(obj: any) { function redactIds(obj: any) {
if (Array.isArray(obj)) { if (Array.isArray(obj)) {

View File

@ -1,83 +1,124 @@
const { S3 } = require("@aws-sdk/client-s3");
const { PrismaClient } = require("@prisma/client"); const { PrismaClient } = require("@prisma/client");
const axios = require("axios"); const axios = require("axios");
const { existsSync } = require("fs"); const { existsSync } = require("fs");
const util = require("util");
const prisma = new PrismaClient(); const prisma = new PrismaClient();
const STORAGE_FOLDER = process.env.STORAGE_FOLDER || "data"; 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) { async function checkFileExistence(path) {
try { if (s3Client) {
if (existsSync(path)) { const bucketParams = {
return true; Bucket: process.env.BUCKET_NAME,
} else return false; Key: path,
} catch (err) { };
console.log(err);
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 // Avatars
async function migrateAvatars() { async function migrateToV2() {
const users = await prisma.user.findMany(); const users = await prisma.user.findMany();
for (let user of users) { 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); const res = await checkFileExistence(path);
if (res) { if (res) {
// await prisma.user.update({ await prisma.user.update({
// where: { id: user.id }, where: { id: user.id },
// data: { image: "avatar/" + user.id }, data: { imagePath: path },
// }); });
console.log(`Updated avatar for user ${user.id}`); console.log(`Updated avatar for avatar ${user.id}`);
} else { } 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(); const links = await prisma.link.findMany();
// Screenshots // PDFs
for (let link of links) { for (let link of links) {
const path = const path = `archives/${link.collectionId}/${link.id}.pdf`;
STORAGE_FOLDER + `/archives/${link.collectionId}/${link.id}.pdf`;
const res = await checkFileExistence(path); const res = await checkFileExistence(path);
if (res) { if (res) {
// await prisma.user.update({ await prisma.link.update({
// where: { id: user.id }, where: { id: link.id },
// data: { image: "avatar/" + user.id }, data: { pdfPath: path },
// }); });
console.log(`Updated capture for link ${link.id}`); console.log(`Updated capture for pdf ${link.id}`);
} else { } 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) { for (let link of links) {
const path = const path = `archives/${link.collectionId}/${link.id}.png`;
STORAGE_FOLDER + `/archives/${link.collectionId}/${link.id}.png`;
const res = await checkFileExistence(path); const res = await checkFileExistence(path);
if (res) { if (res) {
// await prisma.user.update({ await prisma.link.update({
// where: { id: user.id }, where: { id: link.id },
// data: { image: "avatar/" + user.id }, data: { screenshotPath: path },
// }); });
console.log(`Updated capture for link ${link.id}`); console.log(`Updated capture for screenshot ${link.id}`);
} else { } else {
console.log(`No capture found for link ${link.id}`); console.log(`No capture found for screenshot ${link.id}`);
} }
} }
await prisma.$disconnect(); await prisma.$disconnect();
} }
migrateAvatars().catch((e) => { migrateToV2().catch((e) => {
console.error(e); console.error(e);
process.exit(1); process.exit(1);
}); });

View File

@ -14,3 +14,5 @@
// } // }
// res.end(); // res.end();
// }; // };
export {};

View File

@ -154,7 +154,7 @@ export default function Collections() {
</p> </p>
<p className="capitalize text-black dark:text-white"> <p className="capitalize text-black dark:text-white">
Shared collections you're a member of Shared collections you&apos;re a member of
</p> </p>
</div> </div>
</div> </div>

View File

@ -119,7 +119,8 @@ export default function Password() {
</label> </label>
<div> <div>
<p className="text-sm mb-2 text-black dark:text-white"> <p className="text-sm mb-2 text-black dark:text-white">
More information (the more details, the more helpful it'd be) More information (the more details, the more helpful it&apos;d
be)
</p> </p>
<textarea <textarea