api/tiktok: normalize short link URL & catch empty patternMatch

This commit is contained in:
wukko 2025-03-25 18:31:12 +06:00
parent 2f38260e23
commit ab13f78326
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2

View File

@ -1,6 +1,6 @@
import Cookie from "../cookie/cookie.js"; import Cookie from "../cookie/cookie.js";
import { extract } from "../url.js"; import { extract, normalizeURL } from "../url.js";
import { genericUserAgent } from "../../config.js"; import { genericUserAgent } from "../../config.js";
import { updateCookie } from "../cookie/manager.js"; import { updateCookie } from "../cookie/manager.js";
import { createStream } from "../../stream/manage.js"; import { createStream } from "../../stream/manage.js";
@ -23,8 +23,8 @@ export default async function(obj) {
if (html.startsWith('<a href="https://')) { if (html.startsWith('<a href="https://')) {
const extractedURL = html.split('<a href="')[1].split('?')[0]; const extractedURL = html.split('<a href="')[1].split('?')[0];
const { patternMatch } = extract(extractedURL); const { patternMatch } = extract(normalizeURL(extractedURL));
postId = patternMatch.postId; postId = patternMatch?.postId;
} }
} }
if (!postId) return { error: "fetch.short_link" }; if (!postId) return { error: "fetch.short_link" };