Skip to content

Commit 067a426

Browse files
Fijxuunixfox
authored andcommitted
refactor: Move top level constants to it's own modules
1 parent ffd9f4b commit 067a426

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

src/invidious.cr

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,9 @@ rescue ex
6767
puts "Check your 'config.yml' database settings or PostgreSQL settings."
6868
exit(1)
6969
end
70-
ARCHIVE_URL = URI.parse("https://archive.org")
71-
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
72-
REDDIT_URL = URI.parse("https://www.reddit.com")
73-
YT_URL = URI.parse("https://www.youtube.com")
74-
HOST_URL = make_host_url(Kemal.config)
75-
76-
CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
77-
TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"}
70+
HOST_URL = make_host_url(Kemal.config)
7871
MAX_ITEMS_PER_PAGE = 1500
7972

80-
REQUEST_HEADERS_WHITELIST = {"accept", "accept-encoding", "cache-control", "content-length", "if-none-match", "range"}
81-
RESPONSE_HEADERS_BLACKLIST = {"access-control-allow-origin", "alt-svc", "server", "cross-origin-opener-policy-report-only", "report-to", "cross-origin", "timing-allow-origin", "cross-origin-resource-policy"}
82-
HTTP_CHUNK_SIZE = 10485760 # ~10MB
83-
8473
CURRENT_BRANCH = {{ "#{`git branch | sed -n '/* /s///p'`.strip}" }}
8574
CURRENT_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }}
8675
CURRENT_VERSION = {{ "#{`git log -1 --format=%ci | awk '{print $1}' | sed s/-/./g`.strip}" }}
@@ -97,7 +86,7 @@ SOFTWARE = {
9786
"branch" => "#{CURRENT_BRANCH}",
9887
}
9988

100-
YT_POOL = YoutubeConnectionPool.new(YT_URL, capacity: CONFIG.pool_size)
89+
YT_POOL = YoutubeConnectionPool.new(URI.parse("https://www.youtube.com"), capacity: CONFIG.pool_size)
10190

10291
# Image request pool
10392

src/invidious/comments/reddit.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Invidious::Comments
22
extend self
3+
private REDDIT_URL = URI.parse("https://www.reddit.com")
34

45
def fetch_reddit(id, sort_by = "confidence")
56
client = make_client(REDDIT_URL)

src/invidious/helpers/helpers.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require "./macros"
22

3+
TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"}
4+
35
struct Nonce
46
include DB::Serializable
57

src/invidious/helpers/utils.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
2+
13
# See http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
24
def ci_lower_bound(pos, n)
35
if n == 0

src/invidious/routes/api/v1/videos.cr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
require "html"
22

33
module Invidious::Routes::API::V1::Videos
4+
private INTERNET_ARCHIVE_URL = URI.parse("https://archive.org")
5+
private CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
6+
47
def self.videos(env)
58
locale = env.get("preferences").as(Preferences).locale
69

@@ -279,7 +282,7 @@ module Invidious::Routes::API::V1::Videos
279282

280283
file = URI.encode_www_form("#{id[0, 3]}/#{id}.xml")
281284

282-
location = make_client(ARCHIVE_URL, &.get("/download/youtubeannotations_#{index}/#{id[0, 2]}.tar/#{file}"))
285+
location = make_client(INTERNET_ARCHIVE_URL, &.get("/download/youtubeannotations_#{index}/#{id[0, 2]}.tar/#{file}"))
283286

284287
if !location.headers["Location"]?
285288
env.response.status_code = location.status_code

src/invidious/routes/routes.cr

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Invidious::Routes
2+
private REQUEST_HEADERS_WHITELIST = {
3+
"accept",
4+
"accept-encoding",
5+
"cache-control",
6+
"content-length",
7+
"if-none-match",
8+
"range",
9+
}
10+
private RESPONSE_HEADERS_BLACKLIST = {
11+
"access-control-allow-origin",
12+
"alt-svc",
13+
"server",
14+
"cross-origin-opener-policy-report-only",
15+
"report-to",
16+
"cross-origin",
17+
"timing-allow-origin",
18+
"cross-origin-resource-policy
19+
",
20+
}
21+
end

src/invidious/routes/video_playback.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module Invidious::Routes::VideoPlayback
2+
private HTTP_CHUNK_SIZE = 10485760 # ~10MB
3+
24
# /videoplayback
35
def self.get_video_playback(env)
46
locale = env.get("preferences").as(Preferences).locale

0 commit comments

Comments
 (0)