Skip to content

Commit d896a14

Browse files
committed
chore: migrate from dev.floofy.hazel.extensions -> dev.floofy.utils, use Noelware ktor-routing than our own impl.
1 parent 6e029ac commit d896a14

File tree

14 files changed

+36
-217
lines changed

14 files changed

+36
-217
lines changed

src/main/kotlin/dev/floofy/hazel/Bootstrap.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import com.akuleshov7.ktoml.Toml
2121
import com.akuleshov7.ktoml.TomlConfig
2222
import dev.floofy.hazel.core.StorageWrapper
2323
import dev.floofy.hazel.data.Config
24-
import dev.floofy.hazel.extensions.inject
2524
import dev.floofy.hazel.routing.endpoints.endpointsModule
25+
import dev.floofy.utils.koin.inject
26+
import dev.floofy.utils.kotlin.*
2627
import dev.floofy.utils.slf4j.*
2728
import kotlinx.coroutines.runBlocking
2829
import kotlinx.serialization.json.Json

src/main/kotlin/dev/floofy/hazel/Hazel.kt

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ package dev.floofy.hazel
2020
import dev.floofy.hazel.core.Ticker
2121
import dev.floofy.hazel.core.createThreadFactory
2222
import dev.floofy.hazel.data.Config
23-
import dev.floofy.hazel.extensions.formatSize
24-
import dev.floofy.hazel.extensions.inject
25-
import dev.floofy.hazel.extensions.retrieveAll
2623
import dev.floofy.hazel.plugins.KtorLoggingPlugin
2724
import dev.floofy.hazel.plugins.UserAgentPlugin
28-
import dev.floofy.hazel.routing.AbstractEndpoint
2925
import dev.floofy.hazel.routing.createCdnEndpoints
30-
import dev.floofy.utils.koin.retrieve
26+
import dev.floofy.utils.koin.*
27+
import dev.floofy.utils.kotlin.*
3128
import dev.floofy.utils.slf4j.*
3229
import io.ktor.http.*
3330
import io.ktor.serialization.kotlinx.json.*
@@ -43,11 +40,12 @@ import io.ktor.server.request.*
4340
import io.ktor.server.response.*
4441
import io.ktor.server.routing.*
4542
import io.sentry.Sentry
46-
import kotlinx.coroutines.runBlocking
4743
import kotlinx.serialization.json.buildJsonArray
4844
import kotlinx.serialization.json.buildJsonObject
4945
import kotlinx.serialization.json.put
5046
import org.koin.core.context.GlobalContext
47+
import org.noelware.ktor.NoelKtorRoutingPlugin
48+
import org.noelware.ktor.loader.koin.KoinEndpointLoader
5149
import org.slf4j.LoggerFactory
5250
import java.lang.management.ManagementFactory
5351
import java.util.concurrent.ExecutorService
@@ -70,7 +68,7 @@ class Hazel {
7068

7169
log.info("+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+")
7270
log.info("Runtime Information:")
73-
log.info(" * Free / Total Memory [Max]: ${runtime.freeMemory().formatSize()}/${runtime.totalMemory().formatSize()} [${runtime.maxMemory().formatSize()}]")
71+
log.info(" * Free / Total Memory [Max]: ${runtime.freeMemory().sizeToStr()}/${runtime.totalMemory().sizeToStr()} [${runtime.maxMemory().sizeToStr()}]")
7472
log.info(" * Threads: ${threads.threadCount} (${threads.daemonThreadCount} background threads)")
7573
log.info(" * Operating System: ${os.name} with ${os.availableProcessors} processors (${os.arch}; ${os.version})")
7674
log.info(" * Versions:")
@@ -201,32 +199,9 @@ class Hazel {
201199
}
202200
}
203201

