mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00
api/pinterest: fetch.empty
for invalid links
This commit is contained in:
parent
ea3223e0b0
commit
cb78dd1db9
@ -3,6 +3,7 @@ import { resolveRedirectingURL } from "../url.js";
|
|||||||
|
|
||||||
const videoRegex = /"url":"(https:\/\/v1\.pinimg\.com\/videos\/.*?)"/g;
|
const videoRegex = /"url":"(https:\/\/v1\.pinimg\.com\/videos\/.*?)"/g;
|
||||||
const imageRegex = /src="(https:\/\/i\.pinimg\.com\/.*\.(jpg|gif))"/g;
|
const imageRegex = /src="(https:\/\/i\.pinimg\.com\/.*\.(jpg|gif))"/g;
|
||||||
|
const validPinRegex = /"__typename"\s*:\s*"PinNotFound"/;
|
||||||
|
|
||||||
export default async function(o) {
|
export default async function(o) {
|
||||||
let id = o.id;
|
let id = o.id;
|
||||||
@ -19,6 +20,10 @@ export default async function(o) {
|
|||||||
headers: { "user-agent": genericUserAgent }
|
headers: { "user-agent": genericUserAgent }
|
||||||
}).then(r => r.text()).catch(() => {});
|
}).then(r => r.text()).catch(() => {});
|
||||||
|
|
||||||
|
const invalidPin = html.match(validPinRegex);
|
||||||
|
|
||||||
|
if (invalidPin) return { error: "fetch.empty" }
|
||||||
|
|
||||||
if (!html) return { error: "fetch.fail" };
|
if (!html) return { error: "fetch.fail" };
|
||||||
|
|
||||||
const videoLink = [...html.matchAll(videoRegex)]
|
const videoLink = [...html.matchAll(videoRegex)]
|
||||||
|
@ -8,6 +8,15 @@
|
|||||||
"status": "redirect"
|
"status": "redirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "invalid link",
|
||||||
|
"url": "https://www.pinterest.com/pin/eeeeeee/",
|
||||||
|
"params": {},
|
||||||
|
"expected": {
|
||||||
|
"code": 400,
|
||||||
|
"status": "error"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "regular video (isAudioOnly)",
|
"name": "regular video (isAudioOnly)",
|
||||||
"url": "https://www.pinterest.com/pin/70437485604616/",
|
"url": "https://www.pinterest.com/pin/70437485604616/",
|
||||||
|
Loading…
Reference in New Issue
Block a user