diff options
Diffstat (limited to 'src/main/kotlin/DatabaseController.kt')
-rw-r--r-- | src/main/kotlin/DatabaseController.kt | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt index b3fac60..6ec13e4 100644 --- a/src/main/kotlin/DatabaseController.kt +++ b/src/main/kotlin/DatabaseController.kt @@ -243,12 +243,12 @@ class DatabaseController(dbFileLocation: String = "main.db") { } /** - * Returns the accessId of the given File + * Returns the accessId of the given file */ fun getAccessId(fileLocation: String, userId: Int): String { return transaction { try { - FileLocation.update({ (FileLocation.userId eq userId) and (FileLocation.path eq fileLocation) }) { + FileLocation.update({ (FileLocation.userId eq userId) and (FileLocation.path like "$fileLocation%") }) { it[isShared] = true } FileLocation.select { (FileLocation.path eq fileLocation) and (FileLocation.userId eq userId) }.map { it[FileLocation.accessId] }[0] @@ -259,6 +259,23 @@ class DatabaseController(dbFileLocation: String = "main.db") { } /** + * Returns accessId of file in directory + */ + fun getAccessIdOfDirectory(fileName: String, accessId: String): String { + return transaction { + try { + val fileData = + FileLocation.select { FileLocation.accessId eq accessId }.map { it[FileLocation.path] to it[FileLocation.userId] to it[FileLocation.isShared] }[0] + if (fileData.second) + FileLocation.select { (FileLocation.path eq "${fileData.first.first}${fileName.substring(1)}") and (FileLocation.userId eq fileData.first.second) }.map { it[FileLocation.accessId] }[0] + else "" + } catch (_: Exception) { + "" + } + } + } + + /** * Gets the shared file via [accessId] */ fun getSharedFile(accessId: String): ReturnFileData { |