summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr7
-rw-r--r--src/invidious/channels.cr8
-rw-r--r--src/invidious/helpers/handlers.cr41
-rw-r--r--src/invidious/helpers/helpers.cr2
-rw-r--r--src/invidious/users.cr6
-rw-r--r--src/invidious/videos.cr4
6 files changed, 24 insertions, 44 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 167050fd..20a84625 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -85,6 +85,7 @@ LOCALES = {
"nl" => load_locale("nl"),
"pl" => load_locale("pl"),
"ru" => load_locale("ru"),
+ "tr" => load_locale("tr"),
"uk" => load_locale("uk"),
"zh-CN" => load_locale("zh-CN"),
}
@@ -1395,7 +1396,7 @@ post "/login" do |env|
user_array[4] = user_array[4].to_json
args = arg_array(user_array)
- PG_DB.exec("INSERT INTO users VALUES (#{args})", user_array)
+ PG_DB.exec("INSERT INTO users VALUES (#{args})", args: user_array)
PG_DB.exec("INSERT INTO session_ids VALUES ($1, $2, $3)", sid, email, Time.utc)
view_name = "subscriptions_#{sha256(user.email)}"
@@ -2907,7 +2908,7 @@ post "/feed/webhook/:token" do |env|
PG_DB.exec("INSERT INTO channel_videos VALUES (#{args}) \
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
- live_now = $8, premiere_timestamp = $9, views = $10", video_array)
+ live_now = $8, premiere_timestamp = $9, views = $10", args: video_array)
# Update all users affected by insert
if emails.empty?
@@ -5323,4 +5324,6 @@ add_context_storage_type(Preferences)
add_context_storage_type(User)
Kemal.config.logger = logger
+Kemal.config.host_binding = Kemal.config.host_binding != "0.0.0.0" ? Kemal.config.host_binding : CONFIG.host_binding
+Kemal.config.port = Kemal.config.port != 3000 ? Kemal.config.port : CONFIG.port
Kemal.run
diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr
index 7b7d3724..fa05dce4 100644
--- a/src/invidious/channels.cr
+++ b/src/invidious/channels.cr
@@ -179,14 +179,14 @@ def get_channel(id, db, refresh = true, pull_all_videos = true)
args = arg_array(channel_array)
db.exec("INSERT INTO channels VALUES (#{args}) \
- ON CONFLICT (id) DO UPDATE SET author = $2, updated = $3", channel_array)
+ ON CONFLICT (id) DO UPDATE SET author = $2, updated = $3", args: channel_array)
end
else
channel = fetch_channel(id, db, pull_all_videos: pull_all_videos)
channel_array = channel.to_a
args = arg_array(channel_array)
- db.exec("INSERT INTO channels VALUES (#{args})", channel_array)
+ db.exec("INSERT INTO channels VALUES (#{args})", args: channel_array)
end
return channel
@@ -275,7 +275,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
db.exec("INSERT INTO channel_videos VALUES (#{args}) \
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
- live_now = $8, views = $10", video_array)
+ live_now = $8, views = $10", args: video_array)
# Update all users affected by insert
if emails.empty?
@@ -343,7 +343,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
db.exec("INSERT INTO channel_videos VALUES (#{args}) \
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
- live_now = $8, views = $10", video_array)
+ live_now = $8, views = $10", args: video_array)
# Update all users affected by insert
if emails.empty?
diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr
index c8d4da4c..949eb335 100644
--- a/src/invidious/helpers/handlers.cr
+++ b/src/invidious/helpers/handlers.cr
@@ -238,40 +238,15 @@ class HTTP::Client
end
end
-# https://github.com/will/crystal-pg/pull/171
-class PG::Statement < ::DB::Statement
- protected def perform_query(args : Enumerable) : ResultSet
- params = args.map { |arg| PQ::Param.encode(arg) }
- conn = self.conn
- conn.send_parse_message(@sql)
- conn.send_bind_message params
- conn.send_describe_portal_message
- conn.send_execute_message
- conn.send_sync_message
- conn.expect_frame PQ::Frame::ParseComplete
- conn.expect_frame PQ::Frame::BindComplete
- frame = conn.read
- case frame
- when PQ::Frame::RowDescription
- fields = frame.fields
- when PQ::Frame::NoData
- fields = nil
+struct Crystal::ThreadLocalValue(T)
+ @values = Hash(Thread, T).new
+
+ def get(&block : -> T)
+ th = Thread.current
+ if !@values[th]?
+ @values[th] = yield
else
- raise "expected RowDescription or NoData, got #{frame}"
+ @values[th]
end
- ResultSet.new(self, fields)
- rescue IO::Error
- raise DB::ConnectionLost.new(connection)
- end
-
- protected def perform_exec(args : Enumerable) : ::DB::ExecResult
- result = perform_query(args)
- result.each { }
- ::DB::ExecResult.new(
- rows_affected: result.rows_affected,
- last_insert_id: 0_i64 # postgres doesn't support this
- )
- rescue IO::Error
- raise DB::ConnectionLost.new(connection)
end
end
diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr
index 0ec117c1..615e62df 100644
--- a/src/invidious/helpers/helpers.cr
+++ b/src/invidious/helpers/helpers.cr
@@ -235,6 +235,8 @@ struct Config
hsts: {type: Bool?, default: true}, # Enables 'Strict-Transport-Security'. Ensure that `domain` and all subdomains are served securely
disable_proxy: {type: Bool? | Array(String)?, default: false}, # Disable proxying server-wide: options: 'dash', 'livestreams', 'downloads', 'local'
force_resolve: {type: Socket::Family, default: Socket::Family::UNSPEC, converter: FamilyConverter}, # Connect to YouTube over 'ipv6', 'ipv4'. Will sometimes resolve fix issues with rate-limiting (see https://github.com/ytdl-org/youtube-dl/issues/21729)
+ port: {type: Int32, default: 3000}, # Port to listen for connections (overrided by command line argument)
+ host_binding: {type: String, default: "0.0.0.0"}, # Host to bind (overrided by command line argument)
})
end
diff --git a/src/invidious/users.cr b/src/invidious/users.cr
index d3da28d7..6149ae7a 100644
--- a/src/invidious/users.cr
+++ b/src/invidious/users.cr
@@ -107,7 +107,7 @@ def get_user(sid, headers, db, refresh = true)
args = arg_array(user_array)
db.exec("INSERT INTO users VALUES (#{args}) \
- ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", user_array)
+ ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", args: user_array)
db.exec("INSERT INTO session_ids VALUES ($1,$2,$3) \
ON CONFLICT (id) DO NOTHING", sid, user.email, Time.utc)
@@ -126,7 +126,7 @@ def get_user(sid, headers, db, refresh = true)
args = arg_array(user.to_a)
db.exec("INSERT INTO users VALUES (#{args}) \
- ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", user_array)
+ ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3", args: user_array)
db.exec("INSERT INTO session_ids VALUES ($1,$2,$3) \
ON CONFLICT (id) DO NOTHING", sid, user.email, Time.utc)
@@ -295,7 +295,7 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
args = arg_array(notifications)
- notifications = db.query_all("SELECT * FROM channel_videos WHERE id IN (#{args}) ORDER BY published DESC", notifications, as: ChannelVideo)
+ notifications = db.query_all("SELECT * FROM channel_videos WHERE id IN (#{args}) ORDER BY published DESC", args: notifications, as: ChannelVideo)
videos = [] of ChannelVideo
notifications.sort_by! { |video| video.published }.reverse!
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 424d1e50..e175ae39 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -900,7 +900,7 @@ def get_video(id, db, refresh = true, region = nil, force_refresh = false)
db.exec("UPDATE videos SET (info,updated,title,views,likes,dislikes,wilson_score,\
published,description,language,author,ucid,allowed_regions,is_family_friendly,\
genre,genre_url,license,sub_count_text,author_thumbnail)\
- = (#{args}) WHERE id = $1", video_array)
+ = (#{args}) WHERE id = $1", args: video_array)
rescue ex
db.exec("DELETE FROM videos * WHERE id = $1", id)
raise ex
@@ -913,7 +913,7 @@ def get_video(id, db, refresh = true, region = nil, force_refresh = false)
args = arg_array(video_array)
if !region
- db.exec("INSERT INTO videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", video_array)
+ db.exec("INSERT INTO videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", args: video_array)
end
end