diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-07-05 18:43:26 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-07-05 18:43:26 -0500 |
| commit | 1ada71e5ba01c797f4a8aa2993e5e9fbd9ab5b00 (patch) | |
| tree | 5e37bc01c096dc8356edf53128b0c6685d4109a8 /src | |
| parent | b10d0dce78314a532327100db37c3ccb23566c9d (diff) | |
| download | invidious-1ada71e5ba01c797f4a8aa2993e5e9fbd9ab5b00.tar.gz invidious-1ada71e5ba01c797f4a8aa2993e5e9fbd9ab5b00.tar.bz2 invidious-1ada71e5ba01c797f4a8aa2993e5e9fbd9ab5b00.zip | |
Move user state into before_all
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index fe747f79..71051b33 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -221,8 +221,13 @@ before_all do |env| sid = env.request.cookies["SID"].value env.set "sid", sid + subscriptions = PG_DB.query_one?("SELECT subscriptions FROM users WHERE id = $1", sid, as: Array(String)) + subscriptions ||= [] of String + env.set "subscriptions", subscriptions + notifications = PG_DB.query_one?("SELECT cardinality(notifications) FROM users WHERE id = $1", sid, as: Int32) notifications ||= 0 + env.set "notifications", notifications end @@ -236,6 +241,12 @@ get "/" do |env| end get "/watch" do |env| + authorized = env.get? "authorized" + if authorized + subscriptions = env.get("subscriptions").as(Array(String)) + end + subscriptions ||= [] of String + if env.params.query["v"]? id = env.params.query["v"] else @@ -262,14 +273,6 @@ get "/watch" do |env| end listen ||= false - authorized = env.get? "authorized" - if authorized - sid = env.get("sid").as(String) - - subscriptions = PG_DB.query_one?("SELECT subscriptions FROM users WHERE id = $1", sid, as: Array(String)) - end - subscriptions ||= [] of String - client = make_client(YT_URL) begin video = get_video(id, client, PG_DB) @@ -876,7 +879,6 @@ get "/videoplayback*" do |env| if path != "/videoplayback" path = path.lchop("/videoplayback/") path = path.split("/") - # puts path raw_params = {} of String => Array(String) path.each_slice(2) do |pair| @@ -1030,5 +1032,6 @@ end public_folder "assets" add_handler FilteredCompressHandler.new +add_context_storage_type(Array(String)) Kemal.run |
