@@ -4,10 +4,12 @@ import com.sksamuel.aedile.core.LoadingCache
44import io.github.oshai.kotlinlogging.KotlinLogging.logger
55import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
66import io.github.typesafegithub.workflows.actionbindinggenerator.domain.prettyPrintWithoutVersion
7+ import io.ktor.http.HttpStatusCode
78import io.ktor.server.response.respondText
89import io.ktor.server.routing.Route
910import io.ktor.server.routing.Routing
1011import io.ktor.server.routing.get
12+ import io.ktor.server.routing.head
1113import io.ktor.server.routing.route
1214import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics
1315import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
@@ -25,15 +27,41 @@ fun Routing.metadataRoutes(
2527 }
2628
2729 route(" {owner}/{name}/{file}" ) {
28- metadata(metadataCache)
30+ headMetadata(metadataCache)
31+ getMetadata(metadataCache)
2932 }
3033
3134 route(" /refresh/{owner}/{name}/{file}" ) {
32- metadata(metadataCache, refresh = true )
35+ headMetadata(metadataCache, refresh = true )
36+ getMetadata(metadataCache, refresh = true )
3337 }
3438}
3539
36- private fun Route.metadata (
40+ private fun Route.headMetadata (
41+ metadataCache : LoadingCache <ActionCoords , CachedMetadataArtifact >,
42+ refresh : Boolean = false,
43+ ) {
44+ head {
45+ val actionCoords = call.parameters.extractActionCoords(extractVersion = false )
46+
47+ if (refresh) {
48+ metadataCache.invalidate(actionCoords)
49+ }
50+ val metadataArtifacts = metadataCache.get(actionCoords)
51+
52+ if (refresh && ! deliverOnRefreshRoute) return @head call.respondText(text = " OK" )
53+
54+ val file = call.parameters[" file" ] ? : return @head call.respondNotFound()
55+
56+ if (file in metadataArtifacts) {
57+ call.respondText(text = " Exists" , status = HttpStatusCode .OK )
58+ } else {
59+ call.respondNotFound()
60+ }
61+ }
62+ }
63+
64+ private fun Route.getMetadata (
3765 metadataCache : LoadingCache <ActionCoords , CachedMetadataArtifact >,
3866 refresh : Boolean = false,
3967) {
0 commit comments