@@ -49,7 +49,7 @@ suspend fun Routing.createCdnEndpoints() {
49
49
50
50
log.debug(" Configuring CDN endpoints..." )
51
51
val contents = storage.listAll()
52
- log.info (" Found ${contents.size} items to create as routes!" )
52
+ log.debug (" Found ${contents.size} items to create as routes!" )
53
53
54
54
for (content in contents) {
55
55
val name = if (storage.trailer is FilesystemStorageTrailer ) {
@@ -61,7 +61,7 @@ suspend fun Routing.createCdnEndpoints() {
61
61
}
62
62
63
63
log.debug(" Found route $name to register!" )
64
- get(name) {
64
+ get(" / $ name" ) {
65
65
callOnRoute(content, call, storage, name)
66
66
}
67
67
}
@@ -182,7 +182,7 @@ private suspend fun callOnRoute(
182
182
storage : StorageWrapper ,
183
183
name : String
184
184
) {
185
- val stream = storage.open(if (storage.trailer is FilesystemStorageTrailer ) " ./${ name.substring( 1 )} " else name)
185
+ val stream = storage.open(if (storage.trailer is FilesystemStorageTrailer ) " ./$name " else name)
186
186
if (stream == null ) {
187
187
call.respond(
188
188
HttpStatusCode .NotFound ,
@@ -220,28 +220,19 @@ private suspend fun callOnRoute(
220
220
221
221
val contentType = ContentType .parse(rawContentType)
222
222
val shouldDownload = when {
223
- call.request.queryParameters[" download" ] != null -> true
224
223
contentType.match(ContentType .Application .GZip ) -> true
225
224
contentType.match(ContentType .Application .OctetStream ) -> true
226
225
contentType.match(ContentType .Application .Zip ) -> true
227
226
else -> false
228
227
}
229
228
230
229
if (shouldDownload) {
231
- if (call.response.isCommitted) return
232
-
233
- call.response.header(
234
- HttpHeaders .ContentDisposition ,
235
- " attachment; filename=\" ${name.substring(1 ).split(" /" ).last()} \" "
236
- )
237
-
238
- // Close the stream so we don't memory leak
239
- withContext(Dispatchers .IO ) {
240
- stream.close()
230
+ if (! call.response.isCommitted) {
231
+ call.response.header(
232
+ HttpHeaders .ContentDisposition ,
233
+ " attachment; filename=\" ${name.split(" /" ).last()} \" "
234
+ )
241
235
}
242
-
243
- call.respond(HttpStatusCode .NoContent )
244
- return
245
236
}
246
237
247
238
// Check if it is an image, if so, let's do some image manipulation!
0 commit comments