mirror of
https://github.com/imputnet/cobalt.git
synced 2025-01-08 16:07:22 +00:00
fix handling of URLs containing utf-8 characters
Merge pull request #253 from dumbmoron/fix-utf8-urls
This commit is contained in:
commit
88b8a69f9c
|
@ -10,7 +10,7 @@ import hostOverrides from "./processing/hostOverrides.js";
|
||||||
|
|
||||||
export async function getJSON(originalURL, lang, obj) {
|
export async function getJSON(originalURL, lang, obj) {
|
||||||
try {
|
try {
|
||||||
let patternMatch, url = decodeURIComponent(originalURL),
|
let patternMatch, url = encodeURI(decodeURIComponent(originalURL)),
|
||||||
hostname = new URL(url).hostname.split('.'),
|
hostname = new URL(url).hostname.split('.'),
|
||||||
host = hostname[hostname.length - 2];
|
host = hostname[hostname.length - 2];
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,7 @@ export default async function(host, patternMatch, url, lang, obj) {
|
||||||
case "reddit":
|
case "reddit":
|
||||||
r = await reddit({
|
r = await reddit({
|
||||||
sub: patternMatch["sub"],
|
sub: patternMatch["sub"],
|
||||||
id: patternMatch["id"],
|
id: patternMatch["id"]
|
||||||
title: patternMatch["title"]
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "douyin":
|
case "douyin":
|
||||||
|
|
|
@ -48,7 +48,7 @@ async function getAccessToken() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function(obj) {
|
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();
|
const accessToken = await getAccessToken();
|
||||||
if (accessToken) url.hostname = 'oauth.reddit.com';
|
if (accessToken) url.hostname = 'oauth.reddit.com';
|
||||||
|
|
|
@ -8,8 +8,7 @@ export const testers = {
|
||||||
|
|
||||||
"youtube": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 11),
|
"youtube": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 11),
|
||||||
|
|
||||||
"reddit": (patternMatch) => (patternMatch["sub"] && patternMatch["id"] && patternMatch["title"]
|
"reddit": (patternMatch) => (patternMatch.sub?.length <= 22 && patternMatch.id?.length <= 10),
|
||||||
&& patternMatch["sub"].length <= 22 && patternMatch["id"].length <= 10 && patternMatch["title"].length <= 96),
|
|
||||||
|
|
||||||
"tiktok": (patternMatch) => ((patternMatch["user"] && patternMatch["postId"] && patternMatch["postId"].length <= 21)
|
"tiktok": (patternMatch) => ((patternMatch["user"] && patternMatch["postId"] && patternMatch["postId"].length <= 21)
|
||||||
|| (patternMatch["id"] && patternMatch["id"].length <= 13)),
|
|| (patternMatch["id"] && patternMatch["id"].length <= 13)),
|
||||||
|
|
|
@ -9,7 +9,7 @@ const apiVar = {
|
||||||
},
|
},
|
||||||
booleanOnly: ["isAudioOnly", "isNoTTWatermark", "isTTFullAudio", "isAudioMuted", "dubLang", "vimeoDash", "disableMetadata"]
|
booleanOnly: ["isAudioOnly", "isNoTTWatermark", "isTTFullAudio", "isAudioMuted", "dubLang", "vimeoDash", "disableMetadata"]
|
||||||
}
|
}
|
||||||
const forbiddenChars = ['}', '{', '(', ')', '\\', '%', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@", '=='];
|
const forbiddenChars = ['}', '{', '(', ')', '\\', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@", '=='];
|
||||||
const forbiddenCharsString = ['}', '{', '%', '>', '<', '^', ';', '`', '$', '"', "@", '='];
|
const forbiddenCharsString = ['}', '{', '%', '>', '<', '^', ';', '`', '$', '"', "@", '='];
|
||||||
|
|
||||||
export function apiJSON(type, obj) {
|
export function apiJSON(type, obj) {
|
||||||
|
|
Loading…
Reference in a new issue