d->m: Try too-large PNGs as JPEG for upload
Large PNGs were almost certainly originally JPEG photos that were converted to PNG by the user copy-pasting. If the PNG is just supposed to be that large, you can still get the original through the external URL option. Had to change _removeExpiryParams to be based on URL parsing instead of regexp because regexp didn't work with &format=jpeg on the end.
This commit is contained in:
@@ -1103,6 +1103,45 @@ test("message2event: very large attachment is linked instead of being uploaded",
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: very large png is converted to jpeg for upload", async t => {
|
||||
const events = await messageToEvent({
|
||||
content: "",
|
||||
attachments: [{
|
||||
filename: "855064e9-bdae-487a-a497-c662bd510487.png",
|
||||
url: "https://cdn.discordapp.com/attachments/1160894080998461480/1548656385292509274/855064e9-bdae-487a-a497-c662bd510487.png",
|
||||
proxy_url: "https://media.discordapp.net/attachments/1160894080998461480/1548656385292509274/855064e9-bdae-487a-a497-c662bd510487.png",
|
||||
content_type: "image/png",
|
||||
width: 5472,
|
||||
height: 3648,
|
||||
size: 14967919
|
||||
}]
|
||||
}, data.guild.general, {}, {
|
||||
async fetch(url, init) {
|
||||
t.equal(url, "https://media.discordapp.net/attachments/1160894080998461480/1548656385292509274/855064e9-bdae-487a-a497-c662bd510487.png?format=jpeg")
|
||||
t.equal(init.method, "HEAD")
|
||||
return new Response("wa", {headers: {
|
||||
"Content-Type": "image/jpeg",
|
||||
"Content-Length": 483085
|
||||
}})
|
||||
}
|
||||
})
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
"m.mentions": {},
|
||||
msgtype: "m.image",
|
||||
body: "855064e9-bdae-487a-a497-c662bd510487.jpg",
|
||||
info: {
|
||||
w: 5472,
|
||||
h: 3648,
|
||||
mimetype: "image/jpeg",
|
||||
size: 483085
|
||||
},
|
||||
external_url: "https://bridge.example.org/download/discordcdn/1160894080998461480/1548656385292509274/855064e9-bdae-487a-a497-c662bd510487.png",
|
||||
filename: "855064e9-bdae-487a-a497-c662bd510487.jpg",
|
||||
url: "mxc://cadence.moe/zXNXRvJwRDMIzZZVqHUXtGeD"
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: multiple attachments are combined into the same event where possible", async t => {
|
||||
const events = await messageToEvent({
|
||||
content: "hey",
|
||||
|
||||
Reference in New Issue
Block a user