From c5cd1f2f3dabd5a230a4cca74d04422b41a0c3be Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sat, 24 Feb 2024 16:25:55 -0800 Subject: [PATCH] Remove `SwfAsset#html5_*_url` in favor of `SwfAsset#urls` The alt styles controller is the one place we use this right now, but I'm planning to generalize this to loading appearances during item search, too! I also add more `only` fields to the alt styles `as_json` call, because idk it feels like good practice to both 1) say what we need in this endpoint, rather than rely on default behavior upstream, and 2) to avoid leaking fields we didn't realize were on there. (And also to preserve bandwidth, too!) --- app/controllers/alt_styles_controller.rb | 5 ++++- app/javascript/wardrobe-2020/loaders/alt-styles.js | 10 ++++------ app/models/swf_asset.rb | 9 +-------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/controllers/alt_styles_controller.rb b/app/controllers/alt_styles_controller.rb index 33840614..de7acc4e 100644 --- a/app/controllers/alt_styles_controller.rb +++ b/app/controllers/alt_styles_controller.rb @@ -16,10 +16,13 @@ class AltStylesController < ApplicationController format.html { render } format.json { render json: @alt_styles.includes(swf_assets: [:zone]).as_json( + only: [:id, :species_id, :color_id, :body_id, :series_name, + :adjective_name, :thumbnail_url], include: { swf_assets: { + only: [:id, :body_id], include: [:zone], - methods: [:html5_image_url, :html5_svg_url], + methods: [:urls], } }, methods: [:series_name, :adjective_name, :thumbnail_url], diff --git a/app/javascript/wardrobe-2020/loaders/alt-styles.js b/app/javascript/wardrobe-2020/loaders/alt-styles.js index a0f1dc0e..15d4ca27 100644 --- a/app/javascript/wardrobe-2020/loaders/alt-styles.js +++ b/app/javascript/wardrobe-2020/loaders/alt-styles.js @@ -72,11 +72,9 @@ function normalizeSwfAssetToLayer(swfAssetData) { bodyId: swfAssetData.body_id, knownGlitches: [], // TODO - // HACK: We're just simplifying this adapter, but it would be better to - // actually check what file formats the manifest says! - svgUrl: swfAssetData.html5_svg_url, - canvasMovieLibraryUrl: null, - imageUrl: swfAssetData.html5_image_url, - swfUrl: swfAssetData.url, + svgUrl: swfAssetData.urls.svg, + canvasMovieLibraryUrl: swfAssetData.urls.canvas_library, + imageUrl: swfAssetData.urls.png, + swfUrl: swfAssetData.urls.swf, }; } diff --git a/app/models/swf_asset.rb b/app/models/swf_asset.rb index fbd39ea6..64d5f19c 100644 --- a/app/models/swf_asset.rb +++ b/app/models/swf_asset.rb @@ -45,6 +45,7 @@ class SwfAsset < ApplicationRecord swf: url, png: image_url, svg: manifest_asset_urls[:svg], + canvas_library: manifest_asset_urls[:js], manifest: manifest_url, } end @@ -147,14 +148,6 @@ class SwfAsset < ApplicationRecord ).to_s end - def html5_image_url - manifest_asset_urls[:png] - end - - def html5_svg_url - manifest_asset_urls[:svg] - end - def known_glitches self[:known_glitches].split(',') end