file types and exports
This commit is contained in:
parent
db04080463
commit
324ccd70b3
21 changed files with 339 additions and 55 deletions
|
|
@ -4,6 +4,7 @@ import dataUriToBuffer from "data-uri-to-buffer";
|
|||
import ImageResize from "image-resize";
|
||||
import { AutoDiscovery } from 'matrix-js-sdk';
|
||||
import User from '../models/user';
|
||||
const prettyBytes = require("pretty-bytes");
|
||||
|
||||
export const STATE_EVENT_ROOM_DELETION_NOTICE = "im.keanu.room_deletion_notice";
|
||||
export const STATE_EVENT_ROOM_DELETED = "im.keanu.room_deleted";
|
||||
|
|
@ -159,7 +160,7 @@ class Util {
|
|||
// true
|
||||
// );
|
||||
url = matrixClient.mxcUrlToHttp(file.url);
|
||||
} else if (content.file && content.file.url) {
|
||||
} else if (content.file && content.file.url && this.getMimeType(event).startsWith("image/")) {
|
||||
// No thumb, use real url
|
||||
file = content.file;
|
||||
url = matrixClient.mxcUrlToHttp(file.url);
|
||||
|
|
@ -348,7 +349,7 @@ class Util {
|
|||
});
|
||||
}
|
||||
|
||||
sendImage(matrixClient, roomId, file, onUploadProgress, threadRoot) {
|
||||
sendFile(matrixClient, roomId, file, onUploadProgress, threadRoot) {
|
||||
const uploadPromise = new UploadPromise(undefined);
|
||||
uploadPromise.wrappedPromise = new Promise((resolve, reject) => {
|
||||
var reader = new FileReader();
|
||||
|
|
@ -371,13 +372,13 @@ class Util {
|
|||
}
|
||||
|
||||
var description = file.name;
|
||||
var msgtype = 'm.image';
|
||||
if (file.type.startsWith("audio/")) {
|
||||
var msgtype = 'm.file';
|
||||
if (file.type.startsWith("image/")) {
|
||||
msgtype = 'm.image';
|
||||
} else if (file.type.startsWith("audio/")) {
|
||||
msgtype = 'm.audio';
|
||||
} else if (file.type.startsWith("video/")) {
|
||||
msgtype = 'm.video';
|
||||
} else if (file.type.startsWith("application/pdf")) {
|
||||
msgtype = 'm.file';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
|
|
@ -913,7 +914,6 @@ class Util {
|
|||
link.download = event.getContent().body || this.$t("fallbacks.download_name");
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
setTimeout(function () {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
|
|
@ -951,6 +951,68 @@ class Util {
|
|||
}
|
||||
return Promise.resolve(config.defaultBaseUrl);
|
||||
}
|
||||
|
||||
getMimeType(event) {
|
||||
const content = event.getContent();
|
||||
return (content.info && content.info.mimetype) ? content.info.mimetype : (content.file && content.file.mimetype) ? content.file.mimetype : "";
|
||||
}
|
||||
|
||||
getFileName(event) {
|
||||
const content = event.getContent();
|
||||
return (content.body || content.filename || "").toLowerCase();
|
||||
}
|
||||
|
||||
getFileExtension(event) {
|
||||
const fileName = this.getFileName(event);
|
||||
const parts = fileName.split(".");
|
||||
if (parts.length > 1) {
|
||||
return "." + parts[parts.length - 1].toLowerCase();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
getFileSize(event) {
|
||||
const content = event.getContent();
|
||||
if (content.info) {
|
||||
return content.info.size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
getFileSizeFormatted(event) {
|
||||
return prettyBytes(this.getFileSize(event));
|
||||
}
|
||||
|
||||
isFileTypeAPK(event) {
|
||||
const mime = this.getMimeType(event);
|
||||
if (mime === "application/vnd.android.package-archive" || this.getFileName(event).endsWith(".apk")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isFileTypeIPA(event) {
|
||||
if (this.getFileName(event).endsWith(".ipa")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isFileTypePDF(event) {
|
||||
const mime = this.getMimeType(event);
|
||||
if (mime === "application/pdf" || this.getFileName(event).endsWith(".pdf")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isFileTypeZip(event) {
|
||||
const mime = this.getMimeType(event);
|
||||
if (["application/zip", "application/x-zip-compressed", "multipart/x-zip"].includes(mime) || this.getFileName(event).endsWith(".zip")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export default new Util();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue