ui improvements
This commit is contained in:
+12
-2
@@ -1,4 +1,5 @@
|
||||
import { chromium, devices } from "playwright";
|
||||
import { prisma } from "@/lib/api/db";
|
||||
|
||||
export default async (url: string, collectionId: number, linkId: number) => {
|
||||
const archivePath = `data/archives/${collectionId}/${linkId}`;
|
||||
@@ -12,9 +13,18 @@ export default async (url: string, collectionId: number, linkId: number) => {
|
||||
|
||||
await page.goto(url);
|
||||
|
||||
await page.pdf({ path: archivePath + ".pdf" });
|
||||
const linkExists = await prisma.link.findFirst({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
});
|
||||
|
||||
await page.screenshot({ fullPage: true, path: archivePath + ".png" });
|
||||
if (linkExists) {
|
||||
await Promise.all([
|
||||
page.pdf({ path: archivePath + ".pdf" }),
|
||||
page.screenshot({ fullPage: true, path: archivePath + ".png" }),
|
||||
]);
|
||||
}
|
||||
|
||||
await context.close();
|
||||
await browser.close();
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { Session } from "next-auth";
|
||||
import { ExtendedLink, NewLink } from "@/types/global";
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
import getTitle from "../../getTitle";
|
||||
import archive from "../../archive";
|
||||
import { ExtendedLink } from "@/types/global";
|
||||
import fs from "fs";
|
||||
import { Link, UsersAndCollections } from "@prisma/client";
|
||||
import AES from "crypto-js/aes";
|
||||
import hasAccessToCollection from "@/lib/api/hasAccessToCollection";
|
||||
|
||||
export default async function (
|
||||
@@ -42,6 +39,14 @@ export default async function (
|
||||
},
|
||||
});
|
||||
|
||||
fs.unlink(`data/archives/${link.collectionId}/${link.id}.pdf`, (err) => {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
|
||||
fs.unlink(`data/archives/${link.collectionId}/${link.id}.png`, (err) => {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
response: deleteLink,
|
||||
});
|
||||
|
||||
@@ -118,7 +118,7 @@ export default async function (
|
||||
|
||||
const AES_SECRET = process.env.AES_SECRET as string;
|
||||
|
||||
const screenShotHashedPath = AES.encrypt(
|
||||
const screenshotHashedPath = AES.encrypt(
|
||||
`data/archives/${newLink.collectionId}/${newLink.id}.png`,
|
||||
AES_SECRET
|
||||
).toString();
|
||||
@@ -130,7 +130,7 @@ export default async function (
|
||||
|
||||
const updatedLink: ExtendedLink = await prisma.link.update({
|
||||
where: { id: newLink.id },
|
||||
data: { screenshotPath: screenShotHashedPath, pdfPath: pdfHashedPath },
|
||||
data: { screenshotPath: screenshotHashedPath, pdfPath: pdfHashedPath },
|
||||
include: { tags: true, collection: true },
|
||||
});
|
||||
|
||||
|
||||
@@ -7,6 +7,15 @@ export default async function (
|
||||
res: NextApiResponse,
|
||||
session: Session
|
||||
) {
|
||||
// tag cleanup
|
||||
await prisma.tag.deleteMany({
|
||||
where: {
|
||||
links: {
|
||||
none: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const tags = await prisma.tag.findMany({
|
||||
where: {
|
||||
collections: {
|
||||
|
||||
Reference in New Issue
Block a user