This commit is contained in:
lushunming 2025-07-18 14:20:31 +08:00
parent 032e496a26
commit 9f89678c45
4 changed files with 33 additions and 24 deletions

View File

@ -26,14 +26,17 @@ import java.nio.ByteBuffer
import java.nio.charset.Charset import java.nio.charset.Charset
object KtorServer { object KtorServer {
private const val port = 12345 private var port = 12345
private val THREAD_NUM = Runtime.getRuntime().availableProcessors() * 2 private val THREAD_NUM = Runtime.getRuntime().availableProcessors() * 2
private val infos = mutableMapOf<String, Array<Any>>() private val infos = mutableMapOf<String, Array<Any>>()
var ser: io.ktor.server.engine.ApplicationEngine? = null
//每个片1MB //每个片1MB
private val partSize = 1024 * 1024 * 1 private val partSize = 1024 * 1024 * 1
private val server by lazy { fun init() {
embeddedServer(CIO, port) { do {
try {
ser = embeddedServer(CIO, port) {
install(CallLogging) install(CallLogging)
@ -42,32 +45,38 @@ object KtorServer {
call.respondText("ktor running on $port", ContentType.Text.Plain) call.respondText("ktor running on $port", ContentType.Text.Plain)
} }
get("/proxy") { get("/proxy") {
SpiderDebug.log("代理中: ${call.parameters["url"]}")
val url = Util.base64Decode(call.parameters["url"]) val url = Util.base64Decode(call.parameters["url"])
val header: Map<String, String> = Gson().fromJson<Map<String, String>>( val header: Map<String, String> = Gson().fromJson<Map<String, String>>(
Util.base64Decode(call.parameters["headers"]), MutableMap::class.java Util.base64Decode(call.parameters["headers"]),
MutableMap::class.java
) )
proxyAsync( proxyAsync(
url, header, call url, header, call
) )
} }
} }
}.start(wait = false)
} catch (e: Exception) {
SpiderDebug.log("start server e:" + e.message)
++port
ser?.stop()
} }
} while (port < 13000)
} }
/** 启动服务器 */ /** 启动服务器 */
fun start() { fun start() {
SpiderDebug.log("ktorServer start on $port") SpiderDebug.log("ktorServer start on $port")
CoroutineScope(Dispatchers.IO).launch { server.start(true) } CoroutineScope(Dispatchers.IO).launch { init() }
} }
/** 停止服务器 */ /** 停止服务器 */
fun stop() { fun stop() {
server.stop(1_000, 2_000) ser?.stop(1_000, 2_000)
} }
fun buildProxyUrl(url: String, headers: Map<String, String>): String { fun buildProxyUrl(url: String, headers: Map<String, String>): String {

Binary file not shown.

View File

@ -1 +1 @@
68e6ce9893966f1b033d592e0f93b2ea 7610a4d16212252a8db5108551e7c9a7

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;5d41a155e40f64b26b514ec52a1c6ab9", "spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;7610a4d16212252a8db5108551e7c9a7",
"lives": [ "lives": [
{ {
"name": "电视直播", "name": "电视直播",