diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-03-09 12:42:23 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-03-09 12:42:23 -0600 |
| commit | eb1d1e30d1cdcaceb64e6bbba56c64a41269147e (patch) | |
| tree | 58052f8ba6bebfbb5820c5ba413420052a8b80c5 | |
| parent | e22d6d8549ee95c755b3f6a6fdee52cb0053252e (diff) | |
| download | invidious-eb1d1e30d1cdcaceb64e6bbba56c64a41269147e.tar.gz invidious-eb1d1e30d1cdcaceb64e6bbba56c64a41269147e.tar.bz2 invidious-eb1d1e30d1cdcaceb64e6bbba56c64a41269147e.zip | |
Add config file
| -rw-r--r-- | config/config.yml | 8 | ||||
| -rw-r--r-- | src/helpers.cr | 14 | ||||
| -rw-r--r-- | src/invidious.cr | 18 |
3 files changed, 37 insertions, 3 deletions
diff --git a/config/config.yml b/config/config.yml new file mode 100644 index 00000000..f8a06faa --- /dev/null +++ b/config/config.yml @@ -0,0 +1,8 @@ +pool_size: 10 +threads: 5 +db: + user: kemal + password: kemal + host: localhost + port: 5432 + dbname: invidious
\ No newline at end of file diff --git a/src/helpers.cr b/src/helpers.cr index 5b3d6625..7ca5bd61 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -13,6 +13,20 @@ macro templated(filename) render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr" end +class Config + YAML.mapping({ + pool_size: Int32, + threads: Int32, + db: NamedTuple( + user: String, + password: String, + host: String, + port: Int32, + dbname: String, + ), + }) +end + class Video module HTTPParamConverter def self.from_rs(rs) diff --git a/src/invidious.cr b/src/invidious.cr index cdd0b50a..1474fa40 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -18,10 +18,13 @@ require "kemal" require "option_parser" require "pg" require "xml" +require "yaml" require "./helpers" -pool_size = 10 -threads = 5 +CONFIG = Config.from_yaml(File.read("config/config.yml")) + +pool_size = CONFIG.pool_size +threads = CONFIG.threads Kemal.config.extra_options do |parser| parser.banner = "Usage: invidious [arguments]" @@ -45,7 +48,16 @@ end Kemal::CLI.new -PG_DB = DB.open "postgres://kemal:kemal@localhost:5432/invidious" +PG_URL = URI.new( + scheme: "postgres", + user: CONFIG.db[:user], + password: CONFIG.db[:password], + host: CONFIG.db[:host], + port: CONFIG.db[:port], + path: CONFIG.db[:dbname], +) + +PG_DB = DB.open PG_URL YT_URL = URI.parse("https://www.youtube.com") REDDIT_URL = URI.parse("https://api.reddit.com") |
