Skip to content

Commit

Permalink
Update Safe browsing API
Browse files Browse the repository at this point in the history
  • Loading branch information
NayamAmarshe committed Feb 7, 2024
1 parent 57a97e8 commit 5424781
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pages/api/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default async function handler(req, res) {
}

try {
const url = new URL(link).hostname;
const response = await fetch(
"https://safebrowsing.googleapis.com/v4/threatMatches:find?key=" + apiKey,
{
Expand All @@ -75,17 +74,18 @@ export default async function handler(req, res) {
],
platformTypes: ["ANY_PLATFORM"],
threatEntryTypes: ["URL"],
threatEntries: [{ url: `${url}` }],
threatEntries: [{ url: `${link}` }],
},
}),
}
},
);

const data = await response.json();
console.log("馃殌 => data:", data);

if (data && data?.matches?.length > 0) {
// Handle error cases where the URL might not be checked by Safe Browsing
res.status(200).json({ message: "Malicious link entered!" });
res.status(401).json({ message: "Malicious link entered!" });
}
} catch (error) {
res.status(500).json({ error: "Failed to check the URL." });
Expand Down Expand Up @@ -113,7 +113,7 @@ export default async function handler(req, res) {
JSON.stringify({ link }),
password === ""
? process.env.SECRET_KEY
: process.env.SECRET_KEY + password
: process.env.SECRET_KEY + password,
).toString();

const docRef = setDoc(doc(collection(db, collectionName), slug), {
Expand Down

0 comments on commit 5424781

Please sign in to comment.