Skip to content

best way to save what you love

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

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