mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
背景同步
This commit is contained in:
parent
c3bea1cb0f
commit
389cd81ede
@ -72,6 +72,7 @@ object AppWebDav {
|
||||
WebDav(rootWebDavUrl, mAuthorization).makeAsDir()
|
||||
WebDav(bookProgressUrl, mAuthorization).makeAsDir()
|
||||
WebDav(exportsWebDavUrl, mAuthorization).makeAsDir()
|
||||
WebDav(bgWebDavUrl, mAuthorization).makeAsDir()
|
||||
val rootBooksUrl = "${rootWebDavUrl}books"
|
||||
defaultBookWebDav = RemoteBookWebDav(rootBooksUrl, mAuthorization)
|
||||
authorization = mAuthorization
|
||||
@ -159,7 +160,7 @@ object AppWebDav {
|
||||
/**
|
||||
* 获取云端所有背景名称
|
||||
*/
|
||||
suspend fun getAllBgWebDavFiles(): Result<List<WebDavFile>> {
|
||||
private suspend fun getAllBgWebDavFiles(): Result<List<WebDavFile>> {
|
||||
return kotlin.runCatching {
|
||||
if (!NetworkUtils.isAvailable())
|
||||
throw NoStackTraceException("网络未连接")
|
||||
@ -173,9 +174,18 @@ object AppWebDav {
|
||||
/**
|
||||
* 上传背景图片
|
||||
*/
|
||||
suspend fun upBgs(files: List<File>) {
|
||||
suspend fun upBgs(files: Array<File>) {
|
||||
val authorization = authorization ?: return
|
||||
if (!NetworkUtils.isAvailable()) return
|
||||
val bgWebDavFiles = getAllBgWebDavFiles().getOrThrow()
|
||||
.map { it.displayName }
|
||||
.toSet()
|
||||
files.forEach {
|
||||
if (!bgWebDavFiles.contains(it.name)) {
|
||||
WebDav("$bgWebDavUrl${it.name}", authorization)
|
||||
.upload(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -304,10 +304,17 @@ open class WebDav(
|
||||
suspend fun upload(
|
||||
localPath: String,
|
||||
contentType: String = "application/octet-stream"
|
||||
) {
|
||||
upload(File(localPath), contentType)
|
||||
}
|
||||
|
||||
@Throws(WebDavException::class)
|
||||
suspend fun upload(
|
||||
file: File,
|
||||
contentType: String = "application/octet-stream"
|
||||
) {
|
||||
kotlin.runCatching {
|
||||
withContext(IO) {
|
||||
val file = File(localPath)
|
||||
if (!file.exists()) throw WebDavException("文件不存在")
|
||||
// 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息
|
||||
val fileBody = file.asRequestBody(contentType.toMediaType())
|
||||
|
Loading…
Reference in New Issue
Block a user