mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-27 17:08:28 +00:00
api/pinterest: return fetch.empty if a link is invalid (#1299)
This commit is contained in:
parent
170cf293bf
commit
495729e174
@ -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)]
|
||||
|
@ -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/",
|
||||
|
Loading…
Reference in New Issue
Block a user