From 0b00a5dd00fbb37c594e1419db4169d8abf8b41e Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 17 Oct 2021 21:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E6=9C=97=E8=AF=BB=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0Content-Type=E7=94=A8=E6=9D=A5=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E5=AF=B9=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/HttpTTS.kt | 1 + .../io/legado/app/service/HttpReadAloudService.kt | 3 ++- .../app/ui/book/read/config/HttpTtsEditDialog.kt | 2 ++ app/src/main/res/layout/dialog_http_tts_edit.xml | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt b/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt index c77a92b21..77d8eee64 100644 --- a/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt +++ b/app/src/main/java/io/legado/app/data/entities/HttpTTS.kt @@ -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(), diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 5c0d4971e..f0e11dc90 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -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()) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditDialog.kt index f3b95bef9..d519db410 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditDialog.kt @@ -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(), diff --git a/app/src/main/res/layout/dialog_http_tts_edit.xml b/app/src/main/res/layout/dialog_http_tts_edit.xml index 0b0b0430a..2d2f42264 100644 --- a/app/src/main/res/layout/dialog_http_tts_edit.xml +++ b/app/src/main/res/layout/dialog_http_tts_edit.xml @@ -51,6 +51,20 @@ + + + + + +