可以直接导出为链接,方便分享

pull/1295/head
gedoor 3 years ago
parent b5c8b6be05
commit bb8858b616
  1. 7
      app/src/main/java/io/legado/app/help/DirectLinkUpload.kt
  2. 4
      app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt
  3. 13
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt

@ -13,8 +13,11 @@ object DirectLinkUpload {
suspend fun upLoad(fileName: String, byteArray: ByteArray): String { suspend fun upLoad(fileName: String, byteArray: ByteArray): String {
val res = okHttpClient.newCallStrResponse { val res = okHttpClient.newCallStrResponse {
url("https://shuyuan.miaogongzi.site/index.html") url("https://shuyuan.miaogongzi.site/upload.php")
postMultipart(mapOf("file" to Triple(fileName, byteArray, null))) postMultipart(
"multipart/form-data",
mapOf("file" to Triple(fileName, byteArray, "application/json"))
)
} }
val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url) val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url)
return analyzeRule.getString("tag.b@text") return analyzeRule.getString("tag.b@text")

@ -118,8 +118,8 @@ fun Request.Builder.postForm(form: Map<String, String>, encoded: Boolean = false
post(formBody.build()) post(formBody.build())
} }
fun Request.Builder.postMultipart(form: Map<String, Any>) { fun Request.Builder.postMultipart(type: String, form: Map<String, Any>) {
val multipartBody = MultipartBody.Builder() val multipartBody = MultipartBody.Builder().setType(type.toMediaType())
form.forEach { form.forEach {
when (it.value) { when (it.value) {
is Triple<*, *, *> -> { is Triple<*, *, *> -> {

@ -33,8 +33,17 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
} }
} }
private val exportBookshelf = registerForActivityResult(HandleFileContract()) { private val exportBookshelf = registerForActivityResult(HandleFileContract()) {
it?.let { it?.let { uri ->
alert("导出成功") {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.hint = "路径"
editView.setText(uri.toString())
}
customView { alertBinding.root }
okButton {
requireContext().sendToClip(uri.toString())
}
}.show()
} }
} }
abstract val groupId: Long abstract val groupId: Long

Loading…
Cancel
Save