Move calls from getPublicUrlForMxc to getMedia

This commit is contained in:
Cadence Ember 2024-09-13 17:19:42 +12:00
commit c0d92ea66d
7 changed files with 64 additions and 52 deletions

View file

@ -223,10 +223,10 @@ async function getViaServersQuery(roomID, api) {
*/
function getPublicUrlForMxc(mxc) {
assert(hasher, "xxhash is not ready yet")
const avatarURLParts = mxc?.match(/^mxc:\/\/([^/]+)\/(\w+)$/)
if (!avatarURLParts) return null
const mediaParts = mxc?.match(/^mxc:\/\/([^/]+)\/(\w+)$/)
if (!mediaParts) return null
const serverAndMediaID = `${avatarURLParts[1]}/${avatarURLParts[2]}`
const serverAndMediaID = `${mediaParts[1]}/${mediaParts[2]}`
const unsignedHash = hasher.h64(serverAndMediaID)
const signedHash = unsignedHash - 0x8000000000000000n // shifting down to signed 64-bit range
db.prepare("INSERT OR IGNORE INTO media_proxy (permitted_hash) VALUES (?)").run(signedHash)