在线朗读添加Content-Type用来判断返回结果对不对

pull/1395/head
gedoor 3 years ago
parent 0115b0a94a
commit 0b00a5dd00
  1. 1
      app/src/main/java/io/legado/app/data/entities/HttpTTS.kt
  2. 3
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditDialog.kt
  4. 14
      app/src/main/res/layout/dialog_http_tts_edit.xml

@ -47,6 +47,7 @@ data class HttpTTS(
id = doc.readLong("$.id") ?: System.currentTimeMillis(),
name = doc.readString("$.name")!!,
url = doc.readString("$.url")!!,
contentType = doc.readString("$.contentType"),
concurrentRate = doc.readString("$.concurrentRate"),
loginUrl = doc.readString("$.loginUrl"),
loginUi = if (loginUi is List<*>) GSON.toJson(loginUi) else loginUi?.toString(),

@ -134,7 +134,8 @@ class HttpReadAloudService : BaseReadAloudService(),
response = analyzeUrl.evalJS(checkJs, response) as Response
}
}
httpTts.contentType?.let { contentTypeRegex ->
val contentTypeRegex = httpTts.contentType
if (!contentTypeRegex.isNullOrBlank()) {
response.headers["Content-Type"]?.let { contentType ->
if (!contentType.matches(contentTypeRegex.toRegex())) {
throw NoStackTraceException(response.body!!.string())

@ -72,6 +72,7 @@ class HttpTtsEditDialog() : BaseDialogFragment(R.layout.dialog_http_tts_edit),
fun initView(httpTTS: HttpTTS) {
binding.tvName.setText(httpTTS.name)
binding.tvUrl.setText(httpTTS.url)
binding.tvContentType.setText(httpTTS.contentType)
binding.tvLoginUrl.setText(httpTTS.loginUrl)
binding.tvLoginUi.setText(httpTTS.loginUi)
binding.tvLoginCheckJs.setText(httpTTS.loginCheckJs)
@ -117,6 +118,7 @@ class HttpTtsEditDialog() : BaseDialogFragment(R.layout.dialog_http_tts_edit),
id = viewModel.id ?: System.currentTimeMillis(),
name = binding.tvName.text.toString(),
url = binding.tvUrl.text.toString(),
contentType = binding.tvContentType.text?.toString(),
loginUrl = binding.tvLoginUrl.text?.toString(),
loginUi = binding.tvLoginUi.text?.toString(),
loginCheckJs = binding.tvLoginCheckJs.text?.toString(),

@ -51,6 +51,20 @@
</io.legado.app.ui.widget.text.TextInputLayout>
<io.legado.app.ui.widget.text.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Content-Type"
tools:ignore="HardcodedText">
<io.legado.app.ui.widget.code.CodeView
android:id="@+id/tv_content_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="TouchTargetSizeCheck,SpeakableTextPresentCheck" />
</io.legado.app.ui.widget.text.TextInputLayout>
<io.legado.app.ui.widget.text.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

Loading…
Cancel
Save