From a6106077bdd31bd35c1641a9fc0ce4f19d03659f Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 24 Feb 2022 16:48:35 +0100 Subject: [PATCH 1/6] Bump kemal to v1.1.2 --- shard.lock | 6 +----- shard.yml | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/shard.lock b/shard.lock index be4333c1..35d7e1c4 100644 --- a/shard.lock +++ b/shard.lock @@ -18,11 +18,7 @@ shards: kemal: git: https://github.com/kemalcr/kemal.git - version: 1.1.0 - - kilt: - git: https://github.com/jeromegn/kilt.git - version: 0.6.1 + version: 1.1.2 lsquic: git: https://github.com/iv-org/lsquic.cr.git diff --git a/shard.yml b/shard.yml index bf382ec3..76e67846 100644 --- a/shard.yml +++ b/shard.yml @@ -18,7 +18,7 @@ dependencies: version: ~> 0.18.0 kemal: github: kemalcr/kemal - version: ~> 1.1.0 + version: ~> 1.1.2 protodec: github: iv-org/protodec version: ~> 0.1.4 From 212e5ebab5d75c0b356ae9b86a573af9cc8cf571 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 23 Feb 2022 14:04:27 +0100 Subject: [PATCH 2/6] Also bump 'exception_page', a kemal dependency --- shard.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shard.lock b/shard.lock index 35d7e1c4..6cc20230 100644 --- a/shard.lock +++ b/shard.lock @@ -14,7 +14,7 @@ shards: exception_page: git: https://github.com/crystal-loot/exception_page.git - version: 0.2.0 + version: 0.2.2 kemal: git: https://github.com/kemalcr/kemal.git From 84b6429ca65ae407e4257fc771f4b760af72d310 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Tue, 22 Feb 2022 18:41:43 +0100 Subject: [PATCH 3/6] Fix error due to templating engine change --- src/invidious/views/components/item.ecr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 5f8bde13..ce7af783 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -52,11 +52,11 @@ <% if !env.get("preferences").as(Preferences).thin_mode %>
- <% if plid = env.get?("remove_playlist_items") %> -
" method="post"> + <% if plid_form = env.get?("remove_playlist_items") %> + " method="post"> ">

- + @@ -117,11 +117,11 @@

- <% elsif plid = env.get? "add_playlist_items" %> -
" method="post"> + <% elsif plid_form = env.get? "add_playlist_items" %> + " method="post"> ">

- + From 1f66d7ef7471acb07642bb3b8132d824877176fb Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sun, 10 Apr 2022 22:53:03 +0200 Subject: [PATCH 4/6] Keep using kilt for rendering Directly using Crystal's ECR seems to be causing issues, so don't use kemal's 'render' macro and patch 'content_for' to have the same behavior as before Kemal v1.1.1 --- shard.lock | 4 ++++ shard.yml | 3 +++ src/ext/kemal_content_for.cr | 16 ++++++++++++++++ src/invidious.cr | 5 +++++ src/invidious/helpers/macros.cr | 12 +++++++++--- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/ext/kemal_content_for.cr diff --git a/shard.lock b/shard.lock index 6cc20230..cdce1160 100644 --- a/shard.lock +++ b/shard.lock @@ -20,6 +20,10 @@ shards: git: https://github.com/kemalcr/kemal.git version: 1.1.2 + kilt: + git: https://github.com/jeromegn/kilt.git + version: 0.6.1 + lsquic: git: https://github.com/iv-org/lsquic.cr.git version: 2.18.1-2 diff --git a/shard.yml b/shard.yml index 76e67846..9c9b0d37 100644 --- a/shard.yml +++ b/shard.yml @@ -19,6 +19,9 @@ dependencies: kemal: github: kemalcr/kemal version: ~> 1.1.2 + kilt: + github: jeromegn/kilt + version: ~> 0.6.1 protodec: github: iv-org/protodec version: ~> 0.1.4 diff --git a/src/ext/kemal_content_for.cr b/src/ext/kemal_content_for.cr new file mode 100644 index 00000000..a4f3fd96 --- /dev/null +++ b/src/ext/kemal_content_for.cr @@ -0,0 +1,16 @@ +# Overrides for Kemal's `content_for` macro in order to keep using +# kilt as it was before Kemal v1.1.1 (Kemal PR #618). + +require "kemal" +require "kilt" + +macro content_for(key, file = __FILE__) + %proc = ->() { + __kilt_io__ = IO::Memory.new + {{ yield }} + __kilt_io__.to_s + } + + CONTENT_FOR_BLOCKS[{{key}}] = Tuple.new {{file}}, %proc + nil +end diff --git a/src/invidious.cr b/src/invidious.cr index 9f3d5d10..631a6e78 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -16,7 +16,12 @@ require "digest/md5" require "file_utils" + +# Require kemal, kilt, then our own overrides require "kemal" +require "kilt" +require "./ext/kemal_content_for.cr" + require "athena-negotiation" require "openssl/hmac" require "option_parser" diff --git a/src/invidious/helpers/macros.cr b/src/invidious/helpers/macros.cr index 75df1612..43e7171b 100644 --- a/src/invidious/helpers/macros.cr +++ b/src/invidious/helpers/macros.cr @@ -48,13 +48,19 @@ module JSON::Serializable end end -macro templated(filename, template = "template", navbar_search = true) +macro templated(_filename, template = "template", navbar_search = true) navbar_search = {{navbar_search}} - render "src/invidious/views/#{{{filename}}}.ecr", "src/invidious/views/#{{{template}}}.ecr" + + {{ filename = "src/invidious/views/" + _filename + ".ecr" }} + {{ layout = "src/invidious/views/" + template + ".ecr" }} + + __content_filename__ = {{filename}} + content = Kilt.render({{filename}}) + Kilt.render({{layout}}) end macro rendered(filename) - render "src/invidious/views/#{{{filename}}}.ecr" + Kilt.render("src/invidious/views/#{{{filename}}}.ecr") end # Similar to Kemals halt method but works in a From 0a1614a872c10787235b389542bbbf5eabb4da54 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sun, 10 Apr 2022 23:07:06 +0200 Subject: [PATCH 5/6] Also move the other Kemal class override to src/ext/ --- .../static_file_handler.cr => ext/kemal_static_file_handler.cr} | 0 src/invidious.cr | 1 + 2 files changed, 1 insertion(+) rename src/{invidious/helpers/static_file_handler.cr => ext/kemal_static_file_handler.cr} (100%) diff --git a/src/invidious/helpers/static_file_handler.cr b/src/ext/kemal_static_file_handler.cr similarity index 100% rename from src/invidious/helpers/static_file_handler.cr rename to src/ext/kemal_static_file_handler.cr diff --git a/src/invidious.cr b/src/invidious.cr index 631a6e78..dd240852 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -21,6 +21,7 @@ require "file_utils" require "kemal" require "kilt" require "./ext/kemal_content_for.cr" +require "./ext/kemal_static_file_handler.cr" require "athena-negotiation" require "openssl/hmac" From 4fd1631b301983199648d6c28abcd03ebe6215bd Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sat, 16 Apr 2022 22:49:56 +0200 Subject: [PATCH 6/6] Update crystal version in CI --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db0987cf..4e68b7f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,9 +38,9 @@ jobs: matrix: stable: [true] crystal: - - 1.0.0 - - 1.1.1 - 1.2.2 + - 1.3.2 + - 1.4.0 include: - crystal: nightly stable: false