diff options
author | Marvin Borner | 2019-04-15 15:21:23 +0200 |
---|---|---|
committer | Marvin Borner | 2019-04-15 15:21:23 +0200 |
commit | a2a12a1ccb32812fed425333843205697694c236 (patch) | |
tree | 58cc04985197d6f3a8bec92bdbe14adb91a7c699 /src | |
parent | 7ec0252d24e068fd63fe2dc35c8d1364dc58dba9 (diff) |
Added deletion of files from database
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/App.kt | 8 | ||||
-rw-r--r-- | src/main/kotlin/DatabaseController.kt | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index d95c887..a96aabe 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -308,9 +308,11 @@ 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 + val userId = getVerifiedUserId(ctx) + if (userId > 0) { + val path = "$fileHome/$userId/${ctx.splats()[0]}" + File(path).delete() + databaseController.deleteFile(path, userId) } } diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt index 74ddf70..783b387 100644 --- a/src/main/kotlin/DatabaseController.kt +++ b/src/main/kotlin/DatabaseController.kt @@ -228,9 +228,9 @@ class DatabaseController(dbFileLocation: String = "main.db") { fun deleteFile(fileLocation: String, userId: Int) { transaction { try { - FileLocation.deleteWhere { FileLocation.location eq fileLocation and FileLocation. } + FileLocation.deleteWhere { (FileLocation.location eq fileLocation) and (FileLocation.userId eq userId) } } catch (_: org.jetbrains.exposed.exceptions.ExposedSQLException) { - + log.warning("File does not exist!") } } } |