Merge pull request #1182 from DmitrySandalov/master
Allow user to subscribe to playlist (#17)
This commit is contained in:
commit
338dc3223c
|
@ -846,8 +846,14 @@ get "/view_all_playlists" do |env|
|
||||||
|
|
||||||
user = user.as(User)
|
user = user.as(User)
|
||||||
|
|
||||||
items = PG_DB.query_all("SELECT * FROM playlists WHERE author = $1 ORDER BY created", user.email, as: InvidiousPlaylist)
|
items_created = PG_DB.query_all("SELECT * FROM playlists WHERE author = $1 AND id LIKE 'IV%' ORDER BY created", user.email, as: InvidiousPlaylist)
|
||||||
items.map! do |item|
|
items_created.map! do |item|
|
||||||
|
item.author = ""
|
||||||
|
item
|
||||||
|
end
|
||||||
|
|
||||||
|
items_saved = PG_DB.query_all("SELECT * FROM playlists WHERE author = $1 AND id NOT LIKE 'IV%' ORDER BY created", user.email, as: InvidiousPlaylist)
|
||||||
|
items_saved.map! do |item|
|
||||||
item.author = ""
|
item.author = ""
|
||||||
item
|
item
|
||||||
end
|
end
|
||||||
|
@ -918,6 +924,25 @@ post "/create_playlist" do |env|
|
||||||
env.redirect "/playlist?list=#{playlist.id}"
|
env.redirect "/playlist?list=#{playlist.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/subscribe_playlist" do |env|
|
||||||
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||||
|
|
||||||
|
user = env.get? "user"
|
||||||
|
referer = get_referer(env)
|
||||||
|
|
||||||
|
if !user
|
||||||
|
next env.redirect "/"
|
||||||
|
end
|
||||||
|
|
||||||
|
user = user.as(User)
|
||||||
|
|
||||||
|
playlist_id = env.params.query["list"]
|
||||||
|
playlist = get_playlist(PG_DB, playlist_id, locale)
|
||||||
|
subscribe_playlist(PG_DB, user, playlist)
|
||||||
|
|
||||||
|
env.redirect "/playlist?list=#{playlist.id}"
|
||||||
|
end
|
||||||
|
|
||||||
get "/delete_playlist" do |env|
|
get "/delete_playlist" do |env|
|
||||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||||
|
|
||||||
|
@ -933,10 +958,6 @@ get "/delete_playlist" do |env|
|
||||||
sid = sid.as(String)
|
sid = sid.as(String)
|
||||||
|
|
||||||
plid = env.params.query["list"]?
|
plid = env.params.query["list"]?
|
||||||
if !plid || !plid.starts_with?("IV")
|
|
||||||
next env.redirect referer
|
|
||||||
end
|
|
||||||
|
|
||||||
playlist = PG_DB.query_one?("SELECT * FROM playlists WHERE id = $1", plid, as: InvidiousPlaylist)
|
playlist = PG_DB.query_one?("SELECT * FROM playlists WHERE id = $1", plid, as: InvidiousPlaylist)
|
||||||
if !playlist || playlist.author != user.email
|
if !playlist || playlist.author != user.email
|
||||||
next env.redirect referer
|
next env.redirect referer
|
||||||
|
|
|
@ -277,6 +277,27 @@ def create_playlist(db, title, privacy, user)
|
||||||
return playlist
|
return playlist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subscribe_playlist(db, user, playlist)
|
||||||
|
playlist = InvidiousPlaylist.new(
|
||||||
|
title: playlist.title.byte_slice(0, 150),
|
||||||
|
id: playlist.id,
|
||||||
|
author: user.email,
|
||||||
|
description: "", # Max 5000 characters
|
||||||
|
video_count: playlist.video_count,
|
||||||
|
created: Time.utc,
|
||||||
|
updated: playlist.updated,
|
||||||
|
privacy: PlaylistPrivacy::Private,
|
||||||
|
index: [] of Int64,
|
||||||
|
)
|
||||||
|
|
||||||
|
playlist_array = playlist.to_a
|
||||||
|
args = arg_array(playlist_array)
|
||||||
|
|
||||||
|
db.exec("INSERT INTO playlists VALUES (#{args})", args: playlist_array)
|
||||||
|
|
||||||
|
return playlist
|
||||||
|
end
|
||||||
|
|
||||||
def extract_playlist(plid, nodeset, index)
|
def extract_playlist(plid, nodeset, index)
|
||||||
videos = [] of PlaylistVideo
|
videos = [] of PlaylistVideo
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,12 @@
|
||||||
<% if playlist.is_a?(InvidiousPlaylist) && playlist.author == user.try &.email %>
|
<% if playlist.is_a?(InvidiousPlaylist) && playlist.author == user.try &.email %>
|
||||||
<div class="pure-u-1-3"><a href="/edit_playlist?list=<%= plid %>"><i class="icon ion-md-create"></i></a></div>
|
<div class="pure-u-1-3"><a href="/edit_playlist?list=<%= plid %>"><i class="icon ion-md-create"></i></a></div>
|
||||||
<div class="pure-u-1-3"><a href="/delete_playlist?list=<%= plid %>"><i class="icon ion-md-trash"></i></a></div>
|
<div class="pure-u-1-3"><a href="/delete_playlist?list=<%= plid %>"><i class="icon ion-md-trash"></i></a></div>
|
||||||
|
<% else %>
|
||||||
|
<% if PG_DB.query_one?("SELECT id FROM playlists WHERE id = $1", playlist.id, as: String).nil? %>
|
||||||
|
<div class="pure-u-1-3"><a href="/subscribe_playlist?list=<%= plid %>"><i class="icon ion-md-add"></i></a></div>
|
||||||
|
<% else %>
|
||||||
|
<div class="pure-u-1-3"><a href="/delete_playlist?list=<%= plid %>"><i class="icon ion-md-trash"></i></a></div>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="pure-u-1-3"><a href="/feed/playlist/<%= plid %>"><i class="icon ion-logo-rss"></i></a></div>
|
<div class="pure-u-1-3"><a href="/feed/playlist/<%= plid %>"><i class="icon ion-logo-rss"></i></a></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<div class="pure-g h-box">
|
<div class="pure-g h-box">
|
||||||
<div class="pure-u-2-3">
|
<div class="pure-u-2-3">
|
||||||
<h3><%= translate(locale, "`x` playlists", %(<span id="count">#{items.size}</span>)) %></h3>
|
<h3><%= translate(locale, "`x` created playlists", %(<span id="count">#{items_created.size}</span>)) %></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1-3" style="text-align:right">
|
<div class="pure-u-1-3" style="text-align:right">
|
||||||
<h3>
|
<h3>
|
||||||
|
@ -16,7 +16,21 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pure-g">
|
<div class="pure-g">
|
||||||
<% items.each_slice(4) do |slice| %>
|
<% items_created.each_slice(4) do |slice| %>
|
||||||
|
<% slice.each do |item| %>
|
||||||
|
<%= rendered "components/item" %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pure-g h-box">
|
||||||
|
<div class="pure-u-1">
|
||||||
|
<h3><%= translate(locale, "`x` saved playlists", %(<span id="count">#{items_saved.size}</span>)) %></h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pure-g">
|
||||||
|
<% items_saved.each_slice(4) do |slice| %>
|
||||||
<% slice.each do |item| %>
|
<% slice.each do |item| %>
|
||||||
<%= rendered "components/item" %>
|
<%= rendered "components/item" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<% if user %>
|
<% if user %>
|
||||||
<% playlists = PG_DB.query_all("SELECT id,title FROM playlists WHERE author = $1", user.email, as: {String, String}) %>
|
<% playlists = PG_DB.query_all("SELECT id,title FROM playlists WHERE author = $1 AND id LIKE 'IV%'", user.email, as: {String, String}) %>
|
||||||
<% if !playlists.empty? %>
|
<% if !playlists.empty? %>
|
||||||
<form data-onsubmit="return_false" class="pure-form pure-form-stacked" action="/playlist_ajax" method="post">
|
<form data-onsubmit="return_false" class="pure-form pure-form-stacked" action="/playlist_ajax" method="post">
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
|
|
Loading…
Reference in a new issue