gt22

Untitled

Jun 10th, 2019
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.17 KB | None | 0 0
  1. import api.AttachmentsApi.attachments
  2. import api.ITHApi.ith
  3. import api.MusicApi.music
  4. import api.QuoterApi.quoter
  5. import api.quoterv2.QuoterV2Api.quoterV2
  6. import com.google.common.hash.Hashing
  7. import com.gt22.uadam.utils.obj
  8. import com.gt22.uadam.utils.str
  9. import io.ktor.application.install
  10. import io.ktor.features.ContentNegotiation
  11. import io.ktor.gson.gson
  12. import io.ktor.http.content.files
  13. import io.ktor.http.content.static
  14. import io.ktor.routing.route
  15. import io.ktor.routing.routing
  16. import io.ktor.server.engine.embeddedServer
  17. import io.ktor.server.netty.Netty
  18. import org.jetbrains.exposed.sql.Database
  19. import utils.jsonParser
  20. import web.QuoterWeb.quoterWeb
  21. import java.io.File
  22. import java.nio.charset.StandardCharsets
  23.  
  24. object Core {
  25.  
  26.     val config =  jsonParser.parse(File("config.json").readText()).obj
  27.     private val connectUrl = "jdbc:mysql://${config["host"]!!.str}:3306/${config["database"]!!.str}?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=UTC"
  28.  
  29.     @JvmStatic
  30.     fun main(args: Array<String>) {
  31.        
  32.     }
  33.    
  34.     @JvmStatic
  35.     fun _main(args: Array<String>) {
  36.  
  37.         val server = embeddedServer(Netty, 6741){
  38.             install(ContentNegotiation) {
  39.                 gson {
  40.                     setPrettyPrinting()
  41.                 }
  42.             }
  43.             routing{
  44.                 route("api") {
  45.                     quoter()
  46.                     ith()
  47.                     music()
  48.  
  49.                     route ("v2") {
  50.                         attachments()
  51.                         quoterV2()
  52.                     }
  53.                 }
  54.                 route("web") {
  55.                     quoterWeb()
  56.                 }
  57.                 static("static") {
  58.                     files("styles")
  59.                 }
  60.             }
  61.         }
  62.         Database.connect(connectUrl, "com.mysql.cj.jdbc.Driver", config["user"]!!.str, config["pass"]!!.str)
  63.         server.start(wait = true)
  64.     }
  65.  
  66.     fun verifyKey(key: String): Boolean {
  67.         return Hashing.sha256().hashString(key, StandardCharsets.UTF_8).toString() ==
  68.                 "bf077926f1f26e2e3552001461c1e51ec078c7d488f1519bd570cc86f0efeb1a"
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment