sync
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import { createElement, setTooltip, showAlert, createPicture, createAudio, createVideo, createFile } from "../../ui";
|
||||
import { r } from "../../utility";
|
||||
|
||||
export function createBox(title, functions) {
|
||||
const container = createElement('div', 'comm');
|
||||
@ -16,39 +15,51 @@ export function appendMedia(container, mimeType, url) {
|
||||
case 'application/pdf':
|
||||
container.appendChild(createFile(url, 'file-pdf'));
|
||||
break;
|
||||
case 'application/msword':
|
||||
case 'application/vnd.ms-word':
|
||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
||||
container.appendChild(createFile(url, 'file-word'));
|
||||
break;
|
||||
case 'application/vnd.ms-excel':
|
||||
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
||||
container.appendChild(createFile(url, 'file-excel'));
|
||||
break;
|
||||
case 'application/vnd.ms-powerpoint':
|
||||
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
||||
container.appendChild(createFile(url, 'file-powerpoint'));
|
||||
break;
|
||||
case 'application/smil':
|
||||
// TODO: ignore smil files
|
||||
// container.appendChild(createFile(url, 'smile'));
|
||||
break;
|
||||
case 'audio/aac':
|
||||
case 'audio/amr':
|
||||
case 'audio/mp3':
|
||||
case 'audio/mpeg':
|
||||
case 'audio/x-mpeg':
|
||||
case 'audio/aac':
|
||||
case 'audio/ogg':
|
||||
case 'audio/opus':
|
||||
case 'audio/wav':
|
||||
case 'audio/webm':
|
||||
container.appendChild(createAudio(mimeType, url));
|
||||
break;
|
||||
case 'image/gif':
|
||||
case 'image/jpeg':
|
||||
case 'image/png':
|
||||
container.appendChild(createPicture(url));
|
||||
break;
|
||||
case 'text/plain':
|
||||
case 'text/x-vcard':
|
||||
container.appendChild(createFile(url, 'id-card'));
|
||||
break;
|
||||
case 'video/3gpp':
|
||||
case 'video/mp2t':
|
||||
case 'video/mp4':
|
||||
case 'video/mpeg':
|
||||
case 'video/x-mpeg':
|
||||
case 'video/mp2t':
|
||||
case 'video/webm':
|
||||
case 'video/quicktime':
|
||||
case 'video/webm':
|
||||
container.appendChild(createVideo(url));
|
||||
break;
|
||||
default:
|
||||
if (/^audio\//.test(mimeType)) {
|
||||
if (/^image\//.test(mimeType)) {
|
||||
container.appendChild(createPicture(url));
|
||||
} else if (/^audio\//.test(mimeType)) {
|
||||
container.appendChild(createFile(url, 'music'));
|
||||
} else if (/^video\//.test(mimeType)) {
|
||||
container.appendChild(createFile(url, 'video'));
|
||||
@ -61,30 +72,50 @@ export function appendMedia(container, mimeType, url) {
|
||||
};
|
||||
|
||||
const MaxAttachmentSize = {
|
||||
limit: 2 * 1024 * 1024,
|
||||
text: '2MB'
|
||||
limit: 1_258_291,
|
||||
text: '1.2MB'
|
||||
};
|
||||
|
||||
export const fileSupported = [
|
||||
'.amr',
|
||||
'.ogv',
|
||||
'application/msword',
|
||||
'application/vnd.ms-word',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'application/vnd.ms-powerpoint',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'application/pdf',
|
||||
'audio/aac',
|
||||
'audio/amr',
|
||||
'audio/mp3',
|
||||
'audio/mpeg',
|
||||
'audio/x-mpeg',
|
||||
'audio/amr',
|
||||
'.amr',
|
||||
'audio/ogg',
|
||||
'audio/opus',
|
||||
'audio/wav',
|
||||
'audio/webm',
|
||||
'image/bmp',
|
||||
'image/gif',
|
||||
'image/jpeg',
|
||||
'image/jfif',
|
||||
'image/png',
|
||||
'image/tiff',
|
||||
'image/webp',
|
||||
'text/plain',
|
||||
'text/vcard',
|
||||
'text/x-vcard',
|
||||
'video/3gpp',
|
||||
'video/mp2t',
|
||||
'video/mp4',
|
||||
'video/mpeg',
|
||||
'video/x-mpeg',
|
||||
'video/quicktime',
|
||||
'video/webm',
|
||||
'video/quicktime'
|
||||
];
|
||||
|
||||
export function insertFile(container, file) {
|
||||
export function insertFile(container, file, r) {
|
||||
const label = container.querySelector('.file-selector>.selector-name');
|
||||
if (label != null && file != null) {
|
||||
let type = file.type;
|
||||
@ -93,12 +124,12 @@ export function insertFile(container, file) {
|
||||
type = type.substring(type.lastIndexOf('.'));
|
||||
}
|
||||
if (fileSupported.indexOf(type) < 0) {
|
||||
showAlert(r('error', 'Error'), r('notSupported', 'File type "{type}" is now not supported.').replace('{type}', type));
|
||||
showAlert(r('P_WO_ERROR', 'Error'), r('P_CU_TYPENOTSUPPORTED', 'File type "{type}" is now not supported.').replace('{type}', type));
|
||||
return;
|
||||
}
|
||||
const isImage = /^image\//.test(type);
|
||||
if (!isImage && file.size > MaxAttachmentSize.limit) {
|
||||
showAlert(r('error', 'Error'), r('fileTooLarge', `File is too large. (> ${MaxAttachmentSize.text})`), 'warn');
|
||||
showAlert(r('P_WO_ERROR', 'Error'), r('P_WO_ATTACHMENTSIZEEXCEEDSTHEMAXIMUMTIPS', `Attachment size exceeds the maximum allowed to be sent (${MaxAttachmentSize.text})`), 'warn');
|
||||
return;
|
||||
}
|
||||
const fn = file.name;
|
||||
|
Reference in New Issue
Block a user