|
1 | 1 | import { NextApiRequest, NextApiResponse } from "next"; |
2 | 2 |
|
3 | 3 | import { DocumentPage } from "@prisma/client"; |
| 4 | +import { get } from "@vercel/edge-config"; |
| 5 | +import { waitUntil } from "@vercel/functions"; |
4 | 6 | import * as mupdf from "mupdf"; |
5 | 7 |
|
6 | 8 | import { putFileServer } from "@/lib/files/put-file-server"; |
@@ -142,6 +144,43 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { |
142 | 144 | return { href: link.getURI(), coords: link.getBounds().join(",") }; |
143 | 145 | }); |
144 | 146 |
|
| 147 | + // Check embedded links for blocked keywords |
| 148 | + if (embeddedLinks.length > 0) { |
| 149 | + try { |
| 150 | + const keywords = await get("keywords"); |
| 151 | + if (Array.isArray(keywords) && keywords.length > 0) { |
| 152 | + for (const link of embeddedLinks) { |
| 153 | + if (link.href) { |
| 154 | + const matchedKeyword = keywords.find( |
| 155 | + (keyword) => |
| 156 | + typeof keyword === "string" && link.href.includes(keyword), |
| 157 | + ); |
| 158 | + |
| 159 | + if (matchedKeyword) { |
| 160 | + waitUntil( |
| 161 | + log({ |
| 162 | + message: `Document processing blocked: ${matchedKeyword} \n\n \`Metadata: {teamId: ${teamId}, documentVersionId: ${documentVersionId}, pageNumber: ${pageNumber}}\``, |
| 163 | + type: "error", |
| 164 | + mention: true, |
| 165 | + }), |
| 166 | + ); |
| 167 | + res.status(400).json({ |
| 168 | + error: "Document processing blocked", |
| 169 | + matchedUrl: link.href, |
| 170 | + matchedKeyword: matchedKeyword, |
| 171 | + pageNumber: pageNumber, |
| 172 | + }); |
| 173 | + return; |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + } catch (error) { |
| 179 | + // Log error but continue processing if check fails |
| 180 | + console.log("Failed to check keywords:", error); |
| 181 | + } |
| 182 | + } |
| 183 | + |
145 | 184 | // Will be updated if we use a reduced scale factor |
146 | 185 | let actualScaleFactor = scaleFactor; |
147 | 186 |
|
|
0 commit comments