fedimbed: add embed image alt text even though bots cant use it yet

This commit is contained in:
Cynthia Foxwell 2025-04-04 18:54:42 -06:00
parent 38ef4d1c2f
commit 28fab3823a
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk
4 changed files with 45 additions and 14 deletions

View file

@ -1 +1,2 @@
data/ data/
pnpm-lock.yaml

View file

@ -41,5 +41,11 @@
"#lib/*.js": "./src/lib/*.js", "#lib/*.js": "./src/lib/*.js",
"#util/*.js": "./src/util/*.js", "#util/*.js": "./src/util/*.js",
"#modules/*.js": "./src/modules/*.js" "#modules/*.js": "./src/modules/*.js"
},
"pnpm": {
"onlyBuiltDependencies": [
"sharp",
"sqlite3"
]
} }
} }

10
pnpm-lock.yaml generated
View file

@ -16,7 +16,7 @@ importers:
version: 1.7.0 version: 1.7.0
'@projectdysnomia/dysnomia': '@projectdysnomia/dysnomia':
specifier: github:projectdysnomia/dysnomia#dev specifier: github:projectdysnomia/dysnomia#dev
version: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc version: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600
dumpy: dumpy:
specifier: github:Cynosphere/dumpy.js specifier: github:Cynosphere/dumpy.js
version: https://codeload.github.com/Cynosphere/dumpy.js/tar.gz/5fc22353cdcb97084bab572266390e780d9f7a7b(encoding@0.1.13) version: https://codeload.github.com/Cynosphere/dumpy.js/tar.gz/5fc22353cdcb97084bab572266390e780d9f7a7b(encoding@0.1.13)
@ -459,9 +459,9 @@ packages:
resolution: {integrity: sha512-aGQIwo6/sWtyyqhVK4e1MtxYz4N1X8CNt6SOtCc+Wnczs5S5ONaLHDDR8LYaGn0MgOwvGgXyuZ5sJIfd7iyoUw==} resolution: {integrity: sha512-aGQIwo6/sWtyyqhVK4e1MtxYz4N1X8CNt6SOtCc+Wnczs5S5ONaLHDDR8LYaGn0MgOwvGgXyuZ5sJIfd7iyoUw==}
engines: {node: '>=0.10'} engines: {node: '>=0.10'}
'@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc': '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600':
resolution: {tarball: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc} resolution: {tarball: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600}
version: 0.2.1 version: 0.2.2
engines: {node: '>=18.0.0'} engines: {node: '>=18.0.0'}
peerDependencies: peerDependencies:
'@discordjs/opus': ^0.9.0 '@discordjs/opus': ^0.9.0
@ -2136,7 +2136,7 @@ snapshots:
jsprim: 1.4.2 jsprim: 1.4.2
sshpk: 1.17.0 sshpk: 1.17.0
'@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc': '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600':
dependencies: dependencies:
ws: 8.18.0 ws: 8.18.0
optionalDependencies: optionalDependencies:

View file

