bugs fixed
This commit is contained in:
parent
966136dab6
commit
ea86737835
|
@ -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<boolean>) => void;
|
||||
setSearchFilter: Function;
|
||||
searchFilter: LinkSearchFilter;
|
||||
searchFilter: {
|
||||
name: boolean;
|
||||
url: boolean;
|
||||
description: boolean;
|
||||
tags: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
export default function FilterSearchDropdown({
|
||||
|
|
|
@ -46,6 +46,8 @@ export default function AddOrEditLink({
|
|||
url: "",
|
||||
description: "",
|
||||
tags: [],
|
||||
screenshotPath: "",
|
||||
pdfPath: "",
|
||||
collection: {
|
||||
name: "",
|
||||
ownerId: data?.user.id as number,
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -14,3 +14,5 @@
|
|||
// }
|
||||
// res.end();
|
||||
// };
|
||||
|
||||
export {};
|
||||
|
|
|
@ -154,7 +154,7 @@ export default function Collections() {
|
|||
</p>
|
||||
|
||||
<p className="capitalize text-black dark:text-white">
|
||||
Shared collections you're a member of
|
||||
Shared collections you're a member of
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -119,7 +119,8 @@ export default function Password() {
|
|||
</label>
|
||||
<div>
|
||||
<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'd
|
||||
be)
|
||||
</p>
|
||||
|
||||
<textarea
|
||||
|
|
Ŝarĝante…
Reference in New Issue