diff --git a/app/src/main/assets/web/uploadBook/js/common.js b/app/src/main/assets/web/uploadBook/js/common.js
index 6ba1fe6cf..4b9674445 100644
--- a/app/src/main/assets/web/uploadBook/js/common.js
+++ b/app/src/main/assets/web/uploadBook/js/common.js
@@ -4,87 +4,85 @@
//全局的配置文件
var config = {
- fileTypes : "txt|epub|umd", //允许上传的文件格式 "txt|epub" // |doc|docx|wps|xls|xlsx|et|ppt|pptx|dps
+ fileTypes: "txt|epub|umd", //允许上传的文件格式 "txt|epub" // |doc|docx|wps|xls|xlsx|et|ppt|pptx|dps
//url : "http://"+location.host+"?action=addBook",//"http://localhost/t/post.php",//
- url: "http://192.168.1.16:1122/addLocalBook",
- fileLimitSize : 500 * 1024 *1024
+ url: "../addLocalBook",
+ fileLimitSize: 500 * 1024 * 1024
}
var file = {
- "inQueue" : [], //已经在队列里面的文件,包括 HTML5上传和 Flash上传的
- "clientHaveFiles" : [] // 客户端已经存在的文件列表
+ "inQueue": [], //已经在队列里面的文件,包括 HTML5上传和 Flash上传的
+ "clientHaveFiles": [] // 客户端已经存在的文件列表
}
/**
* HTML5 和 flash 公用,所有文件对象集合
* @var array
*/
-var filesUpload = []; //
+var filesUpload = []; //
$.ajax({
- url : "http://"+location.host+'?action=getBooksList&t='+(+new Date()),//"http://localhost/t/t.php",//
- async:false,//同步获取数据
- dataType : "json",
- success:function(data){
-
- try{
+ url: "http://" + location.host + '?action=getBooksList&t=' + (+new Date()),//"http://localhost/t/t.php",//
+ async: false,//同步获取数据
+ dataType: "json",
+ success: function (data) {
+
+ try {
var dataLen = data.length;
- if(dataLen > 0 ){
- for(var i=0; i < dataLen; i++){
- filesUpload.push(data[i]);
+ if (dataLen > 0) {
+ for (var i = 0; i < dataLen; i++) {
+ filesUpload.push(data[i]);
}
}
- }catch(e){}
-
+ } catch (e) { }
+
}
})
//统计文件大小
-function countFileSize(fileSize)
-{
- var KB = 1024;
+function countFileSize(fileSize) {
+ var KB = 1024;
var MB = 1024 * 1024;
- if(KB >= fileSize){
- return fileSize+"B";
- }else if(MB >= fileSize){
- return (fileSize/KB).toFixed(2)+"KB";
- }else{
- return (fileSize/MB).toFixed(2)+"MB";
+ if (KB >= fileSize) {
+ return fileSize + "B";
+ } else if (MB >= fileSize) {
+ return (fileSize / KB).toFixed(2) + "KB";
+ } else {
+ return (fileSize / MB).toFixed(2) + "MB";
}
}
//如果文件太长进行截取
-function substr_string(name)
-{
+function substr_string(name) {
var maxLen = 15;
var len = name.length;
- if(len < 17 )return name;
-
+ if (len < 17) return name;
+
var lastIndex = name.lastIndexOf(".");
- var suffix = name.substr(lastIndex);
- var pre = name.substr(0,lastIndex);
- var preLen = pre.length;
- var preStart = preLen - 10;
+ var suffix = name.substr(lastIndex);
+ var pre = name.substr(0, lastIndex);
+ var preLen = pre.length;
+ var preStart = preLen - 10;
//前面10个 + 后面5个
- var fileName = pre.substr(0,10) + "...." + pre.substr( preStart > 4 ? -4 : -preStart , 4)+suffix;
+ var fileName = pre.substr(0, 10) + "...." + pre.substr(preStart > 4 ? -4 : -preStart, 4) + suffix;
return fileName
}
function checkFile(file) {
-
- if(file.size > config.fileLimitSize){
+
+ if (file.size > config.fileLimitSize) {
return jsonLang.t11;
}
-
- if (!file.name || !file.name.toLowerCase().match('('+config.fileTypes+')$')) {
+
+ if (!file.name || !file.name.toLowerCase().match('(' + config.fileTypes + ')$')) {
return jsonLang.t12;
}
-
+
var len = filesUpload.length;
- for(var i=0; i< len; i++){
- if(filesUpload[i].name == file.name) {
+ for (var i = 0; i < len; i++) {
+ if (filesUpload[i].name == file.name) {
return jsonLang.t13;
}
}
@@ -101,34 +99,32 @@ function checkFile(file) {
* @param object file 文件对象
* @param int type 0 是swf 上传的,1 是html5上传的
*/
-function fileQueued(file, type)
-{
- var size=0 ,fid=file.id, name="";
+function fileQueued(file, type) {
+ var size = 0, fid = file.id, name = "";
type = type || 0;
-
- if(file != undefined )
- {
+
+ if (file != undefined) {
//计算文件大小 单位MB
size = countFileSize(file.size);
name = substr_string(file.name)
//创建要插入的元素
-// "
"+name+""+
-// " "+
-// " "+
-// " | "+size+" | |
";
-
- var HTML = ''+
- ''+
- '- '+name+'
'+
- '- '+size+'
'+
- '- '+
- '0% '+jsonLang.t9+'
'+
- '
'+
- ''+
+ // ""+name+""+
+ // " "+
+ // " "+
+ // " | "+size+" | |
";
+
+ var HTML = '' +
+ '' +
+ '- ' + name + '
' +
+ '- ' + size + '
' +
+ '- ' +
+ '0% ' + jsonLang.t9 + '
' +
+ '
' +
+ '' +
'';
-
-
+
+
jQuery("#tableStyle").append(HTML);
//保存falsh_id,为上传做准备
//global_flash_id.push(file.id);
@@ -137,55 +133,51 @@ function fileQueued(file, type)
}
}
-function changeTrBackGroundColor()
-{
- var getTr=document.getElementById("tableStyle").getElementsByTagName("dl");
- trNum=getTr.length;
- for(var i=0;i"+jsonLang.t10+"")
+function uploadSuccess(file, serverData, res) {
+ var id = "handle_button_" + file.id;
+ $("#" + id).replaceWith("" + jsonLang.t10 + "")
}
//取消上传
-function userCancelUpload(file_id, type)
-{
-
- if(type==0){
+function userCancelUpload(file_id, type) {
+
+ if (type == 0) {
SWFFuns.cancelUpload(file_id);
- }else{
+ } else {
HTML5Funs.cancelUpload(file_id);
}
-
- $("#handle_button_"+file_id).html(jsonLang.t14).removeClass("orange").addClass("gray");
+
+ $("#handle_button_" + file_id).html(jsonLang.t14).removeClass("orange").addClass("gray");
//如果已经上传一部分了
- if($("#progress_bar_p_"+file_id).hasClass("orange")){
- $("#progress_bar_p_"+file_id).removeClass("orange");
- $("#progress_bar_p_"+file_id).addClass("gray");
- }
+ if ($("#progress_bar_p_" + file_id).hasClass("orange")) {
+ $("#progress_bar_p_" + file_id).removeClass("orange");
+ $("#progress_bar_p_" + file_id).addClass("gray");
+ }
}
@@ -193,14 +185,14 @@ function userCancelUpload(file_id, type)
* 通过文件名称 从全局的文件列表中获取文件对象
*
*/
-function getFileFomeFilesUpload(filename){
+function getFileFomeFilesUpload(filename) {
var len = filesUpload.length;
- for(var i=0; i < len; i++){
- if(filesUpload[i].name == filename){
+ for (var i = 0; i < len; i++) {
+ if (filesUpload[i].name == filename) {
return filesUpload[i];
}
}
-
+
return null;
}
@@ -208,42 +200,42 @@ function getFileFomeFilesUpload(filename){
/**
* 往全局的 上传列表添加一个数据
*/
-function addFileToFilesUpload(file){
-
- if(typeof file == "string"){
- filesUpload.push({"name":file})
+function addFileToFilesUpload(file) {
+
+ if (typeof file == "string") {
+ filesUpload.push({ "name": file })
return true;
- }else if(typeof file == "object"){
+ } else if (typeof file == "object") {
filesUpload.push(file);
return true;
}
-
+
return false;
}
/**
* 往全局的 上传列表添加一个数据
*/
-function updateFileToFilesUpload(file){
-
+function updateFileToFilesUpload(file) {
+
var len = filesUpload.length;
- for(var i=0; i < len; i++){
- if(filesUpload[i].name == file.name){
+ for (var i = 0; i < len; i++) {
+ if (filesUpload[i].name == file.name) {
filesUpload[i] = file;
return true;
}
}
-
+
return false;
}
/**
* 查找在数组中的位置
*/
-function findObjectKey (object, fid){
- var len = object.length;
- for(var i=0; i -1)
- files.splice(filesUploadKey, 1);
-
+ if (filesUploadKey > -1)
+ files.splice(filesUploadKey, 1);
+
return files;
}
\ No newline at end of file
diff --git a/app/src/main/assets/web/uploadBook/js/html5_fun.js b/app/src/main/assets/web/uploadBook/js/html5_fun.js
index 6ef0f2944..806dadc4a 100644
--- a/app/src/main/assets/web/uploadBook/js/html5_fun.js
+++ b/app/src/main/assets/web/uploadBook/js/html5_fun.js
@@ -1,115 +1,115 @@
/**
* 处理拖拽上传
*/
- var isDragOver = false;//拖拽触发点
- var fileNumber = -1; //上传文件编号
- var fileNumberPex = "zyFileUpload_"; //编号前缀
- var currUploadfile = {}; //当前上传的文件对象
-
- var uploadQueue = [];//上传队列集合
- var isUploading = false;//是否正在上传
-
- var XHR
- try{
- XHR = new XMLHttpRequest();
- }catch(e){}
-
-(function(isSupportFileUpload){
-
+var isDragOver = false;//拖拽触发点
+var fileNumber = -1; //上传文件编号
+var fileNumberPex = "zyFileUpload_"; //编号前缀
+var currUploadfile = {}; //当前上传的文件对象
+
+var uploadQueue = [];//上传队列集合
+var isUploading = false;//是否正在上传
+
+var XHR
+try {
+ XHR = new XMLHttpRequest();
+} catch (e) { }
+
+(function (isSupportFileUpload) {
+
//不支持拖拽上传,或者 不支持FormData ,显示WiFi表示
- if(!isSupportFileUpload){
+ if (!isSupportFileUpload) {
$("#drag_area").addClass("wf_wifi");
$("#drag_area h3").html("");
return;
- //更换样式
- }else{
+ //更换样式
+ } else {
$("#drag_area").addClass("wf_normal");
}
-
-
+
+
addEvent();
-
+
/**
* 添加事件
*/
- function addEvent(){
+ function addEvent() {
var dropArea = $('#drag_area h3')[0];
dropArea.addEventListener('dragover', handleDragOver, false);
dropArea.addEventListener('dragleave', handleDragLeave, false);
dropArea.addEventListener('drop', handleDrop, false);
- }
+ }
/**
* 松开拖拽文件的处理,进行上传
*/
- function handleDrop(evt){
-
+ function handleDrop(evt) {
+
evt.stopPropagation();
evt.preventDefault();
$('#drag_area').addClass('wf_normal').removeClass('wf_active');
-
+
console.log("Drop");
isDragOver = false;
-
- var file={};
+
+ var file = {};
var errorMsgs = [];
var len = evt.dataTransfer.files.length;
-
- for(var i=0; i < len; i++){
- fileNumber ++ ;
+
+ for (var i = 0; i < len; i++) {
+ fileNumber++;
file = evt.dataTransfer.files[i];
- file.id = fileNumberPex+fileNumber;
-
+ file.id = fileNumberPex + fileNumber;
+
//检测文件
msg = checkFile(file)
//文件可以通过
- if(!msg){
+ if (!msg) {
//添加全局
filesUpload.push(file);
//添加上传队列
uploadQueue.push(file);
//在页面进行展示
fileQueued(file, 1);
- }else{
+ } else {
errorMsgs.push(msg)
}
}
-
- if(errorMsgs.length>0){
+
+ if (errorMsgs.length > 0) {
//只选择做一个进行上传
- if(len==1){
+ if (len == 1) {
alert(errorMsgs[0]);
-
- }else{
- a1=len;
- a2=len - errorMsgs.length;
- var replaceArr = new Array(a1,a2);
- alert(stringReplace(jsonLang.t7,replaceArr));
+ } else {
+ a1 = len;
+ a2 = len - errorMsgs.length;
+
+ var replaceArr = new Array(a1, a2);
+ alert(stringReplace(jsonLang.t7, replaceArr));
}
}
-
+
//拿出第一个,进行上传
- if(!isUploading && uploadQueue.length>0) uploadFiles(uploadQueue.shift());
+ if (!isUploading && uploadQueue.length > 0) uploadFiles(uploadQueue.shift());
}
-
- function handleDragOver(evt){
-
+
+ function handleDragOver(evt) {
+
evt.stopPropagation();
evt.preventDefault();
//防止多次DOM操作
if (!isDragOver) {
console.log("Over");
- $('#drag_area').addClass('wf_active').removeClass('wf_normal');
+ $('#drag_area').addClass('wf_active').removeClass('wf_normal');
isDragOver = true;
}
-
-
+
+
}
-
- function handleDragLeave(evt){
-
+
+ function handleDragLeave(evt) {
+
console.log("DragLeave");
evt.stopPropagation();
evt.preventDefault();
@@ -119,7 +119,7 @@
- function uploadFiles(file){
+ function uploadFiles(file) {
//正在上传
isUploading = true;
//设置上传的数据
@@ -129,10 +129,10 @@
fd.append("Upload", "Submit Query");
//设置当前的上传对象
currUploadfile = file;
- if(XHR.readyState>0){
- XHR = new XMLHttpRequest();
+ if (XHR.readyState > 0) {
+ XHR = new XMLHttpRequest();
}
-
+
XHR.upload.addEventListener("progress", progress, false);
XHR.upload.addEventListener("load", requestLoad, false);
XHR.upload.addEventListener("error", error, false);
@@ -140,105 +140,105 @@
XHR.upload.addEventListener("loadend", loadend, false);
XHR.upload.addEventListener("loadstart", loadstart, false);
XHR.open("POST", config.url);
- XHR.setRequestHeader("Content-Type","application/octet-stream");
+ XHR.setRequestHeader("Content-Type", "multipart/mixed stream");
XHR.send(fd);
- XHR.onreadystatechange = function() {
-
+ XHR.onreadystatechange = function () {
+
//只要上传完成不管成功失败
- if (XHR.readyState == 4 ){
- console.log("onreadystatechange " , XHR.status, +new Date());
-
- if(XHR.status == 200){
+ if (XHR.readyState == 4) {
+ console.log("onreadystatechange ", XHR.status, +new Date());
+
+ if (XHR.status == 200) {
uploadSuccess(currUploadfile, {}, XHR.status)
- }else{
+ } else {
uploadError()
}
-
+
//进行下一个上传
nextUpload()
}
};
-
+
}
//请求完成,无论失败或成功
- function loadend(evt){
- console.log("loadend",+new Date(),evt);
+ function loadend(evt) {
+ console.log("loadend", +new Date(), evt);
}
//请求开始
- function loadstart(evt){
- console.log("loadstart",evt);
+ function loadstart(evt) {
+ console.log("loadstart", evt);
}
-
+
//在请求发送或接收数据期间,在服务器指定的时间间隔触发。
- function progress(evt){
- uploadProgress(currUploadfile, evt.loaded || evt.position , evt.total)
+ function progress(evt) {
+ uploadProgress(currUploadfile, evt.loaded || evt.position, evt.total)
}
-
+
//在请求被取消时触发,例如,在调用 abort() 方法时。
- function abort(evt){
- console.log("abort",evt);
+ function abort(evt) {
+ console.log("abort", evt);
}
-
+
//在请求失败时触发。
- function error(evt){
+ function error(evt) {
//终止ajax请求
XHR.abort();
uploadError()
nextUpload();
}
-
+
//在请求成功完成时触发。
- function requestLoad(evt){
- console.log("requestLoad", +new Date(),evt);
+ function requestLoad(evt) {
+ console.log("requestLoad", +new Date(), evt);
}
-
+
//进行下一个上传
- function nextUpload(){
+ function nextUpload() {
isUploading = false;
- if(uploadQueue.length>0){
- uploadFiles(uploadQueue.shift());
- }else{
- //米有正在上传的了
- currUploadfile = {}
+ if (uploadQueue.length > 0) {
+ uploadFiles(uploadQueue.shift());
+ } else {
+ //米有正在上传的了
+ currUploadfile = {}
}
}
-
+
//上传出错误了,比如断网,
- function uploadError(){
+ function uploadError() {
//移除全局变量中的,上传出错的
removeFileFromFilesUpload(filesUpload, currUploadfile.id)
var file = currUploadfile;
- $("#handle_button_"+file.id).replaceWith(""+jsonLang.t8+"")
+ $("#handle_button_" + file.id).replaceWith("" + jsonLang.t8 + "")
}
-
-
+
+
//对外部注册的函数
var HTML5Funs = {
/**
* 取消上传
* @param string fid 文件的Id
*/
- cancelUpload : function(fid){
-
+ cancelUpload: function (fid) {
+
var filesUploadKey = -1;
var uploadQueueKey = -1;
-
-
+
+
//从全局中删除文件
removeFileFromFilesUpload(filesUpload, fid)
-
+
//如果是正在上传的,AJAX取消
- if(currUploadfile.id == fid){
+ if (currUploadfile.id == fid) {
XHR.abort();
- }else{
+ } else {
//从上传队列中移除
removeFileFromFilesUpload(uploadQueue, fid)
}
}
}
-
+
window.HTML5Funs = HTML5Funs;
-
+
})("FormData" in window && "ondrop" in document.body)
\ No newline at end of file
diff --git a/app/src/main/assets/web/uploadBook/js/langSwich.js b/app/src/main/assets/web/uploadBook/js/langSwich.js
index a313747bf..b3b5a749a 100644
--- a/app/src/main/assets/web/uploadBook/js/langSwich.js
+++ b/app/src/main/assets/web/uploadBook/js/langSwich.js
@@ -3,86 +3,87 @@
* 切换语言环境 addby zhongweikang@zhangyue.com 2015/09/23
*/
- var language;//当前语言
- var jsonEn;//英文
- var jsonZh;//中文
-
- /**
- * 语言包
- */
- jsonEn = { t0:"WiFi Upload",t1:"Documents",t2:"Name",t3:"Size",t4:"Operation",
- t5:"Supported Format:TXT、EPUB、UMD",t6:"Drag here and Drop to upload",
- t7:"You choosed [txt] files ,we only can upload [txt] of them。\nPlease choose TXT、EPUB、UMD files, file name cannot be repeated.",
- t8:"Failed",t9:"Cancel",t10:"Done",t11:"One of books is over 500MB",t12:"Bad file mode",
- t13:"File already exists",t14:"Canceled"
- };
- jsonZh = { t0:"WiFi 下载",t1:"文档",t2:"名字",t3:"大小",t4:"操作",
- t5:"支持类型:TXT、EPUB、UMD",t6:"拖至此处上传",
- t7:"你选择了[txt]个文件,我们只能上传其中的[txt]。\n请选择 TXT、EPUB、UMD 类型的文件,文件的名字不能重复。",
- t8:"失败",t9:"取消",t10:"完成",t11:"上传文件不能大于500MB",t12:"无效的文件格式",
- t13:"文件已存在",t14:"已取消"
- };
-
- if (navigator.language) {
- language = navigator.language;
- }
- else {
- language = navigator.browserLanguage;
- }
- language = language.toLowerCase(language);
-
- /**
- * 切换语言
- */
- function langSwich(s){
- switch(s){
- case 'en-us':
- _strReplace(jsonEn);
- break;
- case 'zh-cn':
- _strReplace(jsonZh);
- break;
- default:
- _strReplace(jsonEn);
- break;
- }
- }
- function _strReplace(d){
- window.jsonLang=d;//全局变量在其他js文件中会遇到,勿删。
- for(var i in jsonLang){
- $('[data-js=' + i + ']').html(d[i])
- }
- }
-
- /**
- * 特殊字符串替换,例:语言包中的 t7
- * content 替换前的文本
- * replace 待插入的文本 (支持变量或数组)
- */
- var isArray = function(obj) {
- return Object.prototype.toString.call(obj) === '[object Array]';
- }
- function stringReplace(content,replace){
-
- var str = content;
- if(!str){return null;}
-
- if(isArray(replace)){
- strs=str.split("[txt]");
- count = strs.length-1;
-
- var string = '';
- for(var i=0;i"},*/
- file_size_limit : config.fileLimitSize+" B",
- file_types : "*."+config.fileTypes.split("|").join(";*."),
-
- file_types_description : "All Files",
- file_upload_limit : 1000, //配置上传个数
- file_queue_limit : 0,
- custom_settings : {
- progressTarget : "fsUploadProgress",
- cancelButtonId : "btnCancel"
+ file_size_limit: config.fileLimitSize + " B",
+ file_types: "*." + config.fileTypes.split("|").join(";*."),
+
+ file_types_description: "All Files",
+ file_upload_limit: 1000, //配置上传个数
+ file_queue_limit: 0,
+ custom_settings: {
+ progressTarget: "fsUploadProgress",
+ cancelButtonId: "btnCancel"
},
debug: 0,
- button_cursor:SWFUpload.CURSOR.HAND,
+ button_cursor: SWFUpload.CURSOR.HAND,
button_image_url: "i/wifi_btn_b.png",
button_width: "240",
button_height: "100",
@@ -29,37 +28,34 @@ window.onload = function() {
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '',
- assume_success_timeout:30,
- file_queued_handler : swfFileQueued,
- file_queue_error_handler : fileQueueError,
- file_dialog_complete_handler : fileDialogComplete,
- upload_start_handler : uploadStart,
- upload_progress_handler : uploadProgress,
- upload_error_handler : uploadError,
- upload_success_handler : uploadSuccess,
- upload_complete_handler : uploadComplete,
- queue_complete_handler : queueComplete
+ assume_success_timeout: 30,
+ file_queued_handler: swfFileQueued,
+ file_queue_error_handler: fileQueueError,
+ file_dialog_complete_handler: fileDialogComplete,
+ upload_start_handler: uploadStart,
+ upload_progress_handler: uploadProgress,
+ upload_error_handler: uploadError,
+ upload_success_handler: uploadSuccess,
+ upload_complete_handler: uploadComplete,
+ queue_complete_handler: queueComplete
};
swfu = new SWFUpload(settings);
- };
-
-
-
- //上传完成
-function uploadComplete(file,server,response)
-{
+};
+
+
+
+//上传完成
+function uploadComplete(file, server, response) {
//继续下一个文件的上传
this.startUpload();
}
//完成队列里的上传
-function queueComplete(numFilesUploaded)
-{
-
+function queueComplete(numFilesUploaded) {
+
}
-function userStartUpload(file_id)
-{
+function userStartUpload(file_id) {
swfu.startUpload(file_id);
}
@@ -67,36 +63,31 @@ function userStartUpload(file_id)
-function fileQueueError(file, errorCode, message)
-{
- switch(errorCode){
+function fileQueueError(file, errorCode, message) {
+ switch (errorCode) {
case -100:
- //alert("Over 100 books");
+ //alert("Over 100 books");
case -110:
//alert("One of books is over 500MB");
- break;
+ break;
case -120:
//alert("One of books is 0KB");
- break;
+ break;
}
}
//入列完毕
-function fileDialogComplete(numFilesSelected, numFilesQueued)
-{
- if (numFilesSelected > 0)
- {
+function fileDialogComplete(numFilesSelected, numFilesQueued) {
+ if (numFilesSelected > 0) {
this.startUpload()
}
}
//开始上传
-function uploadStart(file)
-{
+function uploadStart(file) {
return true;
}
//上传出错
-function uploadError(file, errorCode, message)
-{
+function uploadError(file, errorCode, message) {
switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
errorMessage = "Error";
@@ -111,7 +102,7 @@ function uploadError(file, errorCode, message)
errorMessage = "Security error";
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
- errorMessage = "Security error";
+ errorMessage = "Security error";
break;
case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
errorMessage = "Unable to verify. Skip ";
@@ -119,14 +110,14 @@ function uploadError(file, errorCode, message)
default:
errorMessage = "Unhandled error";
break;
- }
-
+ }
+
//从上传队列中移除
- removeFileFromFilesUpload(filesUpload, file.id)
-
+ removeFileFromFilesUpload(filesUpload, file.id)
+
errorMessage = jsonLang.t8;
- $("#handle_button_"+file.id).replaceWith(""+errorMessage+"")
+ $("#handle_button_" + file.id).replaceWith("" + errorMessage + "")
}
@@ -134,59 +125,59 @@ var tmp = 0;
var errorFile = 0;
var errorMsgs = [];
-function swfFileQueued(file){
-
-
+function swfFileQueued(file) {
+
+
//本次上传选中的文件个数
- if(swfSelectCount==0) swfSelectCount = this.getStats().files_queued
+ if (swfSelectCount == 0) swfSelectCount = this.getStats().files_queued
//检测文件
msg = checkFile(file)
-
+
//文件可以通过
- if(!msg){
+ if (!msg) {
//添加全局的队列
filesUpload.push(file);
//在页面进行展示
fileQueued(file, 0)
- }else{
+ } else {
//从上传队列移除,验证失败的文件
this.cancelUpload(file.id, false)
errorMsgs.push(msg)
}
-
-
-
+
+
+
//队列选择完毕,初始化所有的数据
- if(++tmp == swfSelectCount){
-
- if(errorMsgs.length>0){
+ if (++tmp == swfSelectCount) {
+
+ if (errorMsgs.length > 0) {
//只选择做一个进行上传
- if(swfSelectCount==1){
+ if (swfSelectCount == 1) {
alert(errorMsgs[0]);
- }else{
- a1=swfSelectCount;
- a2=swfSelectCount - errorMsgs.length;
+ } else {
+ a1 = swfSelectCount;
+ a2 = swfSelectCount - errorMsgs.length;
- var replaceArr = new Array(a1,a2);
- alert(stringReplace(jsonLang.t7,replaceArr));
- }
+ var replaceArr = new Array(a1, a2);
+ alert(stringReplace(jsonLang.t7, replaceArr));
+ }
}
-
+
tmp = 0;
errorFile = 0;
swfSelectCount = 0;
errorMsgs = []
}
-
+
}
var SWFFuns = {
- cancelUpload : function(fid){
- swfu.cancelUpload(fid, false);
+ cancelUpload: function (fid) {
+ swfu.cancelUpload(fid, false);
}
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt
index fe09727f4..34a77b9e2 100644
--- a/app/src/main/java/io/legado/app/api/controller/BookController.kt
+++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt
@@ -197,25 +197,32 @@ object BookController {
DiskFileItemFactory(0, LocalBook.cacheFolder)
}
- fun addLocalBook(session: NanoHTTPD.IHTTPSession): ReturnData {
+ fun addLocalBook(session: NanoHTTPD.IHTTPSession, postData: String?): ReturnData {
val returnData = ReturnData()
- NanoFileUpload(bookFileFactory).parseRequest(session).forEach {
- val path = FileUtils.getPath(LocalBook.cacheFolder, it.name)
- val nameAuthor = LocalBook.analyzeNameAuthor(it.name)
- val book = Book(
- bookUrl = path,
- name = nameAuthor.first,
- author = nameAuthor.second,
- originName = it.name,
- coverUrl = FileUtils.getPath(
- appCtx.externalFiles,
- "covers",
- "${MD5Utils.md5Encode16(path)}.jpg"
+ try {
+ NanoFileUpload(bookFileFactory).parseRequest(session).forEach {
+ val path = FileUtils.getPath(LocalBook.cacheFolder, it.name)
+ val nameAuthor = LocalBook.analyzeNameAuthor(it.name)
+ val book = Book(
+ bookUrl = path,
+ name = nameAuthor.first,
+ author = nameAuthor.second,
+ originName = it.name,
+ coverUrl = FileUtils.getPath(
+ appCtx.externalFiles,
+ "covers",
+ "${MD5Utils.md5Encode16(path)}.jpg"
+ )
)
+ if (book.isEpub()) EpubFile.upBookInfo(book)
+ if (book.isUmd()) UmdFile.upBookInfo(book)
+ appDb.bookDao.insert(book)
+ }
+ } catch (e: Exception) {
+ e.printStackTrace()
+ return returnData.setErrorMsg(
+ e.localizedMessage ?: appCtx.getString(R.string.unknown_error)
)
- if (book.isEpub()) EpubFile.upBookInfo(book)
- if (book.isUmd()) UmdFile.upBookInfo(book)
- appDb.bookDao.insert(book)
}
return returnData.setData(true)
}
diff --git a/app/src/main/java/io/legado/app/web/HttpServer.kt b/app/src/main/java/io/legado/app/web/HttpServer.kt
index 6678d52cf..84f8de3bb 100644
--- a/app/src/main/java/io/legado/app/web/HttpServer.kt
+++ b/app/src/main/java/io/legado/app/web/HttpServer.kt
@@ -21,8 +21,8 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
var uri = session.uri
try {
- when (session.method.name) {
- "OPTIONS" -> {
+ when (session.method) {
+ Method.OPTIONS -> {
val response = newFixedLengthResponse("")
response.addHeader("Access-Control-Allow-Methods", "POST")
response.addHeader("Access-Control-Allow-Headers", "content-type")
@@ -30,7 +30,7 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
//response.addHeader("Access-Control-Max-Age", "3600");
return response
}
- "POST" -> {
+ Method.POST -> {
val files = HashMap()
session.parseBody(files)
val postData = files["postData"]
@@ -40,11 +40,11 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
"/saveSources" -> SourceController.saveSources(postData)
"/saveBook" -> BookController.saveBook(postData)
"/deleteSources" -> SourceController.deleteSources(postData)
- "/addLocalBook" -> BookController.addLocalBook(session)
+ "/addLocalBook" -> BookController.addLocalBook(session, postData)
else -> null
}
}
- "GET" -> {
+ Method.GET -> {
val parameters = session.parameters
returnData = when (uri) {
@@ -58,6 +58,7 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
else -> null
}
}
+ else -> Unit
}
if (returnData == null) {