From 190a0131d4cbec2e867c2f29f24a889d9080356e Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Thu, 23 Nov 2023 14:44:25 +0000 Subject: [PATCH 1/3] api: url-encode UTF-8 characters in url this encode-decode construct is ugly, but necessary to retain backwards compatibility for weirdos that encode the URL when passing it in via json ( like the frontend, for example. :/ ) --- src/modules/api.js | 2 +- src/modules/sub/utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/api.js b/src/modules/api.js index 92fa5374..62e9a7c6 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -10,7 +10,7 @@ import hostOverrides from "./processing/hostOverrides.js"; export async function getJSON(originalURL, lang, obj) { try { - let patternMatch, url = decodeURIComponent(originalURL), + let patternMatch, url = encodeURI(decodeURIComponent(originalURL)), hostname = new URL(url).hostname.split('.'), host = hostname[hostname.length - 2]; diff --git a/src/modules/sub/utils.js b/src/modules/sub/utils.js index 41ee07db..cfb56aa8 100644 --- a/src/modules/sub/utils.js +++ b/src/modules/sub/utils.js @@ -9,7 +9,7 @@ const apiVar = { }, booleanOnly: ["isAudioOnly", "isNoTTWatermark", "isTTFullAudio", "isAudioMuted", "dubLang", "vimeoDash", "disableMetadata"] } -const forbiddenChars = ['}', '{', '(', ')', '\\', '%', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@", '==']; +const forbiddenChars = ['}', '{', '(', ')', '\\', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@", '==']; const forbiddenCharsString = ['}', '{', '%', '>', '<', '^', ';', '`', '$', '"', "@", '=']; export function apiJSON(type, obj) { From 7468b803fbb8f2bf6ee341aaa9a1067f2f731854 Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Thu, 23 Nov 2023 14:45:52 +0000 Subject: [PATCH 2/3] reddit: don't include title in API request path --- src/modules/processing/services/reddit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/processing/services/reddit.js b/src/modules/processing/services/reddit.js index c985831a..ea1f835a 100644 --- a/src/modules/processing/services/reddit.js +++ b/src/modules/processing/services/reddit.js @@ -48,7 +48,7 @@ async function getAccessToken() { } export default async function(obj) { - const url = new URL(`https://www.reddit.com/r/${obj.sub}/comments/${obj.id}/${obj.title}.json`); + const url = new URL(`https://www.reddit.com/r/${obj.sub}/comments/${obj.id}.json`); const accessToken = await getAccessToken(); if (accessToken) url.hostname = 'oauth.reddit.com'; From 3ca65e0daf6177c449b5b8d7201e43ba36dc21f3 Mon Sep 17 00:00:00 2001 From: wukko Date: Thu, 23 Nov 2023 21:35:02 +0600 Subject: [PATCH 3/3] reddit: remove the rest of references to title --- src/modules/processing/match.js | 3 +-- src/modules/processing/servicesPatternTesters.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/processing/match.js b/src/modules/processing/match.js index 9857cdb1..feb91e34 100644 --- a/src/modules/processing/match.js +++ b/src/modules/processing/match.js @@ -67,8 +67,7 @@ export default async function(host, patternMatch, url, lang, obj) { case "reddit": r = await reddit({ sub: patternMatch["sub"], - id: patternMatch["id"], - title: patternMatch["title"] + id: patternMatch["id"] }); break; case "douyin": diff --git a/src/modules/processing/servicesPatternTesters.js b/src/modules/processing/servicesPatternTesters.js index b4c75a8c..9720a523 100644 --- a/src/modules/processing/servicesPatternTesters.js +++ b/src/modules/processing/servicesPatternTesters.js @@ -8,8 +8,7 @@ export const testers = { "youtube": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 11), - "reddit": (patternMatch) => (patternMatch["sub"] && patternMatch["id"] && patternMatch["title"] - && patternMatch["sub"].length <= 22 && patternMatch["id"].length <= 10 && patternMatch["title"].length <= 96), + "reddit": (patternMatch) => (patternMatch.sub?.length <= 22 && patternMatch.id?.length <= 10), "tiktok": (patternMatch) => ((patternMatch["user"] && patternMatch["postId"] && patternMatch["postId"].length <= 21) || (patternMatch["id"] && patternMatch["id"].length <= 13)),