Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
add logs
Marc Seitz15f9748debea
diff --git a/lib/utils.ts b/lib/utils.tsindex c087ce28..b2bd8f67 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -27,3 +27,31 @@ export async function fetcher<JSON = any>(return res.json();}+++export const log = async (+ message: string,+) => {+ /* Log a message to the console */+ try {+ return await fetch(`${process.env.PPMK_SLACK_WEBHOOK_URL}`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ blocks: [+ {+ type: "section",+ text: {+ type: "mrkdwn",+ text: `${message}`,+ },+ },+ ],+ }),+ });+ } catch (e) {+ console.log(`Failed to log to Dub Slack. Error: ${e}`);+ }+};\ No newline at end of filediff --git a/pages/api/documents/[id]/links.ts b/pages/api/documents/[id]/links.tsindex 7cd2e3b1..f281a6f1 100644--- a/pages/api/documents/[id]/links.ts+++ b/pages/api/documents/[id]/links.ts@@ -2,6 +2,7 @@ import { NextApiRequest, NextApiResponse } from "next";import { getServerSession } from "next-auth/next";import prisma from "@/lib/prisma";import { authOptions } from "../../auth/[...nextauth]";+import { log } from "@/lib/utils";export default async function handle(req: NextApiRequest,@@ -36,6 +37,7 @@ export default async function handle(res.status(200).json(links);} catch (error) {+ log(`Failed to get links for document ${id}. Error: \n\n ${error}`)return res.status(500).json({message: "Internal Server Error",error: (error as Error).message,diff --git a/pages/api/documents/index.ts b/pages/api/documents/index.tsindex 91b56f9a..73bfa3a5 100644--- a/pages/api/documents/index.ts+++ b/pages/api/documents/index.ts@@ -3,7 +3,7 @@ import { getServerSession } from "next-auth/next";import prisma from "@/lib/prisma";import { authOptions } from "../auth/[...nextauth]";import { CustomUser } from "@/lib/types";-import { getExtension } from "@/lib/utils";+import { getExtension, log } from "@/lib/utils";export default async function handle(req: NextApiRequest,@@ -78,6 +78,7 @@ export default async function handle(res.status(201).json(document);} catch (error) {+ log(`Failed to create document. Error: \n\n ${error}`)res.status(500).json({message: "Internal Server Error",error: (error as Error).message,diff --git a/pages/api/views.ts b/pages/api/views.tsindex f8a0290c..f7573f6b 100644--- a/pages/api/views.ts+++ b/pages/api/views.ts@@ -1,5 +1,6 @@import { NextApiRequest, NextApiResponse } from "next";import prisma from "@/lib/prisma";+import { log } from "@/lib/utils";export default async function handle(req: NextApiRequest,@@ -24,6 +25,7 @@ export default async function handle(res.status(200).json({ message: "View recorded" });} catch (error) {+ log(`Failed to record view for ${linkId}. Error: \n\n ${error}`)res.status(500).json({ message: (error as Error).message });}}