diff options
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/App.kt | 15 | ||||
-rw-r--r-- | src/main/kotlin/DatabaseController.kt | 13 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index fb93564..d95c887 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -101,6 +101,11 @@ fun main() { * TODO: Fix possible security issue with "../" */ post("/upload/*", ::upload, roles(Roles.USER)) + + /** + * Deletes file + */ + post("/delete/*", ::delete, roles(Roles.USER)) } } @@ -300,6 +305,16 @@ fun setup(ctx: Context) { } /** + * Deletes the requested file + */ +fun delete(ctx: Context) { + if (getVerifiedUserId(ctx) > 0) { + File("$fileHome/${getVerifiedUserId(ctx)}/${ctx.splats()[0]}").delete() + // TODO: delete from database + } +} + +/** * Declares the roles in which a user can be in */ enum class Roles : Role { diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt index a89a719..74ddf70 100644 --- a/src/main/kotlin/DatabaseController.kt +++ b/src/main/kotlin/DatabaseController.kt @@ -223,6 +223,19 @@ class DatabaseController(dbFileLocation: String = "main.db") { } /** + * Removes the file from the database + */ + fun deleteFile(fileLocation: String, userId: Int) { + transaction { + try { + FileLocation.deleteWhere { FileLocation.location eq fileLocation and FileLocation. } + } catch (_: org.jetbrains.exposed.exceptions.ExposedSQLException) { + + } + } + } + + /** * Checks whether the site has been set up */ fun isSetup(): Boolean { |