204-
routing {
205-
self.log.debug("Registering file routes...")
206-
val s = this
207-
runBlocking {
208-
s.createCdnEndpoints()
209-
}
210-
211-
val endpoints = GlobalContext.retrieveAll<AbstractEndpoint>()
212-
self.log.info("Found ${endpoints.size} to register!")
213-
214-
for (endpoint in endpoints) {
215-
self.log.debug("${endpoint.path} [${endpoint.methods.joinToString(", ") { it.value }}]")
216-
for (method in endpoint.methods) {
217-
if (self.routesRegistered.contains(Pair(method, endpoint.path))) {
218-
self.log.debug("Endpoint ${method.value} ${endpoint.path} is already registered.")
219-
continue
220-
}
221-
222-
self.routesRegistered.add(Pair(method, endpoint.path))
223-
route(endpoint.path, method) {
224-
handle {
225-
endpoint.call(call)
226-
}
227-
}
228-
}
229-
}
202+
install(Routing)
203+
install(NoelKtorRoutingPlugin) {
204+
endpointLoader = KoinEndpointLoader
230205
}
231206
}
232207
}

src/main/kotlin/dev/floofy/hazel/extensions/FormatExtensions.kt

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/main/kotlin/dev/floofy/hazel/extensions/KoinExtensions.kt

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/main/kotlin/dev/floofy/hazel/extensions/KotlinExtensions.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/kotlin/dev/floofy/hazel/plugins/UserAgentPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package dev.floofy.hazel.plugins
1919

20-
import dev.floofy.hazel.extensions.ifNotNull
20+
import dev.floofy.utils.kotlin.*
2121
import io.ktor.server.application.*
2222
import io.ktor.server.request.*
2323
import org.slf4j.MDC

src/main/kotlin/dev/floofy/hazel/routing/AbstractEndpoint.kt

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/main/kotlin/dev/floofy/hazel/routing/RoutingExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package dev.floofy.hazel.routing
2020
import dev.floofy.hazel.HazelScope
2121
import dev.floofy.hazel.core.ImageManipulator
2222
import dev.floofy.hazel.core.StorageWrapper
23-
import dev.floofy.hazel.extensions.inject
23+
import dev.floofy.utils.koin.*
2424
import dev.floofy.utils.slf4j.logging
2525
import io.ktor.http.*
2626
import io.ktor.http.content.*

src/main/kotlin/dev/floofy/hazel/routing/endpoints/FaviconEndpoint.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515
* limitations under the License.
1616
*/
1717

18+
@file:Suppress("UNUSED")
1819
package dev.floofy.hazel.routing.endpoints
1920

20-
import dev.floofy.hazel.routing.AbstractEndpoint
2121
import io.ktor.http.*
2222
import io.ktor.server.application.*
2323
import io.ktor.server.response.*
24+
import org.noelware.ktor.endpoints.AbstractEndpoint
25+
import org.noelware.ktor.endpoints.Get
2426
import java.io.File
2527

2628
class FaviconEndpoint: AbstractEndpoint("/favicon.ico") {
27-
override suspend fun call(call: ApplicationCall) {
29+
@Get
30+
suspend fun call(call: ApplicationCall) {
2831
call.response.status(HttpStatusCode.OK)
2932
call.respondFile(File("./assets/feather.png"))
3033
}

src/main/kotlin/dev/floofy/hazel/routing/endpoints/HeartbeatEndpoint.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
* limitations under the License.
1616
*/
1717

18+
@file:Suppress("UNUSED")
1819
package dev.floofy.hazel.routing.endpoints
1920

20-
import dev.floofy.hazel.routing.AbstractEndpoint
2121
import io.ktor.http.*
2222
import io.ktor.server.application.*
2323
import io.ktor.server.response.*
24+
import org.noelware.ktor.endpoints.AbstractEndpoint
25+
import org.noelware.ktor.endpoints.Get
2426

2527
class HeartbeatEndpoint: AbstractEndpoint("/heartbeat") {
26-
override suspend fun call(call: ApplicationCall) {
28+
@Get
29+
suspend fun call(call: ApplicationCall) {
2730
call.respond(HttpStatusCode.OK, "OK")
2831
}
2932
}

0 commit comments

Comments
 (0)