api/match: accept object as single argument

hi im what i do
This commit is contained in:
wukko 2024-09-02 08:27:31 +06:00
parent 93f2a6b226
commit 8cee4e58c5
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
2 changed files with 34 additions and 33 deletions

View file

@ -213,9 +213,11 @@ export const runAPI = (express, app, __dirname) => {
} }
try { try {
const result = await match( const result = await match({
parsed.host, parsed.patternMatch, normalizedRequest host: parsed.host,
); patternMatch: parsed.patternMatch,
params: normalizedRequest,
});
res.status(result.status).json(result.body); res.status(result.status).json(result.body);
} catch { } catch {

View file

@ -32,8 +32,8 @@ import bluesky from "./services/bluesky.js";
let freebind; let freebind;
export default async function(host, patternMatch, obj) { export default async function({ host, patternMatch, params }) {
const { url } = obj; const { url } = params;
assert(url instanceof URL); assert(url instanceof URL);
let dispatcher, requestIP; let dispatcher, requestIP;
@ -48,9 +48,8 @@ export default async function(host, patternMatch, obj) {
try { try {
let r, let r,
isAudioOnly = obj.downloadMode === "audio", isAudioOnly = params.downloadMode === "audio",
isAudioMuted = obj.downloadMode === "mute", isAudioMuted = params.downloadMode === "mute";
disableMetadata = !!obj.disableMetadata;
if (!testers[host]) { if (!testers[host]) {
return createResponse("error", { return createResponse("error", {
@ -71,8 +70,8 @@ export default async function(host, patternMatch, obj) {
r = await twitter({ r = await twitter({
id: patternMatch.id, id: patternMatch.id,
index: patternMatch.index - 1, index: patternMatch.index - 1,
toGif: !!obj.twitterGif, toGif: !!params.twitterGif,
alwaysProxy: obj.alwaysProxy, alwaysProxy: params.alwaysProxy,
dispatcher dispatcher
}); });
break; break;
@ -81,14 +80,14 @@ export default async function(host, patternMatch, obj) {
r = await vk({ r = await vk({
userId: patternMatch.userId, userId: patternMatch.userId,
videoId: patternMatch.videoId, videoId: patternMatch.videoId,
quality: obj.videoQuality quality: params.videoQuality
}); });
break; break;
case "ok": case "ok":
r = await ok({ r = await ok({
id: patternMatch.id, id: patternMatch.id,
quality: obj.videoQuality quality: params.videoQuality
}); });
break; break;
@ -99,11 +98,11 @@ export default async function(host, patternMatch, obj) {
case "youtube": case "youtube":
let fetchInfo = { let fetchInfo = {
id: patternMatch.id.slice(0, 11), id: patternMatch.id.slice(0, 11),
quality: obj.videoQuality, quality: params.videoQuality,
format: obj.youtubeVideoCodec, format: params.youtubeVideoCodec,
isAudioOnly, isAudioOnly,
isAudioMuted, isAudioMuted,
dubLang: obj.youtubeDubLang, dubLang: params.youtubeDubLang,
dispatcher dispatcher
} }
@ -129,10 +128,10 @@ export default async function(host, patternMatch, obj) {
r = await tiktok({ r = await tiktok({
postId: patternMatch.postId, postId: patternMatch.postId,
id: patternMatch.id, id: patternMatch.id,
fullAudio: obj.tiktokFullAudio, fullAudio: params.tiktokFullAudio,
isAudioOnly, isAudioOnly,
h265: obj.tiktokH265, h265: params.tiktokH265,
alwaysProxy: obj.alwaysProxy, alwaysProxy: params.alwaysProxy,
}); });
break; break;
@ -148,7 +147,7 @@ export default async function(host, patternMatch, obj) {
r = await vimeo({ r = await vimeo({
id: patternMatch.id.slice(0, 11), id: patternMatch.id.slice(0, 11),
password: patternMatch.password, password: patternMatch.password,
quality: obj.videoQuality, quality: params.videoQuality,
isAudioOnly, isAudioOnly,
}); });
break; break;
@ -160,7 +159,7 @@ export default async function(host, patternMatch, obj) {
url, url,
author: patternMatch.author, author: patternMatch.author,
song: patternMatch.song, song: patternMatch.song,
format: obj.audioFormat, format: params.audioFormat,
shortLink: patternMatch.shortLink || false, shortLink: patternMatch.shortLink || false,
accessKey: patternMatch.accessKey || false accessKey: patternMatch.accessKey || false
}); });
@ -169,8 +168,8 @@ export default async function(host, patternMatch, obj) {
case "instagram": case "instagram":
r = await instagram({ r = await instagram({
...patternMatch, ...patternMatch,
quality: obj.videoQuality, quality: params.videoQuality,
alwaysProxy: obj.alwaysProxy, alwaysProxy: params.alwaysProxy,
dispatcher dispatcher
}) })
break; break;
@ -191,7 +190,7 @@ export default async function(host, patternMatch, obj) {
case "streamable": case "streamable":
r = await streamable({ r = await streamable({
id: patternMatch.id, id: patternMatch.id,
quality: obj.videoQuality, quality: params.videoQuality,
isAudioOnly, isAudioOnly,
}); });
break; break;
@ -199,7 +198,7 @@ export default async function(host, patternMatch, obj) {
case "twitch": case "twitch":
r = await twitch({ r = await twitch({
clipId: patternMatch.clip || false, clipId: patternMatch.clip || false,
quality: obj.videoQuality, quality: params.videoQuality,
isAudioOnly, isAudioOnly,
}); });
break; break;
@ -209,7 +208,7 @@ export default async function(host, patternMatch, obj) {
id: patternMatch.id, id: patternMatch.id,
yappyId: patternMatch.yappyId, yappyId: patternMatch.yappyId,
key: patternMatch.key, key: patternMatch.key,
quality: obj.videoQuality, quality: params.videoQuality,
isAudioOnly, isAudioOnly,
}); });
break; break;
@ -221,7 +220,7 @@ export default async function(host, patternMatch, obj) {
case "snapchat": case "snapchat":
r = await snapchat({ r = await snapchat({
...patternMatch, ...patternMatch,
alwaysProxy: obj.alwaysProxy, alwaysProxy: params.alwaysProxy,
}); });
break; break;
@ -240,7 +239,7 @@ export default async function(host, patternMatch, obj) {
case "bsky": case "bsky":
r = await bluesky({ r = await bluesky({
...patternMatch, ...patternMatch,
alwaysProxy: obj.alwaysProxy alwaysProxy: params.alwaysProxy
}); });
break; break;
@ -290,15 +289,15 @@ export default async function(host, patternMatch, obj) {
return matchAction({ return matchAction({
r, r,
host, host,
audioFormat: obj.audioFormat, audioFormat: params.audioFormat,
isAudioOnly, isAudioOnly,
isAudioMuted, isAudioMuted,
disableMetadata, disableMetadata: params.disableMetadata,
filenameStyle: obj.filenameStyle, filenameStyle: params.filenameStyle,
twitterGif: obj.twitterGif, twitterGif: params.twitterGif,
requestIP, requestIP,
audioBitrate: obj.audioBitrate, audioBitrate: params.audioBitrate,
alwaysProxy: obj.alwaysProxy, alwaysProxy: params.alwaysProxy,
}) })
} catch { } catch {
return createResponse("error", { return createResponse("error", {