Updated to new EEPROM script.
This commit is contained in:
parent
eb81ed7a82
commit
fe77f1616c
4 changed files with 48 additions and 69 deletions
|
@ -19,7 +19,7 @@ const MszEEPROM = (() => {
|
||||||
const scriptElem = $e({
|
const scriptElem = $e({
|
||||||
tag: 'script',
|
tag: 'script',
|
||||||
attrs: {
|
attrs: {
|
||||||
src: `${peepPath}/eeprom.js`,
|
src: `${peepPath}/scripts/eepromv1a.js`,
|
||||||
charset: 'utf-8',
|
charset: 'utf-8',
|
||||||
type: 'text/javascript',
|
type: 'text/javascript',
|
||||||
onerror: () => reject(),
|
onerror: () => reject(),
|
||||||
|
|
|
@ -22,10 +22,10 @@ const MszForumEditor = function(form) {
|
||||||
MszEEPROM.init()
|
MszEEPROM.init()
|
||||||
.catch(() => console.error('Failed to initialise EEPROM'))
|
.catch(() => console.error('Failed to initialise EEPROM'))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const eepromClient = new EEPROM(peepApp, `${peepPath}/uploads`, '');
|
const eepromClient = new EEPROM(peepApp, peepPath);
|
||||||
const eepromHistory = <div class="eeprom-widget-history-items"/>;
|
const eepromHistory = <div class="eeprom-widget-history-items"/>;
|
||||||
|
|
||||||
const eepromHandleFileUpload = file => {
|
const eepromHandleFileUpload = async file => {
|
||||||
const uploadElemNameValue = <div class="eeprom-widget-file-name-value" title={file.name}>{file.name}</div>;
|
const uploadElemNameValue = <div class="eeprom-widget-file-name-value" title={file.name}>{file.name}</div>;
|
||||||
const uploadElemName = <a class="eeprom-widget-file-name" target="_blank">{uploadElemNameValue}</a>;
|
const uploadElemName = <a class="eeprom-widget-file-name" target="_blank">{uploadElemNameValue}</a>;
|
||||||
const uploadElemProgressText = <div class="eeprom-widget-file-progress">Please wait...</div>;
|
const uploadElemProgressText = <div class="eeprom-widget-file-progress">Please wait...</div>;
|
||||||
|
@ -46,62 +46,22 @@ const MszForumEditor = function(form) {
|
||||||
eepromHistory.appendChild(uploadElem);
|
eepromHistory.appendChild(uploadElem);
|
||||||
|
|
||||||
const explodeUploadElem = () => $r(uploadElem);
|
const explodeUploadElem = () => $r(uploadElem);
|
||||||
const uploadTask = eepromClient.createUpload(file);
|
const uploadTask = eepromClient.create(file);
|
||||||
|
|
||||||
uploadTask.onProgress = function(progressInfo) {
|
uploadTask.onProgress(prog => {
|
||||||
const progressValue = `${progressInfo.progress}%`;
|
const progress = `}%`;
|
||||||
uploadElemProgressBarValue.style.width = progressValue;
|
uploadElemProgressBarValue.style.width = `${Math.ceil(prog.progress * 100)}%`;
|
||||||
uploadElemProgressText.textContent = `${progressValue} (${progressInfo.total - progressInfo.loaded} bytes remaining)`;
|
uploadElemProgressText.textContent = `${prog.progress.toLocaleString(undefined, { style: 'percent' })} (${prog.total - prog.loaded} bytes remaining)`;
|
||||||
};
|
});
|
||||||
|
|
||||||
uploadTask.onFailure = function(errorInfo) {
|
try {
|
||||||
if(!errorInfo.userAborted) {
|
const fileInfo = await uploadTask.start();
|
||||||
let errorText = 'Was unable to upload file.';
|
|
||||||
|
|
||||||
switch(errorInfo.error) {
|
|
||||||
case EEPROM.ERR_INVALID:
|
|
||||||
errorText = 'Upload request was invalid.';
|
|
||||||
break;
|
|
||||||
case EEPROM.ERR_AUTH:
|
|
||||||
errorText = 'Upload authentication failed, refresh and try again.';
|
|
||||||
break;
|
|
||||||
case EEPROM.ERR_ACCESS:
|
|
||||||
errorText = "You're not allowed to upload files.";
|
|
||||||
break;
|
|
||||||
case EEPROM.ERR_GONE:
|
|
||||||
errorText = 'Upload client has a configuration error or the server is gone.';
|
|
||||||
break;
|
|
||||||
case EEPROM.ERR_DMCA:
|
|
||||||
errorText = 'This file has been uploaded before and was removed for copyright reasons, you cannot upload this file.';
|
|
||||||
break;
|
|
||||||
case EEPROM.ERR_SERVER:
|
|
||||||
errorText = 'Upload server returned a critical error, try again later.';
|
|
||||||
break;
|
|
||||||
case EEPROM.ERR_SIZE:
|
|
||||||
if(errorInfo.maxSize < 1)
|
|
||||||
errorText = 'Selected file is too large.';
|
|
||||||
else {
|
|
||||||
const types = ['bytes', 'KB', 'MB', 'GB', 'TB'],
|
|
||||||
typeIndex = parseInt(Math.floor(Math.log(errorInfo.maxSize) / Math.log(1024))),
|
|
||||||
number = Math.round(errorInfo.maxSize / Math.pow(1024, _i), 2);
|
|
||||||
|
|
||||||
errorText = `Upload may not be larger than ${number} ${types[typeIndex]}.`;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadElem.classList.add('eeprom-widget-file-fail');
|
|
||||||
uploadElemProgressText.textContent = errorText;
|
|
||||||
MszShowMessageBox(errorText, 'Upload Error');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
uploadTask.onComplete = function(fileInfo) {
|
|
||||||
uploadElem.classList.add('eeprom-widget-file-done');
|
uploadElem.classList.add('eeprom-widget-file-done');
|
||||||
uploadElemName.href = fileInfo.url;
|
uploadElemName.href = fileInfo.url;
|
||||||
uploadElemProgressText.textContent = '';
|
uploadElemProgressText.textContent = '';
|
||||||
|
|
||||||
const insertTheLinkIntoTheBoxEx2 = function() {
|
const insertTheLinkIntoTheBoxEx2 = () => {
|
||||||
const parserMode = parseInt(parserElem.value);
|
const parserMode = parseInt(parserElem.value);
|
||||||
let insertText = location.protocol + fileInfo.url;
|
let insertText = location.protocol + fileInfo.url;
|
||||||
|
|
||||||
|
@ -124,14 +84,27 @@ const MszForumEditor = function(form) {
|
||||||
uploadElemProgressText.appendChild(<a href="javascript:void(0)" onclick={() => insertTheLinkIntoTheBoxEx2()}>Insert</a>);
|
uploadElemProgressText.appendChild(<a href="javascript:void(0)" onclick={() => insertTheLinkIntoTheBoxEx2()}>Insert</a>);
|
||||||
uploadElemProgressText.appendChild($t(' '));
|
uploadElemProgressText.appendChild($t(' '));
|
||||||
uploadElemProgressText.appendChild(<a href="javascript:void(0)" onclick={() => {
|
uploadElemProgressText.appendChild(<a href="javascript:void(0)" onclick={() => {
|
||||||
eepromClient.deleteUpload(fileInfo).start();
|
eepromClient.delete(fileInfo)
|
||||||
explodeUploadElem();
|
.then(() => explodeUploadElem())
|
||||||
|
.catch(ex => {
|
||||||
|
console.error(ex);
|
||||||
|
MszShowMessageBox(ex, 'Upload Error');
|
||||||
|
});
|
||||||
}}>Delete</a>);
|
}}>Delete</a>);
|
||||||
|
|
||||||
insertTheLinkIntoTheBoxEx2();
|
insertTheLinkIntoTheBoxEx2();
|
||||||
};
|
} catch(ex) {
|
||||||
|
let errorText = 'Upload aborted.';
|
||||||
|
|
||||||
uploadTask.start();
|
if(!ex.aborted) {
|
||||||
|
console.error(ex);
|
||||||
|
errorText = ex.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadElem.classList.add('eeprom-widget-file-fail');
|
||||||
|
uploadElemProgressText.textContent = errorText;
|
||||||
|
await MszShowMessageBox(errorText, 'Upload Error');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const eepromFormInput = <input type="file" multiple={true} class="eeprom-widget-form-input"
|
const eepromFormInput = <input type="file" multiple={true} class="eeprom-widget-form-input"
|
||||||
|
|
|
@ -67,16 +67,12 @@ const MszMessagesReply = function(element) {
|
||||||
MszEEPROM.init()
|
MszEEPROM.init()
|
||||||
.catch(() => console.error('Failed to initialise EEPROM'))
|
.catch(() => console.error('Failed to initialise EEPROM'))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const eepromClient = new EEPROM(peepApp, `${peepPath}/uploads`, '');
|
const eepromClient = new EEPROM(peepApp, peepPath);
|
||||||
const eepromHandleFileUpload = file => {
|
const eepromHandleFileUpload = async file => {
|
||||||
const uploadTask = eepromClient.createUpload(file);
|
const uploadTask = eepromClient.create(file);
|
||||||
|
|
||||||
uploadTask.onFailure = errorInfo => {
|
try {
|
||||||
if(!errorInfo.userAborted)
|
const fileInfo = await uploadTask.start();
|
||||||
MszShowMessageBox('Was unable to upload file.', 'Upload Error');
|
|
||||||
};
|
|
||||||
|
|
||||||
uploadTask.onComplete = fileInfo => {
|
|
||||||
const parserMode = parseInt(parserSelect.value);
|
const parserMode = parseInt(parserSelect.value);
|
||||||
let insertText = location.protocol + fileInfo.url;
|
let insertText = location.protocol + fileInfo.url;
|
||||||
|
|
||||||
|
@ -94,9 +90,16 @@ const MszMessagesReply = function(element) {
|
||||||
|
|
||||||
$insertTags(bodyElem, insertText, '');
|
$insertTags(bodyElem, insertText, '');
|
||||||
bodyElem.value = bodyElem.value.trim();
|
bodyElem.value = bodyElem.value.trim();
|
||||||
};
|
} catch(ex) {
|
||||||
|
let errorText = 'Upload aborted.';
|
||||||
|
|
||||||
uploadTask.start();
|
if(!ex.aborted) {
|
||||||
|
console.error(ex);
|
||||||
|
errorText = ex.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
await MszShowMessageBox(errorText, 'Upload Error');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bodyElem.addEventListener('paste', ev => {
|
bodyElem.addEventListener('paste', ev => {
|
||||||
|
|
|
@ -12,8 +12,11 @@ const MszShowConfirmBox = async (text, title, target) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const MszShowMessageBox = (text, title, buttons, target) => {
|
const MszShowMessageBox = (text, title, buttons, target) => {
|
||||||
if(typeof text !== 'string')
|
if(typeof text !== 'string') {
|
||||||
throw 'text must be a string';
|
if(text !== undefined && text !== null && typeof text.toString === 'function')
|
||||||
|
text = text.toString();
|
||||||
|
else throw 'text must be a string';
|
||||||
|
}
|
||||||
if(!(target instanceof Element))
|
if(!(target instanceof Element))
|
||||||
target = document.body;
|
target = document.body;
|
||||||
|
|
||||||
|
|
Reference in a new issue