113 lines
4.4 KiB
HTML
113 lines
4.4 KiB
HTML
|
<!doctype html>
|
||
|
<input type="file" id="-eeprom-file"/> <button id="-eeprom-abort">Abort</button> <progress id="-eeprom-progress" min="0" max="100" value="0"></progress> <span id="-eeprom-progress-done"></span> <span id="-eeprom-progress-total"></span><br/>
|
||
|
<div id="-eeprom-history"></div>
|
||
|
<script src="/js/eeprom-v1.0.js" type="text/javascript"></script>
|
||
|
<script type="text/javascript">
|
||
|
var eFile = document.getElementById('-eeprom-file'),
|
||
|
eAbort = document.getElementById('-eeprom-abort'),
|
||
|
eProgress = document.getElementById('-eeprom-progress'),
|
||
|
eProgressD = document.getElementById('-eeprom-progress-done'),
|
||
|
eProgressT = document.getElementById('-eeprom-progress-total'),
|
||
|
eHistory = document.getElementById('-eeprom-history'),
|
||
|
eTask = undefined;
|
||
|
|
||
|
eAbort.onclick = function() {
|
||
|
if(eTask)
|
||
|
eTask.abort();
|
||
|
};
|
||
|
|
||
|
var eClient = new EEPROM(1, '/uploads', 'Misuzu :cookie');
|
||
|
|
||
|
eFile.onchange = function() {
|
||
|
var task = eTask = eClient.createUpload(this.files[0]);
|
||
|
|
||
|
task.onProgress = function(progressInfo) {
|
||
|
eProgress.value = progressInfo.progress;
|
||
|
eProgressD.textContent = progressInfo.loaded;
|
||
|
eProgressT.textContent = progressInfo.total;
|
||
|
};
|
||
|
|
||
|
task.onFailure = function(errorInfo) {
|
||
|
if(!errorInfo.userAborted) {
|
||
|
var 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 {
|
||
|
var _t = ['bytes', 'KB', 'MB', 'GB', 'TB'],
|
||
|
_i = parseInt(Math.floor(Math.log(errorInfo.maxSize) / Math.log(1024))),
|
||
|
_s = Math.round(errorInfo.maxSize / Math.pow(1024, _i), 2);
|
||
|
|
||
|
errorText = 'Upload may not be larger than %1 %2.'.replace('%1', _s).replace('%2', _t[_i]);
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
alert(errorText);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
task.onComplete = function(fileInfo) {
|
||
|
eTask = undefined;
|
||
|
|
||
|
var elem = document.createElement('div');
|
||
|
elem.id = fileInfo.id;
|
||
|
|
||
|
var link = document.createElement('a');
|
||
|
link.textContent = fileInfo.id;
|
||
|
link.href = fileInfo.url;
|
||
|
link.target = '_blank';
|
||
|
elem.appendChild(link);
|
||
|
|
||
|
elem.appendChild(document.createTextNode(' '));
|
||
|
|
||
|
var del = document.createElement('button');
|
||
|
del.textContent = 'Delete';
|
||
|
del.onclick = function() {
|
||
|
var dTask = eClient.deleteUpload(fileInfo);
|
||
|
|
||
|
dTask.onFailure = function(reason) {
|
||
|
alert('Delete failed: ' + reason);
|
||
|
};
|
||
|
|
||
|
dTask.onSuccess = function() {
|
||
|
eHistory.removeChild(elem);
|
||
|
};
|
||
|
|
||
|
dTask.start();
|
||
|
};
|
||
|
elem.appendChild(del);
|
||
|
|
||
|
elem.appendChild(document.createTextNode(' '));
|
||
|
|
||
|
var json = document.createElement('code');
|
||
|
json.textContent = JSON.stringify(fileInfo);
|
||
|
elem.appendChild(json);
|
||
|
|
||
|
eHistory.appendChild(elem);
|
||
|
};
|
||
|
|
||
|
task.start();
|
||
|
};
|
||
|
</script>
|