From 72d2817c3683c14fb49d7c5603e001db54d2078c Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sun, 17 Sep 2023 14:47:22 +0200 Subject: [PATCH] HTML: Make template.ecr more resilient to errors --- src/invidious/views/template.ecr | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 9904b4fc..2263f8e9 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -1,8 +1,12 @@ -<% - locale = env.get("preferences").as(Preferences).locale - dark_mode = env.get("preferences").as(Preferences).dark_mode -%> +<%- + user = env.get?("user").try &.as(IV::User) + prefs = env.get?("preferences").try &.as(Preferences) + + locale = prefs.try &.locale || "en-US" + dark_mode = prefs.try &.dark_mode || "auto" + show_nick = prefs.try &.show_nick || false +-%> @@ -40,7 +44,7 @@ <% end %>
- <% if env.get? "user" %> + <% if user %> - <% if env.get("preferences").as(Preferences).show_nick %> + <%- if show_nick -%>
- <%= HTML.escape(env.get("user").as(Invidious::User).email) %> + <%= HTML.escape(user.try &.email) %>
- <% end %> + <%- end -%>
" method="post"> "> @@ -158,7 +162,7 @@
- <% if env.get? "user" %> + <% if user %>