@ -271,7 +271,9 @@ async function blueskyQuoteEmbed(quote) {
const embed = quote.embeds[0]; const embed = quote.embeds[0];
switch (embed.$type) { switch (embed.$type) {
case "app.bsky.embed.images#view": { case "app.bsky.embed.images#view": {
embeds.push(...embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}}))); embeds.push(
...embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize, description: image.alt}}))
);
break; break;
} }
case "app.bsky.embed.video#view": { case "app.bsky.embed.video#view": {
@ -290,7 +292,9 @@ async function blueskyQuoteEmbed(quote) {
} }
case "app.bsky.embed.recordWithMedia#view": { case "app.bsky.embed.recordWithMedia#view": {
if (embed.media.$type === "app.bsky.embed.images#view") { if (embed.media.$type === "app.bsky.embed.images#view") {
embeds.push(...embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}}))); embeds.push(
...embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize, description: image.alt}}))
);
} else if (embed.media.$type === "app.bsky.embed.video#view") { } else if (embed.media.$type === "app.bsky.embed.video#view") {
const lookup = await fetch(`https://plc.directory/${quote.author.did}`).then((res) => res.json()); const lookup = await fetch(`https://plc.directory/${quote.author.did}`).then((res) => res.json());
const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint; const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
@ -426,7 +430,9 @@ async function bluesky(msg, url, spoiler = false) {
if (post.embed) { if (post.embed) {
switch (post.embed.$type) { switch (post.embed.$type) {
case "app.bsky.embed.images#view": { case "app.bsky.embed.images#view": {
embeds.push(...post.embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}}))); embeds.push(
...post.embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize, description: image.alt}}))
);
break; break;
} }
case "app.bsky.embed.video#view": { case "app.bsky.embed.video#view": {
@ -463,7 +469,12 @@ async function bluesky(msg, url, spoiler = false) {
hasQuote = true; hasQuote = true;
if (post.embed.media.$type === "app.bsky.embed.images#view") { if (post.embed.media.$type === "app.bsky.embed.images#view") {
embeds.push(...post.embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}}))); embeds.push(
...post.embed.media.images.map((image) => ({
...mainEmbed,
image: {url: image.fullsize, description: image.alt},
}))
);
} else if (post.embed.media.$type === "app.bsky.embed.video#view") { } else if (post.embed.media.$type === "app.bsky.embed.video#view") {
const lookup = await fetch(`https://plc.directory/${post.author.did}`).then((res) => res.json()); const lookup = await fetch(`https://plc.directory/${post.author.did}`).then((res) => res.json());
const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint; const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
@ -535,7 +546,10 @@ async function bluesky(msg, url, spoiler = false) {
}, },
}).then((res) => Number(res.headers.get("Content-Length"))); }).then((res) => Number(res.headers.get("Content-Length")));
if (size <= getUploadLimit(guild)) { let limit = getUploadLimit(guild);
if (msg.attachmentSizeLimit != null) limit = msg.attachmentSizeLimit;
if (size <= limit) {
const file = await fetch(attachment.url, { const file = await fetch(attachment.url, {
headers: { headers: {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
@ -551,6 +565,7 @@ async function bluesky(msg, url, spoiler = false) {
? attachment.type.replace("/", ".").replace("quicktime", "mov") ? attachment.type.replace("/", ".").replace("quicktime", "mov")
: attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")), : attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")),
file, file,
description: attachment.desc,
}); });
} }
} }
@ -1291,12 +1306,16 @@ async function processUrl(msg, url, spoiler = false, command = false) {
const guild = msg.channel?.guild ?? (msg.guildID ? hf.bot.guilds.get(msg.guildID) : false); const guild = msg.channel?.guild ?? (msg.guildID ? hf.bot.guilds.get(msg.guildID) : false);
let limit = getUploadLimit(guild);
if (msg.attachmentSizeLimit != null) limit = msg.attachmentSizeLimit;
if (images.length > 0) { if (images.length > 0) {
if (images.length <= 4) { if (images.length <= 4) {
for (const attachment of images) { for (const attachment of images) {
const embed = Object.assign({}, baseEmbed); const embed = Object.assign({}, baseEmbed);
embed.image = { embed.image = {
url: attachment.url, url: attachment.url,
description: attachment.desc,
}; };
embeds.push(embed); embeds.push(embed);
} }
@ -1309,7 +1328,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
}, },
}).then((res) => Number(res.headers.get("Content-Length"))); }).then((res) => Number(res.headers.get("Content-Length")));
if (size <= getUploadLimit(guild)) { if (size <= limit) {
const file = await fetch(attachment.url, { const file = await fetch(attachment.url, {
headers: { headers: {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
@ -1341,7 +1360,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
}, },
}).then((res) => Number(res.headers.get("Content-Length"))); }).then((res) => Number(res.headers.get("Content-Length")));
if (size <= getUploadLimit(guild)) { if (size <= limit) {
const file = await fetch(attachment.url, { const file = await fetch(attachment.url, {
headers: { headers: {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
@ -1369,6 +1388,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
const embed = Object.assign({}, baseEmbed); const embed = Object.assign({}, baseEmbed);
embed.image = { embed.image = {
url: attachment.url, url: attachment.url,
description: attachment.desc,
}; };
embeds.push(embed); embeds.push(embed);
} }
@ -1379,6 +1399,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
const embed = Object.assign({}, baseEmbed); const embed = Object.assign({}, baseEmbed);
embed.image = { embed.image = {
url: attachment.url, url: attachment.url,
description: attachment.desc,
}; };
embeds.push(embed); embeds.push(embed);
} }
@ -1394,6 +1415,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
const embed = Object.assign({}, _embed); const embed = Object.assign({}, _embed);
embed.image = { embed.image = {
url: attachment.url, url: attachment.url,
description: attachment.desc,
}; };
embeds.push(embed); embeds.push(embed);
} }
@ -1412,7 +1434,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
}, },
}).then((res) => Number(res.headers.get("Content-Length"))); }).then((res) => Number(res.headers.get("Content-Length")));
if (size <= getUploadLimit(guild)) { if (size <= limit) {
const file = await fetch(attachment.url, { const file = await fetch(attachment.url, {
headers: { headers: {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
@ -1428,6 +1450,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
? attachment.type.replace("/", ".").replace("quicktime", "mov") ? attachment.type.replace("/", ".").replace("quicktime", "mov")
: attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")), : attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")),
file, file,
description: attachment.desc,
}); });
} }
} }
@ -1441,7 +1464,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
}, },
}).then((res) => Number(res.headers.get("Content-Length"))); }).then((res) => Number(res.headers.get("Content-Length")));
if (size <= getUploadLimit(guild)) { if (size <= limit) {
const file = await fetch(attachment.url, { const file = await fetch(attachment.url, {
headers: { headers: {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
@ -1457,6 +1480,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
? attachment.type.replace("/", ".").replace("mpeg", "mp3").replace("vnd.wave", "wav").replace("x-", "") ? attachment.type.replace("/", ".").replace("mpeg", "mp3").replace("vnd.wave", "wav").replace("x-", "")
: attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3")), : attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3")),
file, file,
description: attachment.desc,
}); });
} }
} }