From b4364c4921ee1ed34a55ad69bde72810b7812eda Mon Sep 17 00:00:00 2001 From: wukko Date: Wed, 15 May 2024 22:36:24 +0600 Subject: [PATCH] match: remove useless errors module & clean up --- src/modules/processing/match.js | 40 +++++++++++++++++++++++---------- src/modules/sub/errors.js | 11 --------- 2 files changed, 28 insertions(+), 23 deletions(-) delete mode 100644 src/modules/sub/errors.js diff --git a/src/modules/processing/match.js b/src/modules/processing/match.js index 73102dfb..5dfd2765 100644 --- a/src/modules/processing/match.js +++ b/src/modules/processing/match.js @@ -1,8 +1,7 @@ import { strict as assert } from "node:assert"; +import { env } from '../config.js'; import { createResponse } from "../processing/request.js"; -import { errorUnsupported, genericError, brokenLink } from "../sub/errors.js"; - import loc from "../../localization/manager.js"; import { testers } from "./servicesPatternTesters.js"; @@ -25,9 +24,9 @@ import streamable from "./services/streamable.js"; import twitch from "./services/twitch.js"; import rutube from "./services/rutube.js"; import dailymotion from "./services/dailymotion.js"; -import { env } from '../config.js'; let freebind; + export default async function(host, patternMatch, lang, obj) { const { url } = obj; assert(url instanceof URL); @@ -43,10 +42,20 @@ export default async function(host, patternMatch, lang, obj) { } try { - let r, isAudioOnly = !!obj.isAudioOnly, disableMetadata = !!obj.disableMetadata; + let r, + isAudioOnly = !!obj.isAudioOnly, + disableMetadata = !!obj.disableMetadata; - if (!testers[host]) return createResponse("error", { t: errorUnsupported(lang) }); - if (!(testers[host](patternMatch))) return createResponse("error", { t: brokenLink(lang, host) }); + if (!testers[host]) { + return createResponse("error", { + t: loc(lang, 'ErrorUnsupported') + }); + } + if (!(testers[host](patternMatch))) { + return createResponse("error", { + t: loc(lang, 'ErrorBrokenLink', host) + }); + } switch (host) { case "twitter": @@ -177,21 +186,26 @@ export default async function(host, patternMatch, lang, obj) { r = await dailymotion(patternMatch); break; default: - return createResponse("error", { t: errorUnsupported(lang) }); + return createResponse("error", { + t: loc(lang, 'ErrorUnsupported') + }); } if (r.isAudioOnly) isAudioOnly = true; let isAudioMuted = isAudioOnly ? false : obj.isAudioMuted; - if (r.error && r.critical) - return createResponse("critical", { t: loc(lang, r.error) }) - - if (r.error) + if (r.error && r.critical) { + return createResponse("critical", { + t: loc(lang, r.error) + }) + } + if (r.error) { return createResponse("error", { t: Array.isArray(r.error) ? loc(lang, r.error[0], r.error[1]) : loc(lang, r.error) }) + } return matchActionDecider( r, host, obj.aFormat, isAudioOnly, @@ -200,6 +214,8 @@ export default async function(host, patternMatch, lang, obj) { requestIP ) } catch { - return createResponse("error", { t: genericError(lang, host) }) + return createResponse("error", { + t: loc(lang, 'ErrorBadFetch', host) + }) } } diff --git a/src/modules/sub/errors.js b/src/modules/sub/errors.js deleted file mode 100644 index c73ffe85..00000000 --- a/src/modules/sub/errors.js +++ /dev/null @@ -1,11 +0,0 @@ -import loc from "../../localization/manager.js"; - -export function errorUnsupported(lang) { - return loc(lang, 'ErrorUnsupported'); -} -export function brokenLink(lang, host) { - return loc(lang, 'ErrorBrokenLink', host); -} -export function genericError(lang, host) { - return loc(lang, 'ErrorBadFetch', host); -}