api: clean url upon entry, not down the road
This commit is contained in:
parent
d6e4b5ac20
commit
ddc87ca42b
4 changed files with 7 additions and 6 deletions
|
@ -97,7 +97,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
||||||
let chck = checkJSONPost(request);
|
let chck = checkJSONPost(request);
|
||||||
if (!chck) throw new Error();
|
if (!chck) throw new Error();
|
||||||
|
|
||||||
j = await getJSON(chck["url"], lang, chck);
|
j = await getJSON(chck.url, lang, chck);
|
||||||
} else {
|
} else {
|
||||||
j = apiJSON(0, {
|
j = apiJSON(0, {
|
||||||
t: !contentCon ? "invalid content type header" : loc(lang, 'ErrorNoLink')
|
t: !contentCon ? "invalid content type header" : loc(lang, 'ErrorNoLink')
|
||||||
|
|
|
@ -4,11 +4,10 @@ import { apiJSON } from "./sub/utils.js";
|
||||||
import { errorUnsupported } from "./sub/errors.js";
|
import { errorUnsupported } from "./sub/errors.js";
|
||||||
import loc from "../localization/manager.js";
|
import loc from "../localization/manager.js";
|
||||||
import match from "./processing/match.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 {
|
try {
|
||||||
const url = normalizeURL(decodeURIComponent(originalURL));
|
|
||||||
const host = getHostIfValid(url);
|
const host = getHostIfValid(url);
|
||||||
|
|
||||||
if (!host || !services[host].enabled) {
|
if (!host || !services[host].enabled) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { normalizeURL } from "../processing/url.js";
|
||||||
import { createStream } from "../stream/manage.js";
|
import { createStream } from "../stream/manage.js";
|
||||||
|
|
||||||
const apiVar = {
|
const apiVar = {
|
||||||
|
@ -72,6 +73,7 @@ export function unicodeDecode(str) {
|
||||||
}
|
}
|
||||||
export function checkJSONPost(obj) {
|
export function checkJSONPost(obj) {
|
||||||
let def = {
|
let def = {
|
||||||
|
url: normalizeURL(decodeURIComponent(obj.url)),
|
||||||
vCodec: "h264",
|
vCodec: "h264",
|
||||||
vQuality: "720",
|
vQuality: "720",
|
||||||
aFormat: "mp3",
|
aFormat: "mp3",
|
||||||
|
@ -101,7 +103,7 @@ export function checkJSONPost(obj) {
|
||||||
|
|
||||||
if (def.dubLang)
|
if (def.dubLang)
|
||||||
def.dubLang = verifyLanguageCode(obj.dubLang);
|
def.dubLang = verifyLanguageCode(obj.dubLang);
|
||||||
def.url = obj.url;
|
|
||||||
return def
|
return def
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue