Skip to content

Commit

Permalink
Version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
DanThrane committed Jul 18, 2024
1 parent 209a41f commit 8e83f8f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.1.43
2024.1.44
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,37 @@ class FileController(
})

server.addHandler(FilesDownloadIpc.register.handler { user, request ->
val ucloudIdentity = if (controllerContext.configuration.core.launchRealUserInstances) {
val uidToUse = if (controllerContext.configuration.core.launchRealUserInstances) {
UserMapping.localIdToUCloudId(user.uid) ?: throw RPCException("Unknown user", HttpStatusCode.BadRequest)
user.uid
} else {
null
0
}

dbConnection.withSession { session ->
session.prepareStatement(
"""
insert into file_download_sessions(session, plugin_name, plugin_data)
values (:session, :plugin_name, :plugin_data)
insert into file_download_sessions(session, plugin_name, plugin_data, owned_by)
values (:session, :plugin_name, :plugin_data, :uid)
"""
).useAndInvokeAndDiscard(
prepare = {
bindString("session", request.session)
bindString("plugin_name", request.pluginName)
bindString("plugin_data", request.pluginData)
bindInt("uid", uidToUse)
}
)
}
})

server.addHandler(FilesDownloadIpc.retrieve.handler { _, request ->
server.addHandler(FilesDownloadIpc.retrieve.handler { user, request ->
val uidToUse = if (controllerContext.configuration.core.launchRealUserInstances) {
user.uid
} else {
0
}

var result: FileSessionWithPlugin? = null
dbConnection.withSession { session ->
session.prepareStatement(
Expand All @@ -179,10 +187,12 @@ class FileController(
from file_download_sessions
where
session = :token
and owned_by = :uid
"""
).useAndInvoke(
prepare = {
bindString("token", request.id)
bindInt("uid", uidToUse)
},
readRow = { row ->
val pluginName = row.getString(0)!!
Expand All @@ -196,29 +206,37 @@ class FileController(
})

server.addHandler(FilesUploadIpc.register.handler { user, request ->
val ucloudIdentity = if (controllerContext.configuration.core.launchRealUserInstances) {
val uidToSave = if (controllerContext.configuration.core.launchRealUserInstances) {
UserMapping.localIdToUCloudId(user.uid) ?: throw RPCException("Unknown user", HttpStatusCode.BadRequest)
user.uid
} else {
null
0
}

dbConnection.withSession { session ->
session.prepareStatement(
"""
insert into file_upload_sessions(session, plugin_name, plugin_data)
values (:session, :plugin_name, :plugin_data)
insert into file_upload_sessions(session, plugin_name, plugin_data, owned_by)
values (:session, :plugin_name, :plugin_data, :uid)
"""
).useAndInvokeAndDiscard(
prepare = {
bindString("session", request.session)
bindString("plugin_name", request.pluginName)
bindString("plugin_data", request.pluginData)
bindInt("uid", uidToSave)
}
)
}
})

server.addHandler(FilesUploadIpc.retrieve.handler { _, request ->
server.addHandler(FilesUploadIpc.retrieve.handler { user, request ->
val uidToUse = if (controllerContext.configuration.core.launchRealUserInstances) {
user.uid
} else {
0
}

var result: FileSessionWithPlugin? = null
dbConnection.withSession { session ->
session.prepareStatement(
Expand All @@ -227,10 +245,12 @@ class FileController(
from file_upload_sessions
where
session = :token
and owned_by = :uid
"""
).useAndInvoke(
prepare = {
bindString("token", request.id)
bindInt("uid", uidToUse)
},
readRow = { row ->
val pluginName = row.getString(0)!!
Expand All @@ -240,21 +260,28 @@ class FileController(
)
}


result ?: throw RPCException("Invalid token supplied", HttpStatusCode.NotFound)
})

server.addHandler(FilesUploadIpc.delete.handler { _, request ->
server.addHandler(FilesUploadIpc.delete.handler { user, request ->
val uidToUse = if (controllerContext.configuration.core.launchRealUserInstances) {
user.uid
} else {
0
}

dbConnection.withSession { session ->
session.prepareStatement(
"""
delete from file_upload_sessions
where
session = :token
and owned_by = :uid
"""
).useAndInvokeAndDiscard(
prepare = {
bindString("token", request.id)
bindInt("uid", uidToUse)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ fun V1__FileDownloadSessions(): MigrationScript = MigrationScript("V1__FileDownl
"""
).useAndInvokeAndDiscard()
}

fun V2__FileDownloadSessions(): MigrationScript = MigrationScript("V2__FileDownloadSessions") { conn ->
conn.prepareStatement(
// language=postgresql
"""
alter table file_download_sessions add column owned_by int not null default 0;
"""
).useAndInvokeAndDiscard()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ fun V1__FileUploadSessions(): MigrationScript = MigrationScript("V1__FileUploadS
"""
).useAndInvokeAndDiscard()
}

fun V2__FileUploadSessions(): MigrationScript = MigrationScript("V2__FileUploadSessions") { conn ->
conn.prepareStatement(
// language=postgresql
"""
alter table file_upload_sessions add column owned_by int not null default 0;
"""
).useAndInvokeAndDiscard()
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ fun loadMigrations(migrationHandler: MigrationHandler) {
migrationHandler.addScript(V2__Events())
migrationHandler.addScript(V3__Events())
migrationHandler.addScript(V3__UserMapping())
migrationHandler.addScript(V2__FileUploadSessions())
migrationHandler.addScript(V2__FileDownloadSessions())
}

0 comments on commit 8e83f8f

Please sign in to comment.