Media send/receive bug fixes
This commit is contained in:
parent
bf290a5cd7
commit
83d8e03f97
1 changed files with 22 additions and 9 deletions
|
|
@ -93,6 +93,7 @@ class Util {
|
|||
return new Promise((resolve, reject) => {
|
||||
const content = event.getContent();
|
||||
var url = null;
|
||||
var mime = "image/png";
|
||||
var file = null;
|
||||
let decrypt = true;
|
||||
if (content.url != null) {
|
||||
|
|
@ -106,6 +107,9 @@ class Util {
|
|||
useAuthedMedia
|
||||
);
|
||||
decrypt = false;
|
||||
if (content.info) {
|
||||
mime = content.info.mimetype;
|
||||
}
|
||||
} else if (content.file && content.file.url) {
|
||||
file = content.file;
|
||||
url = matrixClient.mxcUrlToHttp(
|
||||
|
|
@ -117,6 +121,7 @@ class Util {
|
|||
undefined,
|
||||
useAuthedMedia
|
||||
);
|
||||
mime = file.mimetype;
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
|
|
@ -142,9 +147,9 @@ class Util {
|
|||
})
|
||||
.then((bytes) => {
|
||||
if (asBlob) {
|
||||
resolve(new Blob([bytes.buffer], { type: file.mimetype }));
|
||||
resolve(new Blob([bytes.buffer], { type: mime }));
|
||||
} else {
|
||||
resolve(URL.createObjectURL(new Blob([bytes.buffer], { type: file.mimetype })));
|
||||
resolve(URL.createObjectURL(new Blob([bytes.buffer], { type: mime })));
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
|
|
@ -163,6 +168,7 @@ class Util {
|
|||
return new Promise((resolve, reject) => {
|
||||
const content = event.getContent();
|
||||
var url = null;
|
||||
var mime = "image/png";
|
||||
var file = null;
|
||||
let decrypt = true;
|
||||
if (content.url != null) {
|
||||
|
|
@ -176,6 +182,9 @@ class Util {
|
|||
useAuthedMedia
|
||||
);
|
||||
decrypt = false;
|
||||
if (content.info) {
|
||||
mime = content.info.mimetype;
|
||||
}
|
||||
} else if (content && content.info && content.info.thumbnail_file && content.info.thumbnail_file.url) {
|
||||
file = content.info.thumbnail_file;
|
||||
// var width = w;
|
||||
|
|
@ -199,6 +208,7 @@ class Util {
|
|||
undefined,
|
||||
useAuthedMedia
|
||||
);
|
||||
mime = file.mimetype;
|
||||
} else if (
|
||||
content.file &&
|
||||
content.file.url &&
|
||||
|
|
@ -216,6 +226,7 @@ class Util {
|
|||
undefined,
|
||||
useAuthedMedia
|
||||
);
|
||||
mime = file.mimetype;
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
|
|
@ -224,17 +235,17 @@ class Util {
|
|||
}
|
||||
|
||||
axios
|
||||
.get(url, {
|
||||
.get(url, useAuthedMedia ? {
|
||||
responseType: "arraybuffer",
|
||||
headers: {
|
||||
Authorization: `Bearer ${matrixClient.getAccessToken()}`,
|
||||
},
|
||||
})
|
||||
} : { responseType: "arraybuffer" })
|
||||
.then((response) => {
|
||||
return decrypt ? this.decryptIfNeeded(file, response) : Promise.resolve({ buffer: response.data });
|
||||
})
|
||||
.then((bytes) => {
|
||||
resolve(URL.createObjectURL(new Blob([bytes.buffer], { type: file.mimetype })));
|
||||
resolve(URL.createObjectURL(new Blob([bytes.buffer], { type: mime })));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("Download error: ", err);
|
||||
|
|
@ -423,7 +434,7 @@ class Util {
|
|||
const uploadPromise = new UploadPromise(undefined);
|
||||
uploadPromise.wrappedPromise = new Promise((resolve, reject) => {
|
||||
var reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
reader.onload = async (e) => {
|
||||
if (uploadPromise.aborted) {
|
||||
reject("Aborted");
|
||||
return;
|
||||
|
|
@ -509,7 +520,7 @@ class Util {
|
|||
data = encryptedBytes;
|
||||
|
||||
// Calculate sha256
|
||||
var hash = new Uint8Array(sha256.create().update(data).arrayBuffer());
|
||||
let hash = await crypto.subtle.digest("SHA-256", data);
|
||||
|
||||
const jwk = {
|
||||
kty: "oct",
|
||||
|
|
@ -541,7 +552,7 @@ class Util {
|
|||
if (response.error) {
|
||||
return reject(response.error);
|
||||
}
|
||||
encryptedFile.url = response.content_uri;
|
||||
messageContent.file.url = response.content_uri;
|
||||
return msgtype == "m.audio" ? this.generateWaveform(fileContents, messageContent) : true;
|
||||
})
|
||||
.then(() => {
|
||||
|
|
@ -1126,7 +1137,9 @@ class Util {
|
|||
}
|
||||
|
||||
getFileSizeFormatted(event) {
|
||||
return prettyBytes(this.getFileSize(event));
|
||||
const size = this.getFileSize(event);
|
||||
const res = prettyBytes(size);
|
||||
return res;
|
||||
}
|
||||
|
||||
isFileTypeAPK(event) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue