Skip to content

Commit

Permalink
feat: 统一文件管理,优化书籍内容使用缓存图片,修复书架绝对路径bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorqin committed Jul 14, 2022
1 parent 92d81b8 commit 59ec8e3
Show file tree
Hide file tree
Showing 15 changed files with 1,181 additions and 1,386 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ apply(plugin = "kotlin")
apply(plugin = "io.github.fvarrui.javapackager.plugin")

group = "com.htmake"
version = "2.5.4"
version = "2.5.5"

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
2 changes: 1 addition & 1 deletion cli.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply plugin: 'io.spring.dependency-management'
apply plugin: 'kotlin'

group = 'com.htmake'
version = '2.5.4'
version = '2.5.5'
sourceCompatibility = '1.8'

repositories {
Expand Down
78 changes: 47 additions & 31 deletions src/main/java/com/htmake/reader/api/YueduApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.htmake.reader.api.controller.UserController
import com.htmake.reader.api.controller.WebdavController
import com.htmake.reader.api.controller.ReplaceRuleController
import com.htmake.reader.api.controller.BookmarkController
import com.htmake.reader.api.controller.FileController
import com.htmake.reader.utils.error
import com.htmake.reader.utils.success
import com.htmake.reader.utils.getStorage
Expand Down Expand Up @@ -105,8 +106,23 @@ class YueduApi : RestVerticle() {
}
router.route("/assets/*").handler(StaticHandler.create().setAllowRootFileSystemAccess(true).setWebRoot(assetsDir).setDefaultContentEncoding("UTF-8"));

// epub资源
// 书籍资源
var dataDir = getWorkDir("storage", "data");
router.route("/book-assets/*").handler {
var path = it.request().path().replace("/book-assets/", "/", true)
path = URLDecoder.decode(path, "UTF-8")
if (path.endsWith("html", true)) {
var filePath = File(dataDir + path)
if (filePath.exists()) {
// 处理 js 注入脚本
BookConfig.injectJavascriptToEpubChapter(filePath.toString())
}
}
it.next()
}
router.route("/book-assets/*").handler(StaticHandler.create().setAllowRootFileSystemAccess(true).setWebRoot(dataDir).setDefaultContentEncoding("UTF-8"));

// 兼容之前的 epub 缓存
router.route("/epub/*").handler {
var path = it.request().path().replace("/epub/", "/", true)
path = URLDecoder.decode(path, "UTF-8")
Expand Down Expand Up @@ -135,6 +151,7 @@ class YueduApi : RestVerticle() {
}
val replaceRuleController = ReplaceRuleController(coroutineContext)
val bookmarkController = BookmarkController(coroutineContext)
val fileController = FileController(coroutineContext)

/** 书源模块 */
router.post("/reader3/saveBookSource").coroutineHandler { bookSourceController.saveBookSource(it) }
Expand Down Expand Up @@ -230,19 +247,6 @@ class YueduApi : RestVerticle() {
router.post("/reader3/deleteBookGroup").coroutineHandler { bookController.deleteBookGroup(it) }
router.post("/reader3/saveBookGroupOrder").coroutineHandler { bookController.saveBookGroupOrder(it) }

// 书仓功能
// 获取书仓文件列表
router.get("/reader3/getLocalStoreFileList").coroutineHandler { bookController.getLocalStoreFileList(it) }
// 下载书仓文件
router.get("/reader3/getLocalStoreFile").coroutineHandlerWithoutRes { bookController.getLocalStoreFile(it) }
// 删除书仓文件
router.post("/reader3/deleteLocalStoreFile").coroutineHandler { bookController.deleteLocalStoreFile(it) }
router.post("/reader3/deleteLocalStoreFileList").coroutineHandler { bookController.deleteLocalStoreFileList(it) }
// 从本地书仓/webdav导入
router.post("/reader3/importFromLocalPathPreview").coroutineHandler { bookController.importFromLocalPathPreview(it) }
// 上传文件到书仓
router.post("/reader3/uploadFileToLocalStore").coroutineHandler { bookController.uploadFileToLocalStore(it) }

// 调试书源
router.get("/reader3/bookSourceDebugSSE").coroutineHandlerWithoutRes { bookController.bookSourceDebugSSE(it) }

Expand Down Expand Up @@ -299,23 +303,6 @@ class YueduApi : RestVerticle() {


/** webdav模块 */
// 获取webdav备份列表
router.get("/reader3/getWebdavFileList").coroutineHandler { webdavController.getWebdavFileList(it) }

// 下载webdav文件
router.get("/reader3/getWebdavFile").coroutineHandlerWithoutRes { webdavController.getWebdavFile(it) }

// 上传webdav文件
router.post("/reader3/uploadFileToWebdav").coroutineHandler { webdavController.uploadFileToWebdav(it) }

// 删除webdav文件
router.get("/reader3/deleteWebdavFile").coroutineHandler { webdavController.deleteWebdavFile(it) }
router.post("/reader3/deleteWebdavFile").coroutineHandler { webdavController.deleteWebdavFile(it) }
router.post("/reader3/deleteWebdavFileList").coroutineHandler { webdavController.deleteWebdavFileList(it) }

// 从webdav备份恢复
router.post("/reader3/restoreFromWebdav").coroutineHandler { webdavController.restoreFromWebdav(it) }

// 备份到webdav
router.post("/reader3/backupToWebdav").coroutineHandler { webdavController.backupToWebdav(it) }

Expand Down Expand Up @@ -346,6 +333,35 @@ class YueduApi : RestVerticle() {
router.post("/reader3/saveBookmarks").coroutineHandler { bookmarkController.saveBookmarks(it) }
router.post("/reader3/deleteBookmark").coroutineHandler { bookmarkController.deleteBookmark(it) }
router.post("/reader3/deleteBookmarks").coroutineHandler { bookmarkController.deleteBookmarks(it) }

/** 文件系统模块 */
// 获取文件列表
router.get("/reader3/file/list").coroutineHandler { fileController.list(it) }

// 读取文件内容
router.get("/reader3/file/get").coroutineHandler { fileController.get(it) }

// 保存文件内容
router.post("/reader3/file/save").coroutineHandler { fileController.save(it) }

// 创建文件夹
router.post("/reader3/file/mkdir").coroutineHandler { fileController.mkdir(it) }

// 下载文件
router.get("/reader3/file/download").coroutineHandlerWithoutRes { fileController.download(it) }

// 上传文件
router.post("/reader3/file/upload").coroutineHandler { fileController.upload(it) }

// 删除文件
router.post("/reader3/file/delete").coroutineHandler { fileController.delete(it) }
router.post("/reader3/file/deleteMulti").coroutineHandler { fileController.deleteMulti(it) }

// 从文件导入
router.post("/reader3/file/importPreview").coroutineHandler { fileController.importPreview(it) }

// 从文件恢复
router.post("/reader3/file/restore").coroutineHandler { fileController.restore(it) }
}

suspend fun setupPort() {
Expand Down
Loading

0 comments on commit 59ec8e3

Please sign in to comment.