diff options
| author | Omar Roth <omarroth@protonmail.com> | 2019-04-30 21:01:57 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@protonmail.com> | 2019-04-30 21:01:57 -0500 |
| commit | 8a525bc13109e9bee3a59d3082d763f91b1dc7f6 (patch) | |
| tree | a25e9a7ef86d467c5a8ea1454240dc51130ce136 | |
| parent | 734905d1f7b0dd3fd0417b91d28b2a3ec132b124 (diff) | |
| download | invidious-8a525bc13109e9bee3a59d3082d763f91b1dc7f6.tar.gz invidious-8a525bc13109e9bee3a59d3082d763f91b1dc7f6.tar.bz2 invidious-8a525bc13109e9bee3a59d3082d763f91b1dc7f6.zip | |
Add '/api/v1/auth/preferences'
| -rw-r--r-- | src/invidious.cr | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 2e031c7d..98c18b55 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -4388,15 +4388,26 @@ get "/api/v1/auth/notifications" do |env| end end -# TODO -# get "/api/v1/auth/preferences" do |env| -# ... -# end +get "/api/v1/auth/preferences" do |env| + env.response.content_type = "application/json" + user = env.get("user").as(User) + user.preferences.to_json +end -# TODO -# post "/api/v1/auth/preferences" do |env| -# ... -# end +post "/api/v1/auth/preferences" do |env| + env.response.content_type = "application/json" + user = env.get("user").as(User) + + begin + preferences = Preferences.from_json(env.request.body || "{}") + rescue + preferences = user.preferences + end + + PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email) + + env.response.status_code = 204 +end get "/api/v1/auth/subscriptions" do |env| env.response.content_type = "application/json" |
