mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-02 08:53:13 +05:30
Allow user to subscribe to playlist (#17)
This commit is contained in:
parent
750ef296c6
commit
5d8de5fde2
@ -846,8 +846,14 @@ get "/view_all_playlists" do |env|
|
||||
|
||||
user = user.as(User)
|
||||
|
||||
items = PG_DB.query_all("SELECT * FROM playlists WHERE author = $1 ORDER BY created", user.email, as: InvidiousPlaylist)
|
||||
items.map! do |item|
|
||||
items_created = PG_DB.query_all("SELECT * FROM playlists WHERE author = $1 AND id LIKE 'IV%' ORDER BY created", user.email, as: InvidiousPlaylist)
|
||||
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
|
||||
end
|
||||
@ -918,6 +924,25 @@ post "/create_playlist" do |env|
|
||||
env.redirect "/playlist?list=#{playlist.id}"
|
||||
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|
|
||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||
|
||||
@ -933,10 +958,6 @@ get "/delete_playlist" do |env|
|
||||
sid = sid.as(String)
|
||||
|
||||
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)
|
||||
if !playlist || playlist.author != user.email
|
||||
next env.redirect referer
|
||||
|
@ -277,6 +277,27 @@ def create_playlist(db, title, privacy, user)
|
||||
return playlist
|
||||
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)
|
||||
videos = [] of PlaylistVideo
|
||||
|
||||
|
@ -45,6 +45,12 @@
|
||||
<% 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="/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 %>
|
||||
<div class="pure-u-1-3"><a href="/feed/playlist/<%= plid %>"><i class="icon ion-logo-rss"></i></a></div>
|
||||
</div>
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<div class="pure-g h-box">
|
||||
<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 class="pure-u-1-3" style="text-align:right">
|
||||
<h3>
|
||||
@ -16,7 +16,21 @@
|
||||
</div>
|
||||
|
||||
<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| %>
|
||||
<%= rendered "components/item" %>
|
||||
<% end %>
|
||||
|
@ -102,7 +102,7 @@
|
||||
</p>
|
||||
|
||||
<% 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? %>
|
||||
<form data-onsubmit="return_false" class="pure-form pure-form-stacked" action="/playlist_ajax" method="post">
|
||||
<div class="pure-control-group">
|
||||
|
Loading…
Reference in New Issue
Block a user