Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jul 31, 2024
1 parent 0fea035 commit 84813a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 6 additions & 6 deletions app/src/main/assets/web/uploadBook/js/html5_fun.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@
//正在上传
isUploading = true;
//设置上传的数据
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
var data = e.target.result;
// var reader = new FileReader();
// reader.readAsDataURL(file);
// reader.onload = function (e) {
// var data = e.target.result;
var fd = new FormData();
fd.append("fileName", file.name);
fd.append("fileData", data);
fd.append("fileData", file);
//设置当前的上传对象
currUploadfile = file;
if(XHR.readyState>0){
Expand Down Expand Up @@ -171,7 +171,7 @@
nextUpload()
}
};
};
// };
}

//请求完成,无论失败或成功
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/io/legado/app/api/controller/BookController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.legado.app.utils.stackTraceStr
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import splitties.init.appCtx
import java.io.File

object BookController {

Expand All @@ -48,6 +49,7 @@ object BookController {
2 -> books.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}

3 -> books.sortedBy { it.order }
else -> books.sortedByDescending { it.durChapterTime }
}
Expand Down Expand Up @@ -256,14 +258,18 @@ object BookController {
/**
* 添加本地书籍
*/
fun addLocalBook(parameters: Map<String, List<String>>): ReturnData {
fun addLocalBook(
parameters: Map<String, List<String>>,
files: Map<String, String>
): ReturnData {
val returnData = ReturnData()
val fileName = parameters["fileName"]?.firstOrNull()
?: return returnData.setErrorMsg("fileName 不能为空")
val fileData = parameters["fileData"]?.firstOrNull()
val fileData = files["fileData"]
?: return returnData.setErrorMsg("fileData 不能为空")
kotlin.runCatching {
LocalBook.importFileOnLine(fileData, fileName)
val uri = LocalBook.saveBookFile(File(fileData).inputStream(), fileName)
LocalBook.importFile(uri)
}.onFailure {
return when (it) {
is SecurityException -> returnData.setErrorMsg("需重新设置书籍保存位置!")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/legado/app/web/HttpServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
"/saveBook" -> BookController.saveBook(postData)
"/deleteBook" -> BookController.deleteBook(postData)
"/saveBookProgress" -> BookController.saveBookProgress(postData)
"/addLocalBook" -> BookController.addLocalBook(session.parameters)
"/addLocalBook" -> BookController.addLocalBook(session.parameters, files)
"/saveReadConfig" -> BookController.saveWebReadConfig(postData)
"/saveRssSource" -> RssSourceController.saveSource(postData)
"/saveRssSources" -> RssSourceController.saveSources(postData)
Expand Down

0 comments on commit 84813a5

Please sign in to comment.