|
|
@ -270,20 +270,24 @@ get "/" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
get "/watch" do |env|
|
|
|
|
get "/watch" do |env|
|
|
|
|
|
|
|
|
if env.params.query["v"]?
|
|
|
|
|
|
|
|
id = env.params.query["v"]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
next env.redirect "/"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
user = env.get? "user"
|
|
|
|
user = env.get? "user"
|
|
|
|
if user
|
|
|
|
if user
|
|
|
|
user = user.as(User)
|
|
|
|
user = user.as(User)
|
|
|
|
|
|
|
|
if user.watched != ["N/A"] && !user.watched.includes? id
|
|
|
|
|
|
|
|
PG_DB.exec("UPDATE users SET watched = watched || $1 WHERE id = $2", [id], user.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
preferences = user.preferences
|
|
|
|
preferences = user.preferences
|
|
|
|
subscriptions = user.subscriptions.as(Array(String))
|
|
|
|
subscriptions = user.subscriptions.as(Array(String))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
subscriptions ||= [] of String
|
|
|
|
subscriptions ||= [] of String
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["v"]?
|
|
|
|
|
|
|
|
id = env.params.query["v"]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
next env.redirect "/"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
autoplay = env.params.query["autoplay"]?.try &.to_i
|
|
|
|
autoplay = env.params.query["autoplay"]?.try &.to_i
|
|
|
|
video_loop = env.params.query["video_loop"]?.try &.to_i
|
|
|
|
video_loop = env.params.query["video_loop"]?.try &.to_i
|
|
|
|
|
|
|
|
|
|
|
@ -1618,8 +1622,12 @@ post "/login" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
sid = Base64.encode(Random::Secure.random_bytes(50))
|
|
|
|
sid = Base64.encode(Random::Secure.random_bytes(50))
|
|
|
|
user = create_user(sid, email, password)
|
|
|
|
user = create_user(sid, email, password)
|
|
|
|
|
|
|
|
if user.watched = ["N/A"]
|
|
|
|
|
|
|
|
user_array = user.to_a[0..-2]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
user_array = user.to_a
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
user_array = user.to_a
|
|
|
|
|
|
|
|
user_array[5] = user_array[5].to_json
|
|
|
|
user_array[5] = user_array[5].to_json
|
|
|
|
args = arg_array(user_array)
|
|
|
|
args = arg_array(user_array)
|
|
|
|
|
|
|
|
|
|
|
@ -1719,6 +1727,10 @@ post "/preferences" do |env|
|
|
|
|
latest_only ||= "off"
|
|
|
|
latest_only ||= "off"
|
|
|
|
latest_only = latest_only == "on"
|
|
|
|
latest_only = latest_only == "on"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unseen_only = env.params.body["unseen_only"]?.try &.as(String)
|
|
|
|
|
|
|
|
unseen_only ||= "off"
|
|
|
|
|
|
|
|
unseen_only = unseen_only == "on"
|
|
|
|
|
|
|
|
|
|
|
|
preferences = {
|
|
|
|
preferences = {
|
|
|
|
"video_loop" => video_loop,
|
|
|
|
"video_loop" => video_loop,
|
|
|
|
"autoplay" => autoplay,
|
|
|
|
"autoplay" => autoplay,
|
|
|
@ -1732,6 +1744,7 @@ post "/preferences" do |env|
|
|
|
|
"max_results" => max_results,
|
|
|
|
"max_results" => max_results,
|
|
|
|
"sort" => sort,
|
|
|
|
"sort" => sort,
|
|
|
|
"latest_only" => latest_only,
|
|
|
|
"latest_only" => latest_only,
|
|
|
|
|
|
|
|
"unseen_only" => unseen_only,
|
|
|
|
}.to_json
|
|
|
|
}.to_json
|
|
|
|
|
|
|
|
|
|
|
|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
|
|
|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
|
|
@ -1773,14 +1786,41 @@ get "/feed/subscriptions" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if preferences.latest_only
|
|
|
|
if preferences.latest_only
|
|
|
|
args = arg_array(user.subscriptions)
|
|
|
|
if preferences.unseen_only
|
|
|
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE \
|
|
|
|
ucids = arg_array(user.subscriptions)
|
|
|
|
ucid IN (#{args}) ORDER BY ucid, published DESC", user.subscriptions, as: ChannelVideo)
|
|
|
|
if user.watched.empty?
|
|
|
|
|
|
|
|
watched = "'{}'"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
watched = arg_array(user.watched, user.subscriptions.size + 1)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE \
|
|
|
|
|
|
|
|
ucid IN (#{ucids}) AND id NOT IN (#{watched}) ORDER BY ucid, published DESC",
|
|
|
|
|
|
|
|
user.subscriptions + user.watched, as: ChannelVideo)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
args = arg_array(user.subscriptions)
|
|
|
|
|
|
|
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE \
|
|
|
|
|
|
|
|
ucid IN (#{args}) ORDER BY ucid, published DESC", user.subscriptions, as: ChannelVideo)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
videos.sort_by! { |video| video.published }.reverse!
|
|
|
|
videos.sort_by! { |video| video.published }.reverse!
|
|
|
|
else
|
|
|
|
else
|
|
|
|
args = arg_array(user.subscriptions, 3)
|
|
|
|
if preferences.unseen_only
|
|
|
|
videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{args}) \
|
|
|
|
ucids = arg_array(user.subscriptions, 3)
|
|
|
|
ORDER BY published DESC LIMIT $1 OFFSET $2", [limit, offset] + user.subscriptions, as: ChannelVideo)
|
|
|
|
if user.watched.empty?
|
|
|
|
|
|
|
|
watched = "'{}'"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
watched = arg_array(user.watched, user.subscriptions.size + 3)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{ucids}) \
|
|
|
|
|
|
|
|
AND id NOT IN (#{watched}) ORDER BY published DESC LIMIT $1 OFFSET $2",
|
|
|
|
|
|
|
|
[limit, offset] + user.subscriptions + user.watched, as: ChannelVideo)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
args = arg_array(user.subscriptions, 3)
|
|
|
|
|
|
|
|
videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{args}) \
|
|
|
|
|
|
|
|
ORDER BY published DESC LIMIT $1 OFFSET $2", [limit, offset] + user.subscriptions, as: ChannelVideo)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
case preferences.sort
|
|
|
|
case preferences.sort
|
|
|
@ -2167,6 +2207,20 @@ get "/subscription_ajax" do |env|
|
|
|
|
env.redirect referer
|
|
|
|
env.redirect referer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/clear_watch_history" do |env|
|
|
|
|
|
|
|
|
user = env.get? "user"
|
|
|
|
|
|
|
|
referer = env.request.headers["referer"]?
|
|
|
|
|
|
|
|
referer ||= "/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if user
|
|
|
|
|
|
|
|
user = user.as(User)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PG_DB.exec("UPDATE users SET watched = '{}' WHERE id = $1", user.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env.redirect referer
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
get "/user/:user" do |env|
|
|
|
|
get "/user/:user" do |env|
|
|
|
|
user = env.params.url["user"]
|
|
|
|
user = env.params.url["user"]
|
|
|
|
env.redirect "/channel/#{user}"
|
|
|
|
env.redirect "/channel/#{user}"
|
|
|
|