tab-seperated modals + eslint fix + much more bug fixed and improvements

This commit is contained in:
Daniel
2023-06-10 02:01:14 +03:30
parent dcdef77387
commit 2df4aad077
64 changed files with 713 additions and 373 deletions
+6 -2
View File
@@ -4,7 +4,11 @@ import puppeteer from "puppeteer-extra";
import AdblockerPlugin from "puppeteer-extra-plugin-adblocker";
import StealthPlugin from "puppeteer-extra-plugin-stealth";
export default async (url: string, collectionId: number, linkId: number) => {
export default async function archive(
url: string,
collectionId: number,
linkId: number
) {
const archivePath = `data/archives/${collectionId}/${linkId}`;
const browser = await puppeteer.launch();
@@ -38,7 +42,7 @@ export default async (url: string, collectionId: number, linkId: number) => {
console.log(err);
await browser.close();
}
};
}
const autoScroll = async (page: Page) => {
await page.evaluate(async () => {
@@ -2,7 +2,10 @@ import { prisma } from "@/lib/api/db";
import getPermission from "@/lib/api/getPermission";
import fs from "fs";
export default async function (collection: { id: number }, userId: number) {
export default async function deleteCollection(
collection: { id: number },
userId: number
) {
if (!collection.id)
return { response: "Please choose a valid collection.", status: 401 };
@@ -1,6 +1,6 @@
import { prisma } from "@/lib/api/db";
export default async function (userId: number) {
export default async function getCollection(userId: number) {
const collections = await prisma.collection.findMany({
where: {
OR: [
@@ -2,7 +2,7 @@ import { prisma } from "@/lib/api/db";
import { CollectionIncludingMembers } from "@/types/global";
import { existsSync, mkdirSync } from "fs";
export default async function (
export default async function postCollection(
collection: CollectionIncludingMembers,
userId: number
) {
@@ -2,7 +2,7 @@ import { prisma } from "@/lib/api/db";
import { CollectionIncludingMembers } from "@/types/global";
import getPermission from "@/lib/api/getPermission";
export default async function (
export default async function updateCollection(
collection: CollectionIncludingMembers,
userId: number
) {
+1 -1
View File
@@ -4,7 +4,7 @@ import fs from "fs";
import { Link, UsersAndCollections } from "@prisma/client";
import getPermission from "@/lib/api/getPermission";
export default async function (
export default async function deleteLink(
link: LinkIncludingCollectionAndTags,
userId: number
) {
+1 -1
View File
@@ -1,5 +1,5 @@
import { prisma } from "@/lib/api/db";
export default async function (userId: number) {
export default async function getLink(userId: number) {
const links = await prisma.link.findMany({
where: {
collection: {
+1 -1
View File
@@ -7,7 +7,7 @@ import AES from "crypto-js/aes";
import getPermission from "@/lib/api/getPermission";
import { existsSync, mkdirSync } from "fs";
export default async function (
export default async function postLink(
link: LinkIncludingCollectionAndTags,
userId: number
) {
+1 -1
View File
@@ -3,7 +3,7 @@ import { LinkIncludingCollectionAndTags } from "@/types/global";
import { UsersAndCollections } from "@prisma/client";
import getPermission from "@/lib/api/getPermission";
export default async function (
export default async function updateLink(
link: LinkIncludingCollectionAndTags,
userId: number
) {
+1 -1
View File
@@ -1,6 +1,6 @@
import { prisma } from "@/lib/api/db";
export default async function (collectionId: number) {
export default async function getCollection(collectionId: number) {
let data;
const collection = await prisma.collection.findFirst({
+1 -1
View File
@@ -1,6 +1,6 @@
import { prisma } from "@/lib/api/db";
export default async function (userId: number) {
export default async function getTags(userId: number) {
// remove empty tags
await prisma.tag.deleteMany({
where: {
+1 -1
View File
@@ -1,6 +1,6 @@
import { prisma } from "@/lib/api/db";
export default async function (
export default async function getUser(
lookupEmail: string,
isSelf: boolean,
userEmail: string
+40 -20
View File
@@ -4,7 +4,40 @@ import fs from "fs";
import path from "path";
import bcrypt from "bcrypt";
export default async function (user: AccountSettings, userId: number) {
export default async function updateUser(
user: AccountSettings,
userId: number
) {
// Password Settings
if (user.newPassword && user.oldPassword) {
const targetUser = await prisma.user.findUnique({
where: {
id: user.id,
},
});
if (
targetUser &&
bcrypt.compareSync(user.oldPassword, targetUser.password)
) {
const saltRounds = 10;
const newHashedPassword = bcrypt.hashSync(user.newPassword, saltRounds);
await prisma.user.update({
where: {
id: userId,
},
data: {
password: newHashedPassword,
},
});
} else {
return { response: "Old password is incorrect.", status: 400 };
}
}
// Avatar Settings
const profilePic = user.profilePic;
if (profilePic.startsWith("data:image/jpeg;base64")) {
@@ -25,6 +58,10 @@ export default async function (user: AccountSettings, userId: number) {
}
} else {
console.log("A file larger than 1.5MB was uploaded.");
return {
response: "A file larger than 1.5MB was uploaded.",
status: 400,
};
}
} else if (profilePic == "") {
fs.unlink(`data/uploads/avatar/${userId}.jpg`, (err) => {
@@ -32,6 +69,8 @@ export default async function (user: AccountSettings, userId: number) {
});
}
// Other settings
const updatedUser = await prisma.user.update({
where: {
id: userId,
@@ -44,25 +83,6 @@ export default async function (user: AccountSettings, userId: number) {
},
});
if (user.newPassword && user.oldPassword) {
const saltRounds = 10;
if (bcrypt.compareSync(user.oldPassword, updatedUser.password)) {
const newHashedPassword = bcrypt.hashSync(user.newPassword, saltRounds);
await prisma.user.update({
where: {
id: userId,
},
data: {
password: newHashedPassword,
},
});
} else {
return { response: "Passwords do not match.", status: 403 };
}
}
const { password, ...userInfo } = updatedUser;
const response: Omit<AccountSettings, "password"> = {
+5 -2
View File
@@ -1,6 +1,9 @@
import { prisma } from "@/lib/api/db";
export default async (userId: number, collectionId: number) => {
export default async function getPermission(
userId: number,
collectionId: number
) {
const check = await prisma.collection.findFirst({
where: {
AND: {
@@ -12,4 +15,4 @@ export default async (userId: number, collectionId: number) => {
});
return check;
};
}
+2 -2
View File
@@ -1,4 +1,4 @@
export default async (url: string) => {
export default async function getTitle(url: string) {
const response = await fetch(url);
const text = await response.text();
@@ -6,4 +6,4 @@ export default async (url: string) => {
let match = text.match(/<title.*>([^<]*)<\/title>/);
if (match) return match[1];
else return "";
};
}