Use attachment proxy for external_url
This commit is contained in:
parent
49948ae2c1
commit
b23b818192
3 changed files with 19 additions and 19 deletions
|
@ -67,7 +67,7 @@ test("message2event embeds: image embed and attachment", async t => {
|
||||||
msgtype: "m.image",
|
msgtype: "m.image",
|
||||||
url: "mxc://cadence.moe/zAXdQriaJuLZohDDmacwWWDR",
|
url: "mxc://cadence.moe/zAXdQriaJuLZohDDmacwWWDR",
|
||||||
body: "Screenshot_20231001_034036.jpg",
|
body: "Screenshot_20231001_034036.jpg",
|
||||||
external_url: "https://cdn.discordapp.com/attachments/176333891320283136/1157854643037163610/Screenshot_20231001_034036.jpg?ex=651a1faa&is=6518ce2a&hm=eb5ca80a3fa7add8765bf404aea2028a28a2341e4a62435986bcdcf058da82f3&",
|
external_url: "https://bridge.example.org/download/discordcdn/176333891320283136/1157854643037163610/Screenshot_20231001_034036.jpg",
|
||||||
filename: "Screenshot_20231001_034036.jpg",
|
filename: "Screenshot_20231001_034036.jpg",
|
||||||
info: {
|
info: {
|
||||||
h: 1170,
|
h: 1170,
|
||||||
|
|
|
@ -103,7 +103,7 @@ const embedTitleParser = markdown.markdownEngine.parserFor({
|
||||||
* @param {DiscordTypes.APIAttachment} attachment
|
* @param {DiscordTypes.APIAttachment} attachment
|
||||||
*/
|
*/
|
||||||
async function attachmentToEvent(mentions, attachment) {
|
async function attachmentToEvent(mentions, attachment) {
|
||||||
const publicURL = dUtils.getPublicUrlForCdn(attachment.url)
|
const external_url = dUtils.getPublicUrlForCdn(attachment.url)
|
||||||
const emoji =
|
const emoji =
|
||||||
attachment.content_type?.startsWith("image/jp") ? "📸"
|
attachment.content_type?.startsWith("image/jp") ? "📸"
|
||||||
: attachment.content_type?.startsWith("image/") ? "🖼️"
|
: attachment.content_type?.startsWith("image/") ? "🖼️"
|
||||||
|
@ -117,9 +117,9 @@ async function attachmentToEvent(mentions, attachment) {
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
"m.mentions": mentions,
|
"m.mentions": mentions,
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
body: `${emoji} Uploaded SPOILER file: ${publicURL} (${pb(attachment.size)})`,
|
body: `${emoji} Uploaded SPOILER file: ${external_url} (${pb(attachment.size)})`,
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: `<blockquote>${emoji} Uploaded SPOILER file: <a href="${publicURL}">${publicURL}</a> (${pb(attachment.size)})</blockquote>`
|
formatted_body: `<blockquote>${emoji} Uploaded SPOILER file: <a href="${external_url}">${external_url}</a> (${pb(attachment.size)})</blockquote>`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for large files, always link them instead of uploading so I don't use up all the space in the content repo
|
// for large files, always link them instead of uploading so I don't use up all the space in the content repo
|
||||||
|
@ -128,9 +128,9 @@ async function attachmentToEvent(mentions, attachment) {
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
"m.mentions": mentions,
|
"m.mentions": mentions,
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
body: `${emoji} Uploaded file: ${publicURL} (${pb(attachment.size)})`,
|
body: `${emoji} Uploaded file: ${external_url} (${pb(attachment.size)})`,
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: `${emoji} Uploaded file: <a href="${publicURL}">${attachment.filename}</a> (${pb(attachment.size)})`
|
formatted_body: `${emoji} Uploaded file: <a href="${external_url}">${attachment.filename}</a> (${pb(attachment.size)})`
|
||||||
}
|
}
|
||||||
} else if (attachment.content_type?.startsWith("image/") && attachment.width && attachment.height) {
|
} else if (attachment.content_type?.startsWith("image/") && attachment.width && attachment.height) {
|
||||||
return {
|
return {
|
||||||
|
@ -138,7 +138,7 @@ async function attachmentToEvent(mentions, attachment) {
|
||||||
"m.mentions": mentions,
|
"m.mentions": mentions,
|
||||||
msgtype: "m.image",
|
msgtype: "m.image",
|
||||||
url: await file.uploadDiscordFileToMxc(attachment.url),
|
url: await file.uploadDiscordFileToMxc(attachment.url),
|
||||||
external_url: attachment.url,
|
external_url,
|
||||||
body: attachment.description || attachment.filename,
|
body: attachment.description || attachment.filename,
|
||||||
filename: attachment.filename,
|
filename: attachment.filename,
|
||||||
info: {
|
info: {
|
||||||
|
@ -154,7 +154,7 @@ async function attachmentToEvent(mentions, attachment) {
|
||||||
"m.mentions": mentions,
|
"m.mentions": mentions,
|
||||||
msgtype: "m.video",
|
msgtype: "m.video",
|
||||||
url: await file.uploadDiscordFileToMxc(attachment.url),
|
url: await file.uploadDiscordFileToMxc(attachment.url),
|
||||||
external_url: attachment.url,
|
external_url,
|
||||||
body: attachment.description || attachment.filename,
|
body: attachment.description || attachment.filename,
|
||||||
filename: attachment.filename,
|
filename: attachment.filename,
|
||||||
info: {
|
info: {
|
||||||
|
@ -170,7 +170,7 @@ async function attachmentToEvent(mentions, attachment) {
|
||||||
"m.mentions": mentions,
|
"m.mentions": mentions,
|
||||||
msgtype: "m.audio",
|
msgtype: "m.audio",
|
||||||
url: await file.uploadDiscordFileToMxc(attachment.url),
|
url: await file.uploadDiscordFileToMxc(attachment.url),
|
||||||
external_url: attachment.url,
|
external_url,
|
||||||
body: attachment.description || attachment.filename,
|
body: attachment.description || attachment.filename,
|
||||||
filename: attachment.filename,
|
filename: attachment.filename,
|
||||||
info: {
|
info: {
|
||||||
|
@ -185,7 +185,7 @@ async function attachmentToEvent(mentions, attachment) {
|
||||||
"m.mentions": mentions,
|
"m.mentions": mentions,
|
||||||
msgtype: "m.file",
|
msgtype: "m.file",
|
||||||
url: await file.uploadDiscordFileToMxc(attachment.url),
|
url: await file.uploadDiscordFileToMxc(attachment.url),
|
||||||
external_url: attachment.url,
|
external_url,
|
||||||
body: attachment.description || attachment.filename,
|
body: attachment.description || attachment.filename,
|
||||||
filename: attachment.filename,
|
filename: attachment.filename,
|
||||||
info: {
|
info: {
|
||||||
|
@ -197,8 +197,8 @@ async function attachmentToEvent(mentions, attachment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("discord-api-types/v10").APIMessage} message
|
* @param {DiscordTypes.APIMessage} message
|
||||||
* @param {import("discord-api-types/v10").APIGuild} guild
|
* @param {DiscordTypes.APIGuild} guild
|
||||||
* @param {{includeReplyFallback?: boolean, includeEditFallbackStar?: boolean}} options default values:
|
* @param {{includeReplyFallback?: boolean, includeEditFallbackStar?: boolean}} options default values:
|
||||||
* - includeReplyFallback: true
|
* - includeReplyFallback: true
|
||||||
* - includeEditFallbackStar: false
|
* - includeEditFallbackStar: false
|
||||||
|
|
|
@ -337,7 +337,7 @@ test("message2event: attachment with no content", async t => {
|
||||||
msgtype: "m.image",
|
msgtype: "m.image",
|
||||||
url: "mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM",
|
url: "mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM",
|
||||||
body: "image.png",
|
body: "image.png",
|
||||||
external_url: "https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png",
|
external_url: "https://bridge.example.org/download/discordcdn/497161332244742154/1124628646431297546/image.png",
|
||||||
filename: "image.png",
|
filename: "image.png",
|
||||||
info: {
|
info: {
|
||||||
mimetype: "image/png",
|
mimetype: "image/png",
|
||||||
|
@ -373,7 +373,7 @@ test("message2event: stickers", async t => {
|
||||||
msgtype: "m.image",
|
msgtype: "m.image",
|
||||||
url: "mxc://cadence.moe/ZDCNYnkPszxGKgObUIFmvjus",
|
url: "mxc://cadence.moe/ZDCNYnkPszxGKgObUIFmvjus",
|
||||||
body: "image.png",
|
body: "image.png",
|
||||||
external_url: "https://cdn.discordapp.com/attachments/122155380120748034/1106366167486038016/image.png",
|
external_url: "https://bridge.example.org/download/discordcdn/122155380120748034/1106366167486038016/image.png",
|
||||||
filename: "image.png",
|
filename: "image.png",
|
||||||
info: {
|
info: {
|
||||||
mimetype: "image/png",
|
mimetype: "image/png",
|
||||||
|
@ -427,7 +427,7 @@ test("message2event: skull webp attachment with content", async t => {
|
||||||
mimetype: "image/webp",
|
mimetype: "image/webp",
|
||||||
size: 74290
|
size: 74290
|
||||||
},
|
},
|
||||||
external_url: "https://cdn.discordapp.com/attachments/112760669178241024/1128084747910918195/skull.webp",
|
external_url: "https://bridge.example.org/download/discordcdn/112760669178241024/1128084747910918195/skull.webp",
|
||||||
filename: "skull.webp",
|
filename: "skull.webp",
|
||||||
url: "mxc://cadence.moe/sDxWmDErBhYBxtDcJQgBETes"
|
url: "mxc://cadence.moe/sDxWmDErBhYBxtDcJQgBETes"
|
||||||
}])
|
}])
|
||||||
|
@ -461,7 +461,7 @@ test("message2event: reply to skull webp attachment with content", async t => {
|
||||||
mimetype: "image/jpeg",
|
mimetype: "image/jpeg",
|
||||||
size: 85906
|
size: 85906
|
||||||
},
|
},
|
||||||
external_url: "https://cdn.discordapp.com/attachments/112760669178241024/1128084851023675515/RDT_20230704_0936184915846675925224905.jpg",
|
external_url: "https://bridge.example.org/download/discordcdn/112760669178241024/1128084851023675515/RDT_20230704_0936184915846675925224905.jpg",
|
||||||
filename: "RDT_20230704_0936184915846675925224905.jpg",
|
filename: "RDT_20230704_0936184915846675925224905.jpg",
|
||||||
url: "mxc://cadence.moe/WlAbFSiNRIHPDEwKdyPeGywa"
|
url: "mxc://cadence.moe/WlAbFSiNRIHPDEwKdyPeGywa"
|
||||||
}])
|
}])
|
||||||
|
@ -551,7 +551,7 @@ test("message2event: reply with a video", async t => {
|
||||||
body: "Ins_1960637570.mp4",
|
body: "Ins_1960637570.mp4",
|
||||||
filename: "Ins_1960637570.mp4",
|
filename: "Ins_1960637570.mp4",
|
||||||
url: "mxc://cadence.moe/kMqLycqMURhVpwleWkmASpnU",
|
url: "mxc://cadence.moe/kMqLycqMURhVpwleWkmASpnU",
|
||||||
external_url: "https://cdn.discordapp.com/attachments/112760669178241024/1197621094786531358/Ins_1960637570.mp4?ex=65bbee8f&is=65a9798f&hm=ae14f7824c3d526c5e11c162e012e1ee405fd5776e1e9302ed80ccd86503cfda&",
|
external_url: "https://bridge.example.org/download/discordcdn/112760669178241024/1197621094786531358/Ins_1960637570.mp4",
|
||||||
info: {
|
info: {
|
||||||
h: 854,
|
h: 854,
|
||||||
mimetype: "video/mp4",
|
mimetype: "video/mp4",
|
||||||
|
@ -572,7 +572,7 @@ test("message2event: voice message", async t => {
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
body: "voice-message.ogg",
|
body: "voice-message.ogg",
|
||||||
external_url: "https://cdn.discordapp.com/attachments/1099031887500034088/1112476845502365786/voice-message.ogg?ex=65c92d4c&is=65b6b84c&hm=0654bab5027474cbe23875954fa117cf44d8914c144cd151879590fa1baf8b1c&",
|
external_url: "https://bridge.example.org/download/discordcdn/1099031887500034088/1112476845502365786/voice-message.ogg",
|
||||||
filename: "voice-message.ogg",
|
filename: "voice-message.ogg",
|
||||||
info: {
|
info: {
|
||||||
duration: 3960.0000381469727,
|
duration: 3960.0000381469727,
|
||||||
|
@ -595,7 +595,7 @@ test("message2event: misc file", async t => {
|
||||||
}, {
|
}, {
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
body: "the.yml",
|
body: "the.yml",
|
||||||
external_url: "https://cdn.discordapp.com/attachments/122155380120748034/1174514575220158545/the.yml?ex=65cd6270&is=65baed70&hm=8c5f1b571784e3c7f99628492298815884e351ae0dc7c2ae40dd22d97caf27d9&",
|
external_url: "https://bridge.example.org/download/discordcdn/122155380120748034/1174514575220158545/the.yml",
|
||||||
filename: "the.yml",
|
filename: "the.yml",
|
||||||
info: {
|
info: {
|
||||||
mimetype: "text/plain; charset=utf-8",
|
mimetype: "text/plain; charset=utf-8",
|
||||||
|
|
Loading…
Reference in a new issue