1
0
Fork 0
forked from OpenNeo/impress

Stop saving outfit images, use new URLs everywhere

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` 🤞
This commit is contained in:
Emi Matchu 2021-05-24 20:05:25 -07:00 committed by GitHub
parent 3e8020cc73
commit 8d29f50392
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,23 +15,48 @@ class Outfit < ActiveRecord::Base
scope :wardrobe_order, order('starred DESC', :name) 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 class OutfitImage
after_commit :enqueue_image! def initialize(image_versions)
@image_versions = image_versions
end
def as_json(more_options={}) def url
serializable_hash :only => [:id, :name, :pet_state_id, :starred], @image_versions[:large]
:methods => [:color_id, :species_id, :worn_and_unworn_item_ids, end
:image_versions, :image_enqueued, :image_layers_hash]
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 end
def image_versions 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. # 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" + base_url = "https://impress-outfit-images.openneo.net/outfits" +
"/#{CGI.escape id.to_s}" + "/#{CGI.escape id.to_s}" +
"/v/#{CGI.escape updated_at.to_i.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 } # image.versions.each { |name, version| versions[name] = version.url }
# end # end
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 def closet_item_ids
item_outfit_relationships.map(&:item_id) item_outfit_relationships.map(&:item_id)