More buttons

This commit is contained in:
2020-08-22 03:23:24 +02:00
parent 7d833e48e1
commit 2ac02688ab
2 changed files with 9 additions and 2 deletions
@@ -50,10 +50,16 @@ class SettingsController(
}
fun export(request: Request, jwtPayload: JwtPayload): Response {
val isDownload = request.form("download") != null
val json = userService.export(jwtPayload.userId)
return Response(Status.OK).body(json).header("Content-Type", "application/json")
val res = Response(Status.OK).body(json).header("Content-Type", "application/json")
return if (isDownload) res.header("Content-Disposition",
"attachment; filename=\"simplenotes-export-${sanitizeFilename(jwtPayload.username)}.json\"")
else res
}
private fun sanitizeFilename(inputName: String): String = inputName.replace("[^a-zA-Z0-9-_.]".toRegex(), "_")
private fun Request.deleteForm(jwtPayload: JwtPayload) =
DeleteForm(jwtPayload.username, form("password"), form("checked") != null)
}