From e03d632b9590741b0581a29876ac068d845879a5 Mon Sep 17 00:00:00 2001 From: Arc <90333108+lastarc@users.noreply.github.com> Date: Sun, 31 Mar 2024 23:43:33 +0200 Subject: [PATCH] feat(bot): add emded-proxy v2 support with v1 as fallback --- bot/commands/media/tiktok.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bot/commands/media/tiktok.js b/bot/commands/media/tiktok.js index a5ca380..d1585ce 100644 --- a/bot/commands/media/tiktok.js +++ b/bot/commands/media/tiktok.js @@ -107,7 +107,26 @@ module.exports = { } console.log(vurl, vwidth, vheight); - const embeddableUrl = `${EMBED_PROXY_URL}/?src=${encodeURIComponent(vurl)}&width=${vwidth}&height=${vheight}`; + let embeddableUrl = ''; + + const v2Check = await fetch(`${EMBED_PROXY_URL}/v2/healthz`); + if (v2Check.ok) { + const v2Res = await fetch(`${EMBED_PROXY_URL}/v2/add`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + src: vurl, + width: vwidth, + height: vheight, + }), + }); + const v2Json = await v2Res.json(); + embeddableUrl = `${EMBED_PROXY_URL}/v2/~/${v2Json.slug}`; + } else { + embeddableUrl = `${EMBED_PROXY_URL}/?src=${encodeURIComponent(vurl)}&width=${vwidth}&height=${vheight}`; + } await replyMsg.edit(`Done ${embeddableUrl}`); }, }; \ No newline at end of file