From 650b8a50fc67dae8cc1eb3186737b1ad20f74f44 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 14 Jun 2018 19:06:22 -0500 Subject: [PATCH] Add subscribe button to channel page --- src/invidious.cr | 8 ++++++++ src/views/channel.ecr | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index d3c563c8..71a0f0b6 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -939,6 +939,14 @@ get "/videoplayback*" do |env| end get "/channel/:ucid" do |env| + authorized = env.get? "authorized" + if authorized + sid = env.get("sid").as(String) + + subscriptions = PG_DB.query_one?("SELECT subscriptions FROM users WHERE id = $1", sid, as: Array(String)) + end + subscriptions ||= [] of String + ucid = env.params.url["ucid"] page = env.params.query["page"]?.try &.to_i diff --git a/src/views/channel.ecr b/src/views/channel.ecr index 857ad57a..e67dbfda 100644 --- a/src/views/channel.ecr +++ b/src/views/channel.ecr @@ -3,6 +3,27 @@ <% end %>

<%= author %>

+<% if authorized %> + <% if subscriptions.includes? ucid %> +

+ + Unsubscribe from <%= author %> + +

+ <% else %> +

+ + Subscribe to <%= author %> + +

+ <% end %> +<% else %> +

+ + Login to subscribe to <%= author %> + +

+<% end %> <% videos.each_slice(4) do |slice| %>
<% slice.each do |video| %>