best way to save what you love
Svelte collaborationdownloaderinstagramjavascriptmusicredditsocial-mediasoundcloudsveltetiktoktwittertypescriptvideovimeovkwebappyoutubeyoutube-downloader
api: move error context to matcher
wukko7ac0726f3769
diff --git a/api/src/processing/match.js b/api/src/processing/match.jsindex cc58565b..d5fc5e34 100644--- a/api/src/processing/match.js+++ b/api/src/processing/match.js@@ -246,9 +246,27 @@ export default async function(host, patternMatch, obj) {}if (r.error) {+ let context;+ switch(r.error) {+ case "content.too_long":+ context = {+ limit: env.durationLimit / 60,+ }+ break;++ case "fetch.fail":+ case "fetch.rate":+ case "content.video.unavailable":+ case "link.unsupported":+ context = {+ service: host,+ }+ break;+ }+return createResponse("error", {code: `error.api.${r.error}`,- context: r?.context+ context})}diff --git a/api/src/processing/services/bilibili.js b/api/src/processing/services/bilibili.jsindex c4762bad..b47b0bc2 100644--- a/api/src/processing/services/bilibili.js+++ b/api/src/processing/services/bilibili.js@@ -47,12 +47,7 @@ async function com_download(id) {let streamData = JSON.parse(html.split('<script>window.__playinfo__=')[1].split('</script>')[0]);if (streamData.data.timelength > env.durationLimit * 1000) {- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };}const [ video, audio ] = extractBestQuality(streamData.data.dash);@@ -92,12 +87,7 @@ async function tv_download(id) {}if (video.duration > env.durationLimit * 1000) {- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };}return {diff --git a/api/src/processing/services/dailymotion.js b/api/src/processing/services/dailymotion.jsindex 67d867cc..a403a16b 100644--- a/api/src/processing/services/dailymotion.js+++ b/api/src/processing/services/dailymotion.js@@ -74,12 +74,7 @@ export default async function({ id }) {}if (media.duration > env.durationLimit) {- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };}const manifest = await fetch(media.hlsURL).then(r => r.text()).catch(() => {});diff --git a/api/src/processing/services/instagram.js b/api/src/processing/services/instagram.jsindex 2dfe98ea..ec225372 100644--- a/api/src/processing/services/instagram.js+++ b/api/src/processing/services/instagram.js@@ -295,12 +295,7 @@ export default function(obj) {async function getStory(username, id) {const cookie = getCookie('instagram');- if (!cookie) return {- error: "link.unsupported",- context: {- service: "instagram"- }- }+ if (!cookie) return { error: "link.unsupported" };const userId = await usernameToId(username, cookie);if (!userId) return { error: "fetch.empty" };@@ -343,12 +338,7 @@ export default function(obj) {}}- return {- error: "link.unsupported",- context: {- service: "instagram"- }- }+ return { error: "link.unsupported" };}const { postId, storyId, username } = obj;diff --git a/api/src/processing/services/ok.js b/api/src/processing/services/ok.jsindex afa3f0e8..2fb6082d 100644--- a/api/src/processing/services/ok.js+++ b/api/src/processing/services/ok.js@@ -38,12 +38,7 @@ export default async function(o) {return { error: "content.video.live" };if (videoData.movie.duration > env.durationLimit)- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };let videos = videoData.videos.filter(v => !v.disallowed);let bestVideo = videos.find(v => resolutions[v.name] === quality) || videos[videos.length - 1];diff --git a/api/src/processing/services/reddit.js b/api/src/processing/services/reddit.jsindex 607a78b6..271cdc86 100644--- a/api/src/processing/services/reddit.js+++ b/api/src/processing/services/reddit.js@@ -82,12 +82,7 @@ export default async function(obj) {return { error: "fetch.empty" };if (data.secure_media?.reddit_video?.duration > env.durationLimit)- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };let audio = false,video = data.secure_media?.reddit_video?.fallback_url?.split('?')[0],diff --git a/api/src/processing/services/rutube.js b/api/src/processing/services/rutube.jsindex 705c455e..4305241a 100644--- a/api/src/processing/services/rutube.js+++ b/api/src/processing/services/rutube.js@@ -39,12 +39,7 @@ export default async function(obj) {if (play.live_streams?.hls) return { error: "content.video.live" };if (play.duration > env.durationLimit * 1000)- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };let m3u8 = await fetch(play.video_balancer.m3u8).then(r => r.text())diff --git a/api/src/processing/services/soundcloud.js b/api/src/processing/services/soundcloud.jsindex 317149cc..394f7dfe 100644--- a/api/src/processing/services/soundcloud.js+++ b/api/src/processing/services/soundcloud.js@@ -82,12 +82,7 @@ export default async function(obj) {return { error: "fetch.empty" };if (json.duration > env.durationLimit * 1000) {- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };}let file = await fetch(fileUrl)diff --git a/api/src/processing/services/tumblr.js b/api/src/processing/services/tumblr.jsindex b25d17f4..b361b98c 100644--- a/api/src/processing/services/tumblr.js+++ b/api/src/processing/services/tumblr.js@@ -22,12 +22,7 @@ export default async function(input) {let { subdomain } = psl.parse(input.url.hostname);if (subdomain?.includes('.')) {- return {- error: "link.unsupported",- context: {- service: "tumblr"- }- }+ return { error: "link.unsupported" };} else if (subdomain === 'www' || subdomain === 'at') {subdomain = undefined}diff --git a/api/src/processing/services/twitch.js b/api/src/processing/services/twitch.jsindex a8d5977c..ac85fbcf 100644--- a/api/src/processing/services/twitch.js+++ b/api/src/processing/services/twitch.js@@ -36,12 +36,7 @@ export default async function (obj) {const clipMetadata = req_metadata.data.clip;if (clipMetadata.durationSeconds > env.durationLimit) {- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };}if (!clipMetadata.videoQualities || !clipMetadata.broadcaster) {return { error: "fetch.empty" };diff --git a/api/src/processing/services/vimeo.js b/api/src/processing/services/vimeo.jsindex 657d1e02..23e84191 100644--- a/api/src/processing/services/vimeo.js+++ b/api/src/processing/services/vimeo.js@@ -77,12 +77,7 @@ const getHLS = async (configURL, obj) => {if (!api) return { error: "fetch.fail" };if (api.video?.duration > env.durationLimit) {- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };}const urlMasterHLS = api.request?.files?.hls?.cdns?.akfire_interconnect_quic?.url;diff --git a/api/src/processing/services/vk.js b/api/src/processing/services/vk.jsindex 5047b843..e3c18e47 100644--- a/api/src/processing/services/vk.js+++ b/api/src/processing/services/vk.js@@ -29,12 +29,7 @@ export default async function(o) {}if (js.mvData.duration > env.durationLimit) {- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };}for (let i in resolutions) {diff --git a/api/src/processing/services/youtube.js b/api/src/processing/services/youtube.jsindex c7d31555..5eea581a 100644--- a/api/src/processing/services/youtube.js+++ b/api/src/processing/services/youtube.js@@ -210,12 +210,7 @@ export default async function(o) {return { error: "youtube.codec" };if (basicInfo.duration > env.durationLimit)- return {- error: "content.too_long",- context: {- limit: env.durationLimit / 60- }- }+ return { error: "content.too_long" };const checkBestAudio = (i) => (i.has_audio && !i.has_video);