From a4322c22a02051f6fb76d7fcff407f5324c2ab29 Mon Sep 17 00:00:00 2001 From: yaoxieyoulei <1622968661@qq.com> Date: Thu, 15 Aug 2024 19:45:35 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=AE=BE=E7=BD=AE=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E6=9C=AC=E5=9C=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../top/yogiczy/mytv/ui/utils/HttpServer.kt | 19 ++++++-- app/src/main/res/raw/index.html | 17 +------- app/src/main/res/raw/index_css.css | 11 +++++ app/src/main/res/raw/index_js.js | 43 +++++++++++++++++++ 4 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/raw/index_css.css create mode 100644 app/src/main/res/raw/index_js.js diff --git a/app/src/main/java/top/yogiczy/mytv/ui/utils/HttpServer.kt b/app/src/main/java/top/yogiczy/mytv/ui/utils/HttpServer.kt index d5982c71..8691e494 100644 --- a/app/src/main/java/top/yogiczy/mytv/ui/utils/HttpServer.kt +++ b/app/src/main/java/top/yogiczy/mytv/ui/utils/HttpServer.kt @@ -47,7 +47,13 @@ object HttpServer : Loggable() { server.listen(AsyncServer.getDefault(), SERVER_PORT) server.get("/") { _, response -> - handleHomePage(response, context) + handleRawResource(response, context, "text/html", R.raw.index) + } + server.get("/index_css.css") { _, response -> + handleRawResource(response, context, "text/css", R.raw.index_css) + } + server.get("/index_js.js") { _, response -> + handleRawResource(response, context, "text/javascript", R.raw.index_js) } server.get("/api/settings") { _, response -> @@ -83,10 +89,15 @@ object HttpServer : Loggable() { ) } - private fun handleHomePage(response: AsyncHttpServerResponse, context: Context) { + private fun handleRawResource( + response: AsyncHttpServerResponse, + context: Context, + contentType: String, + id: Int, + ) { wrapResponse(response).apply { - setContentType("text/html; charset=utf-8") - send(context.resources.openRawResource(R.raw.index).readBytes().decodeToString()) + setContentType(contentType) + send(context.resources.openRawResource(id).readBytes().decodeToString()) } } diff --git a/app/src/main/res/raw/index.html b/app/src/main/res/raw/index.html index bf4d5ec4..e4529b0c 100644 --- a/app/src/main/res/raw/index.html +++ b/app/src/main/res/raw/index.html @@ -5,21 +5,8 @@ 我的电视 - - - - - - - - - - - - - - - + +