Skip to content

Commit

Permalink
Return NotFound instead of Error
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Jan 27, 2025
1 parent 45c091e commit 7662c05
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions webui/src/main/java/org/totschnig/webui/WebInputService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,16 @@ class WebInputService : LifecycleService(), IWebInputService {

get("/download/{file}") {
val appDir = AppDirHelper.getAppDir(this@WebInputService).getOrThrow()
val inputStream = contentResolver.openInputStream(
appDir.findFile(call.parameters["file"]!!)!!.uri.let {
AppDirHelper.ensureContentUri(it, this@WebInputService)
}
)!!
val channel = inputStream.toByteReadChannel()
call.respond(channel)
val file = appDir.findFile(call.parameters["file"]!!)?.uri?.let {
AppDirHelper.ensureContentUri(it, this@WebInputService)
}
if (file == null) {
call.respond(HttpStatusCode.NotFound, "File not found")
} else {
call.respond(
contentResolver.openInputStream(file)!!.toByteReadChannel()
)
}
}
}

Expand Down

0 comments on commit 7662c05

Please sign in to comment.