Skip to content

Commit

Permalink
Merge pull request #5 from lastarc/refactor-embed-proxy
Browse files Browse the repository at this point in the history
feat(bot): add emded-proxy v2 support with v1 as fallback
  • Loading branch information
lastarc authored Mar 31, 2024
2 parents 62133dd + e03d632 commit 67accb5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion bot/commands/media/tiktok.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
},
};

0 comments on commit 67accb5

Please sign in to comment.