This commit is contained in:
Horis
2024-07-31 21:51:27 +08:00
parent 0fea035a05
commit 84813a549c
3 changed files with 16 additions and 10 deletions
@@ -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){
@@ -171,7 +171,7 @@
nextUpload()
}
};
};
// };
}
//请求完成,无论失败或成功
@@ -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 {
@@ -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 }
}
@@ -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("需重新设置书籍保存位置!")
@@ -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)