Skip to content

best way to save what you love

api: clean url upon entry, not down the road

wukkoddc87ca42bb4
diff --git a/src/core/api.js b/src/core/api.js
index 4e78fbb5..71ce8d3e 100644
--- a/src/core/api.js
+++ b/src/core/api.js
@@ -97,7 +97,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
let chck = checkJSONPost(request);
if (!chck) throw new Error();
- j = await getJSON(chck["url"], lang, chck);
+ j = await getJSON(chck.url, lang, chck);
} else {
j = apiJSON(0, {
t: !contentCon ? "invalid content type header" : loc(lang, 'ErrorNoLink')
diff --git a/src/modules/api.js b/src/modules/api.js
index 21132022..c3549bb3 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -4,11 +4,10 @@ import { apiJSON } from "./sub/utils.js";
import { errorUnsupported } from "./sub/errors.js";
import loc from "../localization/manager.js";
import match from "./processing/match.js";
-import { getHostIfValid, normalizeURL } from "./processing/url.js";
+import { getHostIfValid } from "./processing/url.js";
-export async function getJSON(originalURL, lang, obj) {
+export async function getJSON(url, lang, obj) {
try {
- const url = normalizeURL(decodeURIComponent(originalURL));
const host = getHostIfValid(url);
if (!host || !services[host].enabled) {
diff --git a/src/modules/processing/url.js b/src/modules/processing/url.js
index bb602109..2f1ac87f 100644
--- a/src/modules/processing/url.js
+++ b/src/modules/processing/url.js
@@ -93,4 +93,4 @@ export function getHostIfValid(url) {
if (!validSubdomain && !anySubdomainAllowed) return;
return host.sld;
-}
\ No newline at end of file
+}
diff --git a/src/modules/sub/utils.js b/src/modules/sub/utils.js
index ef64d07b..28d37c6c 100644
--- a/src/modules/sub/utils.js
+++ b/src/modules/sub/utils.js
@@ -1,3 +1,4 @@
+import { normalizeURL } from "../processing/url.js";
import { createStream } from "../stream/manage.js";
const apiVar = {
@@ -72,6 +73,7 @@ export function unicodeDecode(str) {
}
export function checkJSONPost(obj) {
let def = {
+ url: normalizeURL(decodeURIComponent(obj.url)),
vCodec: "h264",
vQuality: "720",
aFormat: "mp3",
@@ -101,7 +103,7 @@ export function checkJSONPost(obj) {
if (def.dubLang)
def.dubLang = verifyLanguageCode(obj.dubLang);
- def.url = obj.url;
+
return def
} catch (e) {
return false