added bsky embeds

This commit is contained in:
lolcat 2024-10-30 20:35:31 -04:00
parent 4d3c11eb21
commit 3aaf87c50f
1 changed files with 51 additions and 0 deletions

View File

@ -61,6 +61,8 @@ var headers = {
/*
HTTP server bullshit
*/
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const http_bullshit_handler = function(req, res){
switch(req.url){
@ -526,6 +528,55 @@ deek.on("message", async function(msg, user){
var title = json.title;
var description = "By " + json.author_name;
}else if(bsky = link.match(/https?:\/\/bsky\.app\/profile\/([^\/]+)\/post\/([^?]+)/)){
var bsky_profile = bsky[1];
var bsky_post = bsky[2];
if(!bsky_profile.match(/^did:plc:/)){
// resolve handle
var handle = await(fetch("https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=" + bsky_profile));
var handle_json = await handle.json();
bsky_profile = handle_json.did;
}
var res =
await(
fetch(
"https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread" +
"?uri=" + encodeURIComponent("at://" + bsky_profile + "/app.bsky.feed.post/" + bsky_post) +
//"?uri=at%3A%2F%2Fdid%3Aplc%3Aknkltoiapkt336rr335ztt3p%2Fapp.bsky.feed.post%2F3l3gymllsto2z" +
"&depth=0" +
"&parentHeight=0"
)
);
var json = await res.json();
var title = json.thread.post.author.displayName + " (@" + json.thread.post.author.handle + ") " + " on blueskeet";
var description = "❤️ " + json.thread.post.likeCount + " • 💬 " + json.thread.post.replyCount + " • 📅 " + json.thread.post.indexedAt + "\n" + json.thread.post.record.text + " ";
if(
typeof json.thread.post.embed == "object" &&
typeof json.thread.post.embed.images == "object" &&
typeof json.thread.post.embed.images[0] == "object" &&
typeof json.thread.post.embed.images[0].fullsize == "string"
){
// found image
download = json.thread.post.embed.images[0].fullsize;
mimetype = ["image/jpeg", "jpeg", true];
}
else if(
typeof json.thread.post.embed == "object" &&
typeof json.thread.post.embed.thumbnail == "string"
){
// no video support, fuck you bsky for not giving me mp4 files
download = json.thread.post.embed.thumbnail;
mimetype = ["image/jpeg", "jpeg", true];
}
}else{
var res = await fetch(