Merge remote-tracking branch 'origin/master'

pull/1894/head^2
kunfei 3 years ago
commit f1f517531d
  1. 98
      api.md
  2. 2
      app/src/main/assets/web/bookshelf/css/about.65a00131.css
  3. 2
      app/src/main/assets/web/bookshelf/css/detail.12a39aa7.css
  4. 4
      app/src/main/assets/web/bookshelf/index.html
  5. 1
      app/src/main/assets/web/bookshelf/js/about.2456ab2e.js
  6. 1
      app/src/main/assets/web/bookshelf/js/about.a59e4c80.js
  7. 2
      app/src/main/assets/web/bookshelf/js/app.a68b7203.js
  8. 1
      app/src/main/assets/web/bookshelf/js/detail.178755db.js
  9. 1
      app/src/main/assets/web/bookshelf/js/detail.8e2caf8f.js
  10. 6
      app/src/main/java/io/legado/app/api/ReaderProvider.kt
  11. 28
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  12. 1
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  13. 2
      app/src/main/java/io/legado/app/help/SourceAnalyzer.kt
  14. 2
      app/src/main/java/io/legado/app/utils/ColorUtils.kt

@ -1,30 +1,37 @@
# 阅读API
## 对于Web的配置
您需要先在设置中启用"Web 服务"。
## 使用
### Web
以下说明假设您的操作在本机进行,且开放端口为1234。
如果您要从远程计算机访问[阅读](),请将`127.0.0.1`替换成手机IP。
#### 插入单个书源
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt)
```
URL = http://127.0.0.1:1234/saveSource
Method = POST
```
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt)
#### 插入多个书源or订阅源
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
```
URL = http://127.0.0.1:1234/saveBookSources
URL = http://127.0.0.1:1234/saveRssSources
Method = POST
```
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
#### 获取书源
```
@ -43,25 +50,27 @@ Method = GET
#### 删除多个书源or订阅源
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
```
URL = http://127.0.0.1:1234/deleteBookSources
URL = http://127.0.0.1:1234/deleteRssSources
Method = POST
```
#### 插入书籍
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/Book.kt)。
#### 插入书籍
```
URL = http://127.0.0.1:1234/saveBook
Method = POST
```
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/Book.kt)。
#### 获取所有书籍
```
URL = http://127.0.0.1:1234/getBookshelf
Method = GET
@ -70,6 +79,7 @@ Method = GET
获取APP内的所有书籍。
#### 获取书籍章节列表
```
URL = http://127.0.0.1:1234/getChapterList?url=xxx
Method = GET
@ -78,116 +88,134 @@ Method = GET
获取指定图书的章节列表。
#### 获取书籍内容
```
URL = http://127.0.0.1:1234/getBookContent?url=xxx&index=1
Method = GET
```
获取指定图书的第`index`章节的文本内容。
#### 获取封面
```
URL = http://127.0.0.1:1234/cover?path=xxxxx
Method = GET
```
#### 保存书籍进度
请求BODY内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookProgress.kt)。
```
URL = http://127.0.0.1:1234/saveBookProgress
Method = POST
```
### Content Provider
* 需声明`io.legado.READ_WRITE`权限
* `providerHost`为`包名.readerProvider`, 如`io.legado.app.release.readerProvider`,不同包的地址不同,防止冲突安装失败
* 以下出现的`providerHost`请自行替换
#### 插入单个书源or订阅源
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt)
```
URL = content://providerHost/bookSource/insert
URL = content://providerHost/rssSource/insert
Method = insert
```
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt)
#### 插入多个书源or订阅源
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
```
URL = content://providerHost/bookSources/insert
URL = content://providerHost/rssSources/insert
Method = insert
```
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
#### 获取书源or订阅源
获取指定URL对应的书源信息。
用`Cursor.getString(0)`取出返回结果。
```
URL = content://providerHost/bookSource/query?url=xxx
URL = content://providerHost/rssSource/query?url=xxx
Method = query
```
获取指定URL对应的书源信息。
用`Cursor.getString(0)`取出返回结果。
#### 获取所有书源or订阅源
获取APP内的所有订阅源。
用`Cursor.getString(0)`取出返回结果。
```
URL = content://providerHost/bookSources/query
URL = content://providerHost/rssSources/query
Method = query
```
获取APP内的所有书源。
用`Cursor.getString(0)`取出返回结果。
#### 删除多个书源or订阅源
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
```
URL = content://providerHost/bookSources/delete
URL = content://providerHost/rssSources/delete
Method = delete
```
#### 插入书籍
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookSource.kt),**为数组格式**。
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/Book.kt)。
#### 插入书籍
```
URL = content://providerHost/book/insert
Method = insert
```
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
格式参考[这个文件](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/Book.kt)。
#### 获取所有书籍
获取APP内的所有书籍。
用`Cursor.getString(0)`取出返回结果。
```
URL = content://providerHost/books/query
Method = query
```
获取APP内的所有书籍。
#### 获取书籍章节列表
获取指定图书的章节列表。
用`Cursor.getString(0)`取出返回结果。
#### 获取书籍章节列表
```
URL = content://providerHost/book/chapter/query?url=xxx
Method = query
```
获取指定图书的章节列表。
用`Cursor.getString(0)`取出返回结果。
#### 获取书籍内容
获取指定图书的第`index`章节的文本内容。
用`Cursor.getString(0)`取出返回结果。
```
URL = content://providerHost/book/content/query?url=xxx&index=1
Method = query
```
获取指定图书的第`index`章节的文本内容。
用`Cursor.getString(0)`取出返回结果。
#### 获取封面
```
URL = content://providerHost/book/cover/query?path=xxxx
Method = query

@ -1,3 +1,3 @@
<!DOCTYPE html><html lang="en" style="padding: 0;height:100%"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><link rel="icon" href="../favicon.ico" type="image/x-icon"><link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"><title>Legado Bookshelf</title><link href="css/about.b93f38f9.css" rel="prefetch"><link href="css/detail.d23875f7.css" rel="prefetch"><link href="js/about.a59e4c80.js" rel="prefetch"><link href="js/detail.178755db.js" rel="prefetch"><link href="css/app.e4c919b7.css" rel="preload" as="style"><link href="css/chunk-vendors.bd1373b6.css" rel="preload" as="style"><link href="js/app.e6fe88cd.js" rel="preload" as="script"><link href="js/chunk-vendors.f36dda93.js" rel="preload" as="script"><link href="css/chunk-vendors.bd1373b6.css" rel="stylesheet"><link href="css/app.e4c919b7.css" rel="stylesheet"></head><style>body::-webkit-scrollbar {
<!DOCTYPE html><html lang="en" style="padding: 0;height:100%"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><link rel="icon" href="../favicon.ico" type="image/x-icon"><link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"><title>Legado Bookshelf</title><link href="css/about.65a00131.css" rel="prefetch"><link href="css/detail.12a39aa7.css" rel="prefetch"><link href="js/about.2456ab2e.js" rel="prefetch"><link href="js/detail.8e2caf8f.js" rel="prefetch"><link href="css/app.e4c919b7.css" rel="preload" as="style"><link href="css/chunk-vendors.bd1373b6.css" rel="preload" as="style"><link href="js/app.a68b7203.js" rel="preload" as="script"><link href="js/chunk-vendors.f36dda93.js" rel="preload" as="script"><link href="css/chunk-vendors.bd1373b6.css" rel="stylesheet"><link href="css/app.e4c919b7.css" rel="stylesheet"></head><style>body::-webkit-scrollbar {
display: none;
}</style><body style="margin: 0;height:100%"><noscript><strong>We're sorry but yd-web-tool doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.f36dda93.js"></script><script src="js/app.e6fe88cd.js"></script></body></html>
}</style><body style="margin: 0;height:100%"><noscript><strong>We're sorry but yd-web-tool doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.f36dda93.js"></script><script src="js/app.a68b7203.js"></script></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -21,7 +21,8 @@ class ReaderProvider : ContentProvider() {
private enum class RequestCode {
SaveBookSource, SaveBookSources, DeleteBookSources, GetBookSource, GetBookSources,
SaveRssSource, SaveRssSources, DeleteRssSources, GetRssSource, GetRssSources,
SaveBook, GetBookshelf, RefreshToc, GetChapterList, GetBookContent, GetBookCover
SaveBook, GetBookshelf, RefreshToc, GetChapterList, GetBookContent, GetBookCover,
SaveBookProgress
}
private val postBodyKey = "json"
@ -86,6 +87,9 @@ class ReaderProvider : ContentProvider() {
RequestCode.SaveBook -> values?.let {
BookController.saveBook(values.getAsString(postBodyKey))
}
RequestCode.SaveBookProgress -> values?.let {
BookController.saveBookProgress(values.getAsString(postBodyKey))
}
else -> throw IllegalStateException(
"Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name
)

@ -215,19 +215,23 @@ object BookController {
*/
fun saveBookProgress(postData: String?): ReturnData {
val returnData = ReturnData()
GSON.fromJsonObject<BookProgress>(postData).getOrNull()?.let { bookProgress ->
appDb.bookDao.getBook(bookProgress.name, bookProgress.author)?.let { book ->
book.durChapterIndex = bookProgress.durChapterIndex
book.durChapterPos = bookProgress.durChapterPos
appDb.bookDao.update(book)
AppWebDav.uploadBookProgress(bookProgress)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex
GSON.fromJsonObject<BookProgress>(postData)
.onFailure { it.printOnDebug() }
.getOrNull()?.let { bookProgress ->
appDb.bookDao.getBook(bookProgress.name, bookProgress.author)?.let { book ->
book.durChapterIndex = bookProgress.durChapterIndex
book.durChapterPos = bookProgress.durChapterPos
book.durChapterTitle = bookProgress.durChapterTitle
book.durChapterTime = bookProgress.durChapterTime
appDb.bookDao.update(book)
AppWebDav.uploadBookProgress(bookProgress)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex
}
return returnData.setData("")
}
return returnData.setData("")
}
}
return returnData.setErrorMsg("格式不对")
}
@ -241,7 +245,7 @@ object BookController {
val fileData = parameters["fileData"]?.firstOrNull()
?: return returnData.setErrorMsg("fileData 不能为空")
kotlin.runCatching {
LocalBook.importFileOnLine(fileData, fileName)
LocalBook.importFileOnLine(fileData, fileName)
}.onFailure {
return when (it) {
is SecurityException -> returnData.setErrorMsg("需重新设置书籍保存位置!")

@ -153,6 +153,7 @@ data class RssSource(
style = doc.readString("$.style"),
enableJs = doc.readBool("$.enableJs") ?: true,
loadWithBaseUrl = doc.readBool("$.loadWithBaseUrl") ?: true,
enabledCookieJar = doc.readBool("$.enabledCookieJar") ?: false,
customOrder = doc.readInt("$.customOrder") ?: 0
)
}

@ -150,6 +150,7 @@ object SourceAnalyzer {
source.customOrder = sourceAny.customOrder
source.enabled = sourceAny.enabled
source.enabledExplore = sourceAny.enabledExplore
source.enabledCookieJar = sourceAny.enabledCookieJar
source.concurrentRate = sourceAny.concurrentRate
source.header = sourceAny.header
source.loginUrl = when (sourceAny.loginUrl) {
@ -219,6 +220,7 @@ object SourceAnalyzer {
var customOrder: Int = 0, // 手动排序编号
var enabled: Boolean = true, // 是否启用
var enabledExplore: Boolean = true, // 启用发现
var enabledCookieJar: Boolean = false, // 启用CookieJar
var concurrentRate: String? = null, // 并发率
var header: String? = null, // 请求头
var loginUrl: Any? = null, // 登录规则

@ -10,7 +10,7 @@ import kotlin.math.*
object ColorUtils {
fun isColorLight(@ColorInt color: Int): Boolean {
return ColorUtils.calculateLuminance(color) >= 0.65
return ColorUtils.calculateLuminance(color) >= 0.5
}
fun intToString(intColor: Int): String {

Loading…
Cancel
Save