mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 20:32:50 +02:00
Move calls from getPublicUrlForMxc to getMedia
This commit is contained in:
parent
b45d0f3038
commit
c0d92ea66d
7 changed files with 64 additions and 52 deletions
|
@ -297,6 +297,7 @@ async function setUserPowerCascade(roomID, mxid, power) {
|
|||
}
|
||||
|
||||
async function ping() {
|
||||
// not using mreq so that we can read the status code
|
||||
const res = await fetch(`${mreq.baseUrl}/client/v1/appservice/${reg.id}/ping`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -312,6 +313,21 @@ async function ping() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} mxc
|
||||
* @param {RequestInit} [init]
|
||||
*/
|
||||
function getMedia(mxc, init = {}) {
|
||||
const mediaParts = mxc?.match(/^mxc:\/\/([^/]+)\/(\w+)$/)
|
||||
assert(mediaParts)
|
||||
return fetch(`${mreq.baseUrl}/client/v1/media/download/${mediaParts[1]}/${mediaParts[2]}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${reg.as_token}`
|
||||
},
|
||||
...init
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.path = path
|
||||
module.exports.register = register
|
||||
module.exports.createRoom = createRoom
|
||||
|
@ -336,3 +352,4 @@ module.exports.profileSetAvatarUrl = profileSetAvatarUrl
|
|||
module.exports.setUserPower = setUserPower
|
||||
module.exports.setUserPowerCascade = setUserPowerCascade
|
||||
module.exports.ping = ping
|
||||
module.exports.getMedia = getMedia
|
||||
|
|
|
@ -217,9 +217,8 @@ const commands = [{
|
|||
} else {
|
||||
// Upload it to Discord and have the bridge sync it back to Matrix again
|
||||
for (const e of toUpload) {
|
||||
const publicUrl = mxUtils.getPublicUrlForMxc(e.url)
|
||||
// @ts-ignore
|
||||
const resizeInput = await fetch(publicUrl, {agent: false}).then(res => res.arrayBuffer())
|
||||
const resizeInput = await api.getMedia(e.url, {agent: false}).then(res => res.arrayBuffer())
|
||||
const resizeOutput = await sharp(resizeInput)
|
||||
.resize(EMOJI_SIZE, EMOJI_SIZE, {fit: "inside", withoutEnlargement: true, background: {r: 0, g: 0, b: 0, alpha: 0}})
|
||||
.png()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue