diff --git a/api/src/processing/services/pinterest.js b/api/src/processing/services/pinterest.js index 15566cc4..c21400e1 100644 --- a/api/src/processing/services/pinterest.js +++ b/api/src/processing/services/pinterest.js @@ -3,6 +3,7 @@ import { resolveRedirectingURL } from "../url.js"; const videoRegex = /"url":"(https:\/\/v1\.pinimg\.com\/videos\/.*?)"/g; const imageRegex = /src="(https:\/\/i\.pinimg\.com\/.*\.(jpg|gif))"/g; +const notFoundRegex = /"__typename"\s*:\s*"PinNotFound"/; export default async function(o) { let id = o.id; @@ -19,6 +20,10 @@ export default async function(o) { headers: { "user-agent": genericUserAgent } }).then(r => r.text()).catch(() => {}); + const invalidPin = html.match(notFoundRegex); + + if (invalidPin) return { error: "fetch.empty" }; + if (!html) return { error: "fetch.fail" }; const videoLink = [...html.matchAll(videoRegex)] diff --git a/api/src/util/tests/pinterest.json b/api/src/util/tests/pinterest.json index 4760dd36..adf502c0 100644 --- a/api/src/util/tests/pinterest.json +++ b/api/src/util/tests/pinterest.json @@ -8,6 +8,16 @@ "status": "redirect" } }, + { + "name": "invalid link", + "url": "https://www.pinterest.com/pin/eeeeeee/", + "params": {}, + "expected": { + "code": 400, + "status": "error", + "errorCode": "error.api.fetch.empty" + } + }, { "name": "regular video (isAudioOnly)", "url": "https://www.pinterest.com/pin/70437485604616/",