-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c3d983
commit 3d3407d
Showing
20 changed files
with
297 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../src/commonMain/kotlin/me/nathanfallet/groupeminaste/controllers/files/FilesController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package me.nathanfallet.groupeminaste.controllers.files | ||
|
||
import io.ktor.http.* | ||
import io.ktor.http.content.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.request.* | ||
import kotlinx.datetime.Clock | ||
import me.nathanfallet.cloudflare.models.r2.Object | ||
import me.nathanfallet.groupeminaste.usecases.files.IListFilesUseCase | ||
import me.nathanfallet.groupeminaste.usecases.files.IUploadFileUseCase | ||
import me.nathanfallet.ktorx.models.responses.RedirectResponse | ||
|
||
class FilesController( | ||
private val listFilesUseCase: IListFilesUseCase, | ||
private val uploadFileUseCase: IUploadFileUseCase, | ||
) : IFilesController { | ||
|
||
override suspend fun list(): List<Object> = | ||
emptyList() //listFilesUseCase() // To get fixed in cloudflare-api-client | ||
|
||
override suspend fun upload(call: ApplicationCall): RedirectResponse { | ||
val multipart = call.receiveMultipart() | ||
multipart.forEachPart { part -> | ||
if (part is PartData.FileItem) { | ||
uploadFileUseCase( | ||
part.originalFileName ?: "file-${Clock.System.now()}", | ||
part.streamProvider(), | ||
part.contentType ?: ContentType.Application.OctetStream | ||
) | ||
} | ||
part.dispose() | ||
} | ||
return RedirectResponse("files") | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...kend/src/commonMain/kotlin/me/nathanfallet/groupeminaste/controllers/files/FilesRouter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.nathanfallet.groupeminaste.controllers.files | ||
|
||
import me.nathanfallet.groupeminaste.controllers.models.AdminUnitRouter | ||
import me.nathanfallet.groupeminaste.usecases.web.IGetAdminMenuForCallUseCase | ||
import me.nathanfallet.ktorx.usecases.localization.IGetLocaleForCallUseCase | ||
import me.nathanfallet.usecases.localization.ITranslateUseCase | ||
|
||
class FilesRouter( | ||
controller: IFilesController, | ||
getLocaleForCallUseCase: IGetLocaleForCallUseCase, | ||
translateUseCase: ITranslateUseCase, | ||
getAdminMenuForCallUseCase: IGetAdminMenuForCallUseCase, | ||
) : AdminUnitRouter( | ||
controller, | ||
IFilesController::class, | ||
getLocaleForCallUseCase, | ||
translateUseCase, | ||
getAdminMenuForCallUseCase, | ||
route = "files" | ||
) | ||
|
21 changes: 21 additions & 0 deletions
21
...src/commonMain/kotlin/me/nathanfallet/groupeminaste/controllers/files/IFilesController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.nathanfallet.groupeminaste.controllers.files | ||
|
||
import io.ktor.server.application.* | ||
import me.nathanfallet.cloudflare.models.r2.Object | ||
import me.nathanfallet.ktorx.controllers.IUnitController | ||
import me.nathanfallet.ktorx.models.annotations.AdminTemplateMapping | ||
import me.nathanfallet.ktorx.models.annotations.ListModelPath | ||
import me.nathanfallet.ktorx.models.annotations.Path | ||
import me.nathanfallet.ktorx.models.responses.RedirectResponse | ||
|
||
interface IFilesController : IUnitController { | ||
|
||
@AdminTemplateMapping("admin/files/list.ftl") | ||
@ListModelPath | ||
suspend fun list(): List<Object> | ||
|
||
@AdminTemplateMapping("admin/files/list.ftl") | ||
@Path("POST", "/") | ||
suspend fun upload(call: ApplicationCall): RedirectResponse | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...d/src/commonMain/kotlin/me/nathanfallet/groupeminaste/usecases/files/IListFilesUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package me.nathanfallet.groupeminaste.usecases.files | ||
|
||
import me.nathanfallet.cloudflare.models.r2.Object | ||
import me.nathanfallet.usecases.base.IUnitSuspendUseCase | ||
|
||
interface IListFilesUseCase : IUnitSuspendUseCase<List<Object>> |
7 changes: 7 additions & 0 deletions
7
.../src/commonMain/kotlin/me/nathanfallet/groupeminaste/usecases/files/IUploadFileUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.nathanfallet.groupeminaste.usecases.files | ||
|
||
import io.ktor.http.* | ||
import me.nathanfallet.cloudflare.models.r2.InputStream | ||
import me.nathanfallet.usecases.base.ITripleSuspendUseCase | ||
|
||
interface IUploadFileUseCase : ITripleSuspendUseCase<String, InputStream, ContentType, Unit> |
13 changes: 13 additions & 0 deletions
13
...nd/src/commonMain/kotlin/me/nathanfallet/groupeminaste/usecases/files/ListFilesUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.nathanfallet.groupeminaste.usecases.files | ||
|
||
import me.nathanfallet.cloudflare.models.r2.Object | ||
import me.nathanfallet.cloudflare.r2.IR2Client | ||
|
||
class ListFilesUseCase( | ||
private val r2Client: IR2Client, | ||
private val bucket: String, | ||
) : IListFilesUseCase { | ||
|
||
override suspend fun invoke(): List<Object> = r2Client.listObjectsV2(bucket).contents | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...d/src/commonMain/kotlin/me/nathanfallet/groupeminaste/usecases/files/UploadFileUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package me.nathanfallet.groupeminaste.usecases.files | ||
|
||
import io.ktor.http.* | ||
import me.nathanfallet.cloudflare.client.ICloudflareClient | ||
import me.nathanfallet.cloudflare.models.r2.InputStream | ||
import me.nathanfallet.cloudflare.r2.IR2Client | ||
|
||
class UploadFileUseCase( | ||
private val r2Client: IR2Client, | ||
private val cloudflareClient: ICloudflareClient, | ||
private val bucket: String, | ||
) : IUploadFileUseCase { | ||
|
||
override suspend fun invoke(input1: String, input2: InputStream, input3: ContentType) { | ||
r2Client.putObject(bucket, input1, input2, input3) | ||
cloudflareClient.zones.purgeCache( | ||
"72356ace5c6fddc79486e6aedab34eb7", | ||
listOf("https://cdn.groupe-minaste.org/${input1.removePrefix("/")}") | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
groupeminaste-backend/src/commonMain/resources/templates/admin/files/list.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<#import "../template.ftl" as template> | ||
<@template.page> | ||
<div class="container-fluid py-4"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div class="card card-body"> | ||
<form action="/${locale}/admin/files" class="form-control dropzone" id="dropzone"> | ||
<div class="fallback"> | ||
<input name="file" type="file" multiple/> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="card mt-4"> | ||
<div class="table-responsive"> | ||
<table class="table table-flush" id="datatable-search"> | ||
<thead class="thead-light"> | ||
<tr> | ||
<th><@t key="admin_files_key" /></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<#list items as file> | ||
<tr> | ||
<td class="font-weight-bold"> | ||
<span class="my-2 text-xs"><a href="https://cdn.groupe-minaste.org/${file.key}">https://cdn.groupe-minaste.org/${file.key}</a></span> | ||
</td> | ||
</tr> | ||
</#list> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@3.0.2/dist/umd/simple-datatables.js"></script> | ||
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script> | ||
<script> | ||
const dataTableSearch = new simpleDatatables.DataTable("#datatable-search", { | ||
searchable: true, | ||
fixedHeight: false, | ||
perPageSelect: false | ||
}); | ||
Dropzone.autoDiscover = false; | ||
var drop = document.getElementById('dropzone') | ||
var myDropzone = new Dropzone(drop, { | ||
url: "/${locale}/admin/files", | ||
addRemoveLinks: true | ||
}); | ||
</script> | ||
</@template.page> |
Oops, something went wrong.