Add '/api/v1/auth/subscriptions'

pull/508/head
Omar Roth 6 years ago
parent 64aecba7a0
commit 250860d92c

@ -1712,7 +1712,14 @@ get "/subscription_manager" do |env|
format = env.params.query["format"]? format = env.params.query["format"]?
format ||= "rss" format ||= "rss"
subscriptions = PG_DB.query_all("SELECT * FROM channels WHERE id = ANY('{#{user.subscriptions.join(",")}}')", as: InvidiousChannel) if user.subscriptions.empty?
values = "'{}'"
else
values = "VALUES #{user.subscriptions.map { |id| %(('#{id}')) }.join(",")}"
end
subscriptions = PG_DB.query_all("SELECT * FROM channels WHERE id = ANY(#{values})", as: InvidiousChannel)
subscriptions.sort_by! { |channel| channel.author.downcase } subscriptions.sort_by! { |channel| channel.author.downcase }
if action_takeout if action_takeout
@ -4263,20 +4270,54 @@ end
# ... # ...
# end # end
# TODO get "/api/v1/auth/subscriptions" do |env|
# get "/api/v1/auth/subscriptions" do |env| env.response.content_type = "application/json"
# ... user = env.get("user").as(User)
# end
# TODO if user.subscriptions.empty?
# post "/api/v1/auth/subscriptions/:ucid" do |env| values = "'{}'"
# ... else
# end values = "VALUES #{user.subscriptions.map { |id| %(('#{id}')) }.join(",")}"
end
# TODO subscriptions = PG_DB.query_all("SELECT * FROM channels WHERE id = ANY(#{values})", as: InvidiousChannel)
# delete "/api/v1/auth/subscriptions/:ucid" do |env|
# ... JSON.build do |json|
# end json.array do
subscriptions.each do |subscription|
json.object do
json.field "author", subscription.author
json.field "authorId", subscription.id
end
end
end
end
end
post "/api/v1/auth/subscriptions/:ucid" do |env|
env.response.content_type = "application/json"
user = env.get("user").as(User)
ucid = env.params.url["ucid"]
if !user.subscriptions.includes? ucid
get_channel(ucid, PG_DB, false, false)
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
end
env.response.status_code = 204
end
delete "/api/v1/auth/subscriptions/:ucid" do |env|
env.response.content_type = "application/json"
user = env.get("user").as(User)
ucid = env.params.url["ucid"]
PG_DB.exec("UPDATE users SET subscriptions = array_remove(subscriptions,$1) WHERE email = $2", ucid, user.email)
env.response.status_code = 204
end
get "/api/v1/auth/tokens" do |env| get "/api/v1/auth/tokens" do |env|
env.response.content_type = "application/json" env.response.content_type = "application/json"

Loading…
Cancel
Save