mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-24 12:02:39 +00:00
Remove files that were prematurely added and add backend Compilation files
This commit is contained in:
parent
bef234fd74
commit
6b984c6677
@ -627,11 +627,11 @@ default_user_preferences:
|
||||
##
|
||||
## Accepted values: A list of strings
|
||||
## Each entry can be one of: "Popular", "Trending",
|
||||
## "Subscriptions", "Playlists", "Compilations"
|
||||
## "Subscriptions", "Playlists"
|
||||
##
|
||||
## Default: ["Popular", "Trending", "Subscriptions", "Playlists", "Compilations"] (show all feeds)
|
||||
## Default: ["Popular", "Trending", "Subscriptions", "Playlists"] (show all feeds)
|
||||
##
|
||||
#feed_menu: ["Popular", "Trending", "Subscriptions", "Playlists", "Compilations"]
|
||||
#feed_menu: ["Popular", "Trending", "Subscriptions", "Playlists"]
|
||||
|
||||
##
|
||||
## Default feed to display on the home page.
|
||||
|
20
config/sql/compilation_videos.sql
Normal file
20
config/sql/compilation_videos.sql
Normal file
@ -0,0 +1,20 @@
|
||||
-- Table: public.compilation_videos
|
||||
|
||||
-- DROP TABLE public.compilation_videos;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.compilation_videos
|
||||
(
|
||||
title text,
|
||||
id text,
|
||||
author text,
|
||||
ucid text,
|
||||
length_seconds integer,
|
||||
starting_timestamp_seconds integer,
|
||||
ending_timestamp_seconds integer,
|
||||
published timestamptz,
|
||||
compid text references compilations(id),
|
||||
index int8,
|
||||
PRIMARY KEY (index,compid)
|
||||
);
|
||||
|
||||
GRANT ALL ON TABLE public.compilation_videos TO current_user;
|
@ -1,3 +1,13 @@
|
||||
-- Type: public.privacy
|
||||
|
||||
-- DROP TYPE public.privacy;
|
||||
|
||||
CREATE TYPE public.privacy AS ENUM
|
||||
(
|
||||
'Unlisted',
|
||||
'Private'
|
||||
);
|
||||
|
||||
-- Table: public.compilations
|
||||
|
||||
-- DROP TABLE public.compilations;
|
||||
@ -15,4 +25,4 @@ CREATE TABLE IF NOT EXISTS public.compilations
|
||||
index int8[]
|
||||
);
|
||||
|
||||
GRANT ALL ON public.playlists TO current_user;
|
||||
GRANT ALL ON public.compilations TO current_user;
|
||||
|
@ -413,7 +413,6 @@
|
||||
"Audio mode": "Audio mode",
|
||||
"Video mode": "Video mode",
|
||||
"Playlists": "Playlists",
|
||||
"Compilations": "Compilations",
|
||||
"search_filters_title": "Filters",
|
||||
"search_filters_date_label": "Upload date",
|
||||
"search_filters_date_option_none": "Any date",
|
||||
|
@ -8,7 +8,6 @@ require "../src/invidious/channels/*"
|
||||
require "../src/invidious/videos/caption"
|
||||
require "../src/invidious/videos"
|
||||
require "../src/invidious/playlists"
|
||||
require "../src/invidious/compilations"
|
||||
require "../src/invidious/search/ctoken"
|
||||
require "../src/invidious/trending"
|
||||
require "spectator"
|
||||
|
@ -1,14 +0,0 @@
|
||||
struct Compilation
|
||||
include DB::Serializable
|
||||
|
||||
property title : String
|
||||
property id : String
|
||||
property author : String
|
||||
property ucid : String
|
||||
property length_seconds : Int32
|
||||
property published : Time
|
||||
property plid : String
|
||||
property index : Int64
|
||||
property live_now : Bool
|
||||
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
require "./base.cr"
|
||||
|
||||
#
|
||||
# This module contains functions related to the "playlists" table.
|
||||
# This module contains functions related to the "compilations" table.
|
||||
#
|
||||
module Invidious::Database::Compilations
|
||||
extend self
|
||||
@ -10,22 +10,22 @@ module Invidious::Database::Compilations
|
||||
# Insert / delete
|
||||
# -------------------
|
||||
|
||||
def insert(playlist : InvidiousPlaylist)
|
||||
playlist_array = playlist.to_a
|
||||
def insert(compilation : InvidiousCompilation)
|
||||
compilation_array = compilation.to_a
|
||||
|
||||
request = <<-SQL
|
||||
INSERT INTO playlists
|
||||
VALUES (#{arg_array(playlist_array)})
|
||||
INSERT INTO compilations
|
||||
VALUES (#{arg_array(compilation_array)})
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, args: playlist_array)
|
||||
PG_DB.exec(request, args: compilation_array)
|
||||
end
|
||||
|
||||
# deletes the given playlist and connected playlist videos
|
||||
# deletes the given compilation and connected compilation videos
|
||||
def delete(id : String)
|
||||
PlaylistVideos.delete_by_playlist(id)
|
||||
CompilationVideos.delete_by_compilation(id)
|
||||
request = <<-SQL
|
||||
DELETE FROM playlists *
|
||||
DELETE FROM compilations *
|
||||
WHERE id = $1
|
||||
SQL
|
||||
|
||||
@ -38,7 +38,7 @@ module Invidious::Database::Compilations
|
||||
|
||||
def update(id : String, title : String, privacy, description, updated)
|
||||
request = <<-SQL
|
||||
UPDATE playlists
|
||||
UPDATE compilations
|
||||
SET title = $1, privacy = $2, description = $3, updated = $4
|
||||
WHERE id = $5
|
||||
SQL
|
||||
@ -48,7 +48,7 @@ module Invidious::Database::Compilations
|
||||
|
||||
def update_description(id : String, description)
|
||||
request = <<-SQL
|
||||
UPDATE playlists
|
||||
UPDATE compilations
|
||||
SET description = $1
|
||||
WHERE id = $2
|
||||
SQL
|
||||
@ -56,19 +56,9 @@ module Invidious::Database::Compilations
|
||||
PG_DB.exec(request, description, id)
|
||||
end
|
||||
|
||||
def update_subscription_time(id : String)
|
||||
request = <<-SQL
|
||||
UPDATE playlists
|
||||
SET subscribed = now()
|
||||
WHERE id = $1
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, id)
|
||||
end
|
||||
|
||||
def update_video_added(id : String, index : String | Int64)
|
||||
request = <<-SQL
|
||||
UPDATE playlists
|
||||
UPDATE compilations
|
||||
SET index = array_append(index, $1),
|
||||
video_count = cardinality(index) + 1,
|
||||
updated = now()
|
||||
@ -80,7 +70,7 @@ module Invidious::Database::Compilations
|
||||
|
||||
def update_video_removed(id : String, index : String | Int64)
|
||||
request = <<-SQL
|
||||
UPDATE playlists
|
||||
UPDATE compilations
|
||||
SET index = array_remove(index, $1),
|
||||
video_count = cardinality(index) - 1,
|
||||
updated = now()
|
||||
@ -94,51 +84,51 @@ module Invidious::Database::Compilations
|
||||
# Salect
|
||||
# -------------------
|
||||
|
||||
def select(*, id : String) : InvidiousPlaylist?
|
||||
def select(*, id : String) : InvidiousCompilation?
|
||||
request = <<-SQL
|
||||
SELECT * FROM playlists
|
||||
SELECT * FROM compilations
|
||||
WHERE id = $1
|
||||
SQL
|
||||
|
||||
return PG_DB.query_one?(request, id, as: InvidiousPlaylist)
|
||||
return PG_DB.query_one?(request, id, as: InvidiousCompilation)
|
||||
end
|
||||
|
||||
def select_all(*, author : String) : Array(InvidiousPlaylist)
|
||||
def select_all(*, author : String) : Array(InvidiousCompilation)
|
||||
request = <<-SQL
|
||||
SELECT * FROM playlists
|
||||
SELECT * FROM compilations
|
||||
WHERE author = $1
|
||||
SQL
|
||||
|
||||
return PG_DB.query_all(request, author, as: InvidiousPlaylist)
|
||||
return PG_DB.query_all(request, author, as: InvidiousCompilation)
|
||||
end
|
||||
|
||||
# -------------------
|
||||
# Salect (filtered)
|
||||
# -------------------
|
||||
|
||||
def select_like_iv(email : String) : Array(InvidiousPlaylist)
|
||||
def select_like_iv(email : String) : Array(InvidiousCompilation)
|
||||
request = <<-SQL
|
||||
SELECT * FROM playlists
|
||||
SELECT * FROM compilation
|
||||
WHERE author = $1 AND id LIKE 'IV%'
|
||||
ORDER BY created
|
||||
SQL
|
||||
|
||||
PG_DB.query_all(request, email, as: InvidiousPlaylist)
|
||||
PG_DB.query_all(request, email, as: InvidiousCompilation)
|
||||
end
|
||||
|
||||
def select_not_like_iv(email : String) : Array(InvidiousPlaylist)
|
||||
def select_not_like_iv(email : String) : Array(InvidiousCompilation)
|
||||
request = <<-SQL
|
||||
SELECT * FROM playlists
|
||||
SELECT * FROM compilations
|
||||
WHERE author = $1 AND id NOT LIKE 'IV%'
|
||||
ORDER BY created
|
||||
SQL
|
||||
|
||||
PG_DB.query_all(request, email, as: InvidiousPlaylist)
|
||||
PG_DB.query_all(request, email, as: InvidiousCompilation)
|
||||
end
|
||||
|
||||
def select_user_created_playlists(email : String) : Array({String, String})
|
||||
def select_user_created_compilations(email : String) : Array({String, String})
|
||||
request = <<-SQL
|
||||
SELECT id,title FROM playlists
|
||||
SELECT id,title FROM compilations
|
||||
WHERE author = $1 AND id LIKE 'IV%'
|
||||
SQL
|
||||
|
||||
@ -149,20 +139,20 @@ module Invidious::Database::Compilations
|
||||
# Misc checks
|
||||
# -------------------
|
||||
|
||||
# Check if given playlist ID exists
|
||||
# Check if given compilation ID exists
|
||||
def exists?(id : String) : Bool
|
||||
request = <<-SQL
|
||||
SELECT id FROM playlists
|
||||
SELECT id FROM compilations
|
||||
WHERE id = $1
|
||||
SQL
|
||||
|
||||
return PG_DB.query_one?(request, id, as: String).nil?
|
||||
end
|
||||
|
||||
# Count how many playlist a user has created.
|
||||
# Count how many compilations a user has created.
|
||||
def count_owned_by(author : String) : Int64
|
||||
request = <<-SQL
|
||||
SELECT count(*) FROM playlists
|
||||
SELECT count(*) FROM compilations
|
||||
WHERE author = $1
|
||||
SQL
|
||||
|
||||
@ -171,7 +161,7 @@ module Invidious::Database::Compilations
|
||||
end
|
||||
|
||||
#
|
||||
# This module contains functions related to the "playlist_videos" table.
|
||||
# This module contains functions related to the "compilation_videos" table.
|
||||
#
|
||||
module Invidious::Database::CompilationVideos
|
||||
extend self
|
||||
@ -184,7 +174,7 @@ module Invidious::Database::CompilationVideos
|
||||
video_array = video.to_a
|
||||
|
||||
request = <<-SQL
|
||||
INSERT INTO playlist_videos
|
||||
INSERT INTO compilation_videos
|
||||
VALUES (#{arg_array(video_array)})
|
||||
SQL
|
||||
|
||||
@ -193,67 +183,67 @@ module Invidious::Database::CompilationVideos
|
||||
|
||||
def delete(index)
|
||||
request = <<-SQL
|
||||
DELETE FROM playlist_videos *
|
||||
DELETE FROM compilation_videos *
|
||||
WHERE index = $1
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, index)
|
||||
end
|
||||
|
||||
def delete_by_playlist(plid : String)
|
||||
def delete_by_compilation(compid : String)
|
||||
request = <<-SQL
|
||||
DELETE FROM playlist_videos *
|
||||
WHERE plid = $1
|
||||
DELETE FROM compilation_videos *
|
||||
WHERE compid = $1
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, plid)
|
||||
PG_DB.exec(request, compid)
|
||||
end
|
||||
|
||||
# -------------------
|
||||
# Salect
|
||||
# -------------------
|
||||
|
||||
def select(plid : String, index : VideoIndex, offset, limit = 100) : Array(PlaylistVideo)
|
||||
def select(compid : String, index : VideoIndex, offset, limit = 100) : Array(CompilationVideo)
|
||||
request = <<-SQL
|
||||
SELECT * FROM playlist_videos
|
||||
WHERE plid = $1
|
||||
SELECT * FROM compilation_videos
|
||||
WHERE compid = $1
|
||||
ORDER BY array_position($2, index)
|
||||
LIMIT $3
|
||||
OFFSET $4
|
||||
SQL
|
||||
|
||||
return PG_DB.query_all(request, plid, index, limit, offset, as: PlaylistVideo)
|
||||
return PG_DB.query_all(request, compid, index, limit, offset, as: CompilationVideo)
|
||||
end
|
||||
|
||||
def select_index(plid : String, vid : String) : Int64?
|
||||
def select_index(compid : String, vid : String) : Int64?
|
||||
request = <<-SQL
|
||||
SELECT index FROM playlist_videos
|
||||
WHERE plid = $1 AND id = $2
|
||||
SELECT index FROM compilation_videos
|
||||
WHERE compid = $1 AND id = $2
|
||||
LIMIT 1
|
||||
SQL
|
||||
|
||||
return PG_DB.query_one?(request, plid, vid, as: Int64)
|
||||
return PG_DB.query_one?(request, compid, vid, as: Int64)
|
||||
end
|
||||
|
||||
def select_one_id(plid : String, index : VideoIndex) : String?
|
||||
def select_one_id(compid : String, index : VideoIndex) : String?
|
||||
request = <<-SQL
|
||||
SELECT id FROM playlist_videos
|
||||
WHERE plid = $1
|
||||
SELECT id FROM compilation_videos
|
||||
WHERE compid = $1
|
||||
ORDER BY array_position($2, index)
|
||||
LIMIT 1
|
||||
SQL
|
||||
|
||||
return PG_DB.query_one?(request, plid, index, as: String)
|
||||
return PG_DB.query_one?(request, compid, index, as: String)
|
||||
end
|
||||
|
||||
def select_ids(plid : String, index : VideoIndex, limit = 500) : Array(String)
|
||||
def select_ids(compid : String, index : VideoIndex, limit = 500) : Array(String)
|
||||
request = <<-SQL
|
||||
SELECT id FROM playlist_videos
|
||||
WHERE plid = $1
|
||||
SELECT id FROM compilation_videos
|
||||
WHERE compid = $1
|
||||
ORDER BY array_position($2, index)
|
||||
LIMIT $3
|
||||
SQL
|
||||
|
||||
return PG_DB.query_all(request, plid, index, limit, as: String)
|
||||
return PG_DB.query_all(request, compid, index, limit, as: String)
|
||||
end
|
||||
end
|
||||
|
@ -159,7 +159,7 @@ module Invidious::Database::Playlists
|
||||
return PG_DB.query_one?(request, id, as: String).nil?
|
||||
end
|
||||
|
||||
# Count how many playlist a user has created.
|
||||
# Count how many playlists a user has created.
|
||||
def count_owned_by(author : String) : Int64
|
||||
request = <<-SQL
|
||||
SELECT count(*) FROM playlists
|
||||
|
@ -1,2 +0,0 @@
|
||||
module Invidious::Routes::Compilations
|
||||
end
|
@ -8,6 +8,26 @@ module Invidious::Routes::Feeds
|
||||
def self.compilations(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
user = env.get? "user"
|
||||
referer = get_referer(env)
|
||||
|
||||
return env.redirect "/" if user.nil?
|
||||
|
||||
user = user.as(User)
|
||||
|
||||
# TODO: make a single DB call and separate the items here?
|
||||
items_created = Invidious::Database::Compilations.select_like_iv(user.email)
|
||||
items_created.map! do |item|
|
||||
item.author = ""
|
||||
item
|
||||
end
|
||||
|
||||
items_saved = Invidious::Database::Compilations.select_not_like_iv(user.email)
|
||||
items_saved.map! do |item|
|
||||
item.author = ""
|
||||
item
|
||||
end
|
||||
|
||||
templated "feeds/compilations"
|
||||
end
|
||||
|
||||
|
@ -23,12 +23,6 @@ module Invidious::Routes::Misc
|
||||
else
|
||||
env.redirect "/feed/popular"
|
||||
end
|
||||
when "Compilations"
|
||||
if user
|
||||
env.redirect "/feed/compilations"
|
||||
else
|
||||
env.redirect "/feed/popular"
|
||||
end
|
||||
else
|
||||
templated "search_homepage", navbar_search: false
|
||||
end
|
||||
|
@ -99,7 +99,7 @@ module Invidious::Routes::PreferencesRoute
|
||||
default_home = env.params.body["default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
|
||||
|
||||
feed_menu = [] of String
|
||||
5.times do |index|
|
||||
4.times do |index|
|
||||
option = env.params.body["feed_menu[#{index}]"]?.try &.as(String) || ""
|
||||
if !option.empty?
|
||||
feed_menu << option
|
||||
@ -186,7 +186,7 @@ module Invidious::Routes::PreferencesRoute
|
||||
CONFIG.default_user_preferences.default_home = env.params.body["admin_default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
|
||||
|
||||
admin_feed_menu = [] of String
|
||||
5.times do |index|
|
||||
4.times do |index|
|
||||
option = env.params.body["admin_feed_menu[#{index}]"]?.try &.as(String) || ""
|
||||
if !option.empty?
|
||||
admin_feed_menu << option
|
||||
|
@ -1,6 +0,0 @@
|
||||
<% title = HTML.escape(compilation.title) %>
|
||||
<% author = HTML.escape(compilation.author) %>
|
||||
|
||||
<% content_for "header" do %>
|
||||
<title><%= title %> - Invidious</title>
|
||||
<% end %>
|
@ -1,7 +1,7 @@
|
||||
<div class="feed-menu">
|
||||
<% feed_menu = env.get("preferences").as(Preferences).feed_menu.dup %>
|
||||
<% if !env.get?("user") %>
|
||||
<% feed_menu.reject! {|item| {"Subscriptions", "Playlists", "Compilations"}.includes? item} %>
|
||||
<% feed_menu.reject! {|item| {"Subscriptions", "Playlists"}.includes? item} %>
|
||||
<% end %>
|
||||
<% feed_menu.each do |feed| %>
|
||||
<a href="/feed/<%= feed.downcase %>" class="feed-menu-item pure-menu-heading">
|
||||
|
@ -1,6 +0,0 @@
|
||||
<% content_for "header" do %>
|
||||
<title><%= translate(locale, "Compilations") %> - Invidious</title>
|
||||
<% end %>
|
||||
|
||||
<%= rendered "components/feed_menu" %>
|
||||
|
@ -165,7 +165,7 @@
|
||||
</div>
|
||||
|
||||
<% if env.get?("user") %>
|
||||
<% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists","Compilations"} %>
|
||||
<% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists"} %>
|
||||
<% else %>
|
||||
<% feed_options = {"", "Popular", "Trending"} %>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user