Fix JSON serialization

This commit is contained in:
Omar Roth 2020-03-29 17:44:45 -04:00
parent 0e58d99f4e
commit 3b2e142542
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2
10 changed files with 76 additions and 56 deletions

View file

@ -21,9 +21,11 @@
</div>
<script id="playlist_data" type="application/json">
<%=
{
"csrf_token": "<%= URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "") %>"
}
"csrf_token" => URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "")
}.to_pretty_json
%>
</script>
<script src="/js/playlist_widget.js"></script>

View file

@ -72,13 +72,15 @@
<% end %>
<script id="community_data" type="application/json">
<%=
{
"ucid": "<%= channel.ucid %>",
"youtube_comments_text": "<%= HTML.escape(translate(locale, "View YouTube comments")) %>",
"comments_text": "<%= HTML.escape(translate(locale, "View `x` comments", "{commentCount}")) %>",
"hide_replies_text": "<%= HTML.escape(translate(locale, "Hide replies")) %>",
"show_replies_text": "<%= HTML.escape(translate(locale, "Show replies")) %>",
"preferences": <%= env.get("preferences").as(Preferences).to_json %>
}
"ucid" => channel.ucid,
"youtube_comments_text" => HTML.escape(translate(locale, "View YouTube comments")),
"comments_text" => HTML.escape(translate(locale, "View `x` comments", "{commentCount}")),
"hide_replies_text" => HTML.escape(translate(locale, "Hide replies")),
"show_replies_text" => HTML.escape(translate(locale, "Show replies")),
"preferences" => env.get("preferences").as(Preferences)
}.to_pretty_json
%>
</script>
<script src="/js/community.js?v=<%= ASSET_COMMIT %>"></script>

View file

@ -37,11 +37,13 @@
</video>
<script id="player_data" type="application/json">
<%=
{
"aspect_ratio": "<%= aspect_ratio %>",
"title": "<%= video.title.dump_unquoted %>",
"description": "<%= HTML.escape(video.short_description) %>",
"thumbnail": "<%= thumbnail %>"
}
"aspect_ratio" => aspect_ratio,
"title" => video.title,
"description" => HTML.escape(video.short_description),
"thumbnail" => thumbnail
}.to_pretty_json
%>
</script>
<script src="/js/player.js?v=<%= ASSET_COMMIT %>"></script>

View file

@ -20,14 +20,16 @@
<% end %>
<script id="subscribe_data" type="application/json">
<%=
{
"ucid": "<%= ucid %>",
"author": "<%= HTML.escape(author) %>",
"sub_count_text": "<%= HTML.escape(sub_count_text) %>",
"csrf_token": "<%= URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "") %>",
"subscribe_text": "<%= HTML.escape(translate(locale, "Subscribe")) %>",
"unsubscribe_text": "<%= HTML.escape(translate(locale, "Unsubscribe")) %>"
}
"ucid" => ucid,
"author" => HTML.escape(author),
"sub_count_text" => HTML.escape(sub_count_text),
"csrf_token" => URI.encode_www_form(env.get?("csrf_token").try &.as(String) || ""),
"subscribe_text" => HTML.escape(translate(locale, "Subscribe")),
"unsubscribe_text" => HTML.escape(translate(locale, "Unsubscribe"))
}.to_pretty_json
%>
</script>
<script src="/js/subscribe_widget.js?v=<%= ASSET_COMMIT %>"></script>
<% else %>

View file

@ -16,16 +16,18 @@
<body>
<script id="video_data" type="application/json">
<%=
{
"id": "<%= video.id %>",
"index": "<%= continuation %>",
"plid": "<%= plid %>",
"length_seconds": "<%= video.length_seconds.to_f %>",
"video_series": <%= video_series.to_json %>,
"params": <%= params.to_json %>,
"preferences": <%= preferences.to_json %>,
"premiere_timestamp": <%= video.premiere_timestamp.try &.to_unix || "null" %>
}
"id" => video.id,
"index" => continuation,
"plid" => plid,
"length_seconds" => video.length_seconds.to_f,
"video_series" => video_series,
"params" => params,
"preferences" => preferences,
"premiere_timestamp" => video.premiere_timestamp.try &.to_unix
}.to_pretty_json
%>
</script>
<%= rendered "components/player" %>

View file

@ -19,9 +19,11 @@
</div>
<script id="watched_data" type="application/json">
<%=
{
"csrf_token": "<%= URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "") %>"
}
"csrf_token" => URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "")
}.to_pretty_json
%>
</script>
<script src="/js/watched_widget.js"></script>

View file

@ -70,9 +70,11 @@
<% if playlist.is_a?(InvidiousPlaylist) && playlist.author == user.try &.email %>
<script id="playlist_data" type="application/json">
<%=
{
"csrf_token": "<%= URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "") %>"
}
"csrf_token" => URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "")
}.to_pretty_json
%>
</script>
<script src="/js/playlist_widget.js"></script>
<% end %>

View file

@ -46,9 +46,11 @@
</div>
<script id="watched_data" type="application/json">
<%=
{
"csrf_token": "<%= URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "") %>"
}
"csrf_token" => URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "")
}.to_pretty_json
%>
</script>
<script src="/js/watched_widget.js"></script>

View file

@ -152,10 +152,12 @@
<% if env.get? "user" %>
<script src="/js/sse.js?v=<%= ASSET_COMMIT %>"></script>
<script id="notification_data" type="application/json">
<%=
{
"upload_text": "<%= HTML.escape(translate(locale, "`x` uploaded a video")) %>",
"live_upload_text": "<%= HTML.escape(translate(locale, "`x` is live")) %>"
}
"upload_text" => HTML.escape(translate(locale, "`x` uploaded a video")),
"live_upload_text" => HTML.escape(translate(locale, "`x` is live"))
}.to_pretty_json
%>
</script>
<script src="/js/notifications.js?v=<%= ASSET_COMMIT %>"></script>
<% end %>

View file

@ -27,23 +27,25 @@
<% end %>
<script id="video_data" type="application/json">
<%=
{
"id": "<%= video.id %>",
"index": "<%= continuation %>",
"plid": "<%= plid %>",
"length_seconds": <%= video.length_seconds.to_f %>,
"play_next": <%= !rvs.empty? && !plid && params.continue %>,
"next_video": "<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>",
"youtube_comments_text": "<%= HTML.escape(translate(locale, "View YouTube comments")) %>",
"reddit_comments_text": "<%= HTML.escape(translate(locale, "View Reddit comments")) %>",
"reddit_permalink_text": "<%= HTML.escape(translate(locale, "View more comments on Reddit")) %>",
"comments_text": "<%= HTML.escape(translate(locale, "View `x` comments", "{commentCount}")) %>",
"hide_replies_text": "<%= HTML.escape(translate(locale, "Hide replies")) %>",
"show_replies_text": "<%= HTML.escape(translate(locale, "Show replies")) %>",
"params": <%= params.to_json %>,
"preferences": <%= preferences.to_json %>,
"premiere_timestamp": <%= video.premiere_timestamp.try &.to_unix || "null" %>
}
"id" => video.id,
"index" => continuation,
"plid" => plid,
"length_seconds" => video.length_seconds.to_f,
"play_next" => !rvs.empty? && !plid && params.continue,
"next_video" => rvs.select { |rv| rv["id"]? }[0]?.try &.["id"],
"youtube_comments_text" => HTML.escape(translate(locale, "View YouTube comments")),
"reddit_comments_text" => HTML.escape(translate(locale, "View Reddit comments")),
"reddit_permalink_text" => HTML.escape(translate(locale, "View more comments on Reddit")),
"comments_text" => HTML.escape(translate(locale, "View `x` comments", "{commentCount}")),
"hide_replies_text" => HTML.escape(translate(locale, "Hide replies")),
"show_replies_text" => HTML.escape(translate(locale, "Show replies")),
"params" => params,
"preferences" => preferences,
"premiere_timestamp" => video.premiere_timestamp.try &.to_unix
}.to_pretty_json
%>
</script>
<div id="player-container" class="h-box">