From 8d29f5039290926f4ca085ca0b338023606f2af6 Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Mon, 24 May 2021 20:05:25 -0700 Subject: [PATCH] Stop saving outfit images, use new URLs everywhere MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here, we turn off the hooks that enqueue outfit image updates, and we disconnect the `OutfitImageUploader` that manages uploaded S3 URLs, instead replacing it with an `image` method that simulates the same basic API. This should cause _all_ views on Classic DTI to use the new outfit URLs. Some notable examples: - The user's Outfits page - The donations page - The outfit page, and its sharing metadata I hope I didn't miss anything in the views that will make this crash stuff! I tested the new model code in the Rails console, and checked it against invocations that I noticed when searching the codebase for `outfit.image` 🤞 --- app/models/outfit.rb | 53 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/app/models/outfit.rb b/app/models/outfit.rb index 59a956fd..3ea14eac 100644 --- a/app/models/outfit.rb +++ b/app/models/outfit.rb @@ -15,23 +15,48 @@ class Outfit < ActiveRecord::Base scope :wardrobe_order, order('starred DESC', :name) - mount_uploader :image, OutfitImageUploader + # NOTE: We no longer save images, but we've left the code here for now. + # The `image` method below simulates the previous API for the rest + # of the app! + # mount_uploader :image, OutfitImageUploader + # before_save :update_enqueued_image + # after_commit :enqueue_image! - before_save :update_enqueued_image - after_commit :enqueue_image! + class OutfitImage + def initialize(image_versions) + @image_versions = image_versions + end - def as_json(more_options={}) - serializable_hash :only => [:id, :name, :pet_state_id, :starred], - :methods => [:color_id, :species_id, :worn_and_unworn_item_ids, - :image_versions, :image_enqueued, :image_layers_hash] + def url + @image_versions[:large] + end + + def large + Version.new(@image_versions[:large]) + end + + def medium + Version.new(@image_versions[:medium]) + end + + def small + Version.new(@image_versions[:small]) + end + + Version = Struct.new(:url) + end + + def image? + true + end + + def image + OutfitImage.new(image_versions) end def image_versions - # Now, instead of using the saved outfit to S3, we're trying out the + # Now, instead of using the saved outfit to S3, we're using out the # DTI 2020 API + CDN cache version. - # - # TODO: We're still saving outfit images for now, but we'll stop - # doing that if this transition goes well! base_url = "https://impress-outfit-images.openneo.net/outfits" + "/#{CGI.escape id.to_s}" + "/v/#{CGI.escape updated_at.to_i.to_s}" @@ -47,6 +72,12 @@ class Outfit < ActiveRecord::Base # image.versions.each { |name, version| versions[name] = version.url } # end end + + def as_json(more_options={}) + serializable_hash :only => [:id, :name, :pet_state_id, :starred], + :methods => [:color_id, :species_id, :worn_and_unworn_item_ids, + :image_versions, :image_enqueued, :image_layers_hash] + end def closet_item_ids item_outfit_relationships.map(&:item_id)