ktor
This commit is contained in:
parent
032e496a26
commit
9f89678c45
|
|
@ -26,14 +26,17 @@ import java.nio.ByteBuffer
|
|||
import java.nio.charset.Charset
|
||||
|
||||
object KtorServer {
|
||||
private const val port = 12345
|
||||
private var port = 12345
|
||||
private val THREAD_NUM = Runtime.getRuntime().availableProcessors() * 2
|
||||
private val infos = mutableMapOf<String, Array<Any>>()
|
||||
var ser: io.ktor.server.engine.ApplicationEngine? = null
|
||||
|
||||
//每个片1MB
|
||||
private val partSize = 1024 * 1024 * 1
|
||||
private val server by lazy {
|
||||
embeddedServer(CIO, port) {
|
||||
fun init() {
|
||||
do {
|
||||
try {
|
||||
ser = embeddedServer(CIO, port) {
|
||||
install(CallLogging)
|
||||
|
||||
|
||||
|
|
@ -42,32 +45,38 @@ object KtorServer {
|
|||
call.respondText("ktor running on $port", ContentType.Text.Plain)
|
||||
}
|
||||
get("/proxy") {
|
||||
SpiderDebug.log("代理中: ${call.parameters["url"]}")
|
||||
|
||||
|
||||
val url = Util.base64Decode(call.parameters["url"])
|
||||
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(
|
||||
url, header, call
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}.start(wait = false)
|
||||
} catch (e: Exception) {
|
||||
SpiderDebug.log("start server e:" + e.message)
|
||||
++port
|
||||
ser?.stop()
|
||||
}
|
||||
} while (port < 13000)
|
||||
}
|
||||
|
||||
/** 启动服务器 */
|
||||
fun start() {
|
||||
SpiderDebug.log("ktorServer start on $port")
|
||||
CoroutineScope(Dispatchers.IO).launch { server.start(true) }
|
||||
CoroutineScope(Dispatchers.IO).launch { init() }
|
||||
}
|
||||
|
||||
|
||||
/** 停止服务器 */
|
||||
fun stop() {
|
||||
server.stop(1_000, 2_000)
|
||||
ser?.stop(1_000, 2_000)
|
||||
}
|
||||
|
||||
fun buildProxyUrl(url: String, headers: Map<String, String>): String {
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
68e6ce9893966f1b033d592e0f93b2ea
|
||||
7610a4d16212252a8db5108551e7c9a7
|
||||
|
|
|
|||
|
|
@ -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": [
|
||||
{
|
||||
"name": "电视直播",
|
||||
|
|
|
|||
Loading…
Reference in New Issue