legado/api.md

294 lines
6.3 KiB
Markdown
Raw Permalink Normal View History

2023-03-27 07:40:52 +08:00
# 阅读[API](/app/src/main/java/io/legado/app/api/controller)
2022-05-16 10:55:34 +08:00
2023-03-27 07:40:52 +08:00
## 对于[Web](/app/src/main/java/io/legado/app/web/)的配置
2022-05-16 10:55:34 +08:00
您需要先在设置中启用"Web 服务"。
2022-01-03 23:59:44 +08:00
## 使用
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
### Web
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
以下说明假设您的操作在本机进行且开放端口为1234。
如果您要从远程计算机访问[阅读](),请将`127.0.0.1`替换成手机IP。
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
#### 插入单个书源
2022-05-16 10:55:34 +08:00
请求BODY内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/BookSource.kt)
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
2023-07-08 16:45:31 +08:00
URL = http://127.0.0.1:1234/saveBookSource
2022-01-03 23:59:44 +08:00
Method = POST
```
#### 插入多个书源or订阅源
2022-05-16 10:55:34 +08:00
请求BODY内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/BookSource.kt)**为数组格式**。
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = http://127.0.0.1:1234/saveBookSources
URL = http://127.0.0.1:1234/saveRssSources
Method = POST
```
#### 获取书源
```
URL = http://127.0.0.1:1234/getBookSource?url=xxx
URL = http://127.0.0.1:1234/getRssSource?url=xxx
Method = GET
```
#### 获取所有书源or订阅源
```
URL = http://127.0.0.1:1234/getBookSources
URL = http://127.0.0.1:1234/getRssSources
Method = GET
```
#### 删除多个书源or订阅源
2022-05-16 10:55:34 +08:00
请求BODY内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/BookSource.kt)**为数组格式**。
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = http://127.0.0.1:1234/deleteBookSources
URL = http://127.0.0.1:1234/deleteRssSources
Method = POST
```
2023-03-27 09:47:54 +08:00
#### 调试源
key为书源搜索关键词tag为源链接
```
URL = ws://127.0.0.1:1235/bookSourceDebug
URL = ws://127.0.0.1:1235/rssSourceDebug
Message = { key: [String], tag: [String] }
```
2023-03-27 07:40:52 +08:00
#### 获取替换规则
```
URL = http://127.0.0.1:1234/getReplaceRules
Method = GET
```
#### 替换规则管理
请求BODY内容为`JSON`字符串,
替换规则参考[这个文件](/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt)。
##### 删除
```
URL = http://127.0.0.1:1234/deleteReplaceRule
Method = POST
Body = [ReplaceRule]
```
##### 插入
```
URL = http://127.0.0.1:1234/saveReplaceRule
Method = POST
Body = [ReplaceRule]
```
##### 测试
返回测试文本text替换结果
```
URL = http://127.0.0.1:1234/testReplaceRule
Method = POST
Body = { rule: [ReplaceRule], text: [String] }
```
#### 搜索在线书籍
2023-04-07 09:15:31 +08:00
若想获取对应的书籍的目录正文 请先**插入书籍**以启用缓存,如果试读后决定不添加到书籍,请**删除书籍**
2023-03-27 07:40:52 +08:00
```
2023-03-27 09:47:54 +08:00
URL = ws://127.0.0.1:1235/searchBook
2023-03-27 08:43:57 +08:00
Message = { key: [String] }
2023-03-27 07:40:52 +08:00
```
2022-05-16 10:55:34 +08:00
#### 插入书籍
2022-01-03 23:59:44 +08:00
请求BODY内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/Book.kt)。
2022-01-03 23:59:44 +08:00
```
URL = http://127.0.0.1:1234/saveBook
Method = POST
```
2023-04-07 09:15:31 +08:00
#### 删除书籍
```
URL = http://127.0.0.1:1234/deleteBook
Method = POST
```
2022-01-03 23:59:44 +08:00
#### 获取所有书籍
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = http://127.0.0.1:1234/getBookshelf
Method = GET
```
2022-05-16 10:55:34 +08:00
获取APP内的所有书籍。
2022-01-03 23:59:44 +08:00
#### 获取书籍章节列表
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = http://127.0.0.1:1234/getChapterList?url=xxx
Method = GET
```
2022-05-16 10:55:34 +08:00
获取指定图书的章节列表。
2022-01-03 23:59:44 +08:00
#### 获取书籍内容
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = http://127.0.0.1:1234/getBookContent?url=xxx&index=1
Method = GET
```
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
获取指定图书的第`index`章节的文本内容。
#### 获取封面
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = http://127.0.0.1:1234/cover?path=xxxxx
Method = GET
```
2023-03-27 07:40:52 +08:00
#### 获取正文图片
```
URL = http://127.0.0.1:1234/image?url=${bookUrl}&path=${picUrl}&width=${width}
Method = GET
```
2022-05-16 10:55:34 +08:00
#### 保存书籍进度
请求BODY内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/BookProgress.kt)。
2022-05-16 10:55:34 +08:00
```
URL = http://127.0.0.1:1234/saveBookProgress
Method = POST
```
2022-01-03 23:59:44 +08:00
2023-03-27 07:40:52 +08:00
### [Content Provider](/app/src/main/java/io/legado/app/api/ReaderProvider.kt)
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
* 需声明`io.legado.READ_WRITE`权限
* `providerHost`为`包名.readerProvider`, 如`io.legado.app.release.readerProvider`,不同包的地址不同,防止冲突安装失败
* 以下出现的`providerHost`请自行替换
#### 插入单个书源or订阅源
2022-05-16 10:55:34 +08:00
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/BookSource.kt)
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/bookSource/insert
URL = content://providerHost/rssSource/insert
Method = insert
```
#### 插入多个书源or订阅源
2022-05-16 10:55:34 +08:00
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/BookSource.kt)**为数组格式**。
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/bookSources/insert
URL = content://providerHost/rssSources/insert
Method = insert
```
#### 获取书源or订阅源
2022-05-16 10:55:34 +08:00
获取指定URL对应的书源信息。
用`Cursor.getString(0)`取出返回结果。
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/bookSource/query?url=xxx
URL = content://providerHost/rssSource/query?url=xxx
Method = query
```
#### 获取所有书源or订阅源
2022-05-16 10:55:34 +08:00
获取APP内的所有订阅源。
用`Cursor.getString(0)`取出返回结果。
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/bookSources/query
URL = content://providerHost/rssSources/query
Method = query
```
#### 删除多个书源or订阅源
2022-05-16 10:55:34 +08:00
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/BookSource.kt)**为数组格式**。
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/bookSources/delete
URL = content://providerHost/rssSources/delete
Method = delete
```
2022-05-16 10:55:34 +08:00
#### 插入书籍
2022-01-03 23:59:44 +08:00
创建`Key="json"`的`ContentValues`,内容为`JSON`字符串,
2023-03-27 07:40:52 +08:00
格式参考[这个文件](/app/src/main/java/io/legado/app/data/entities/Book.kt)。
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/book/insert
Method = insert
```
#### 获取所有书籍
2022-05-16 10:55:34 +08:00
获取APP内的所有书籍。
用`Cursor.getString(0)`取出返回结果。
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/books/query
Method = query
```
2022-05-16 10:55:34 +08:00
#### 获取书籍章节列表
获取指定图书的章节列表。
2022-01-03 23:59:44 +08:00
用`Cursor.getString(0)`取出返回结果。
```
URL = content://providerHost/book/chapter/query?url=xxx
Method = query
```
#### 获取书籍内容
2022-05-16 10:55:34 +08:00
获取指定图书的第`index`章节的文本内容。
用`Cursor.getString(0)`取出返回结果。
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/book/content/query?url=xxx&index=1
Method = query
```
#### 获取封面
2022-05-16 10:55:34 +08:00
2022-01-03 23:59:44 +08:00
```
URL = content://providerHost/book/cover/query?path=xxxx
Method = query
```