1
0
Fork 0
forked from OpenNeo/impress

Stop saving local copies of SWFs

I think we used this for both conversion to image, and also for CORS stuff when rendering Flash-based previews… let's trash it, I don't want to be growing our hard drive with files I don't think we use anymore!

If I'm wrong and it turns out we do use them for something, then like. hey I'm sure we'll find out soon enough, and it's very recoverable operation.
This commit is contained in:
Emi Matchu 2023-10-12 22:40:36 -07:00
parent 2e152735c5
commit 5f3ce1210a
2 changed files with 0 additions and 53 deletions

View file

@ -4,9 +4,6 @@ require 'uri'
class SwfAsset < ApplicationRecord class SwfAsset < ApplicationRecord
# We use the `type` column to mean something other than what Rails means! # We use the `type` column to mean something other than what Rails means!
self.inheritance_column = nil self.inheritance_column = nil
PUBLIC_ASSET_DIR = File.join('swfs', 'outfit')
LOCAL_ASSET_DIR = Rails.root.join('public', PUBLIC_ASSET_DIR)
IMAGE_SIZES = { IMAGE_SIZES = {
:small => [150, 150], :small => [150, 150],
@ -19,10 +16,6 @@ class SwfAsset < ApplicationRecord
scope :includes_depth, -> { includes(:zone) } scope :includes_depth, -> { includes(:zone) }
def local_swf_path
LOCAL_ASSET_DIR.join(local_path_within_outfit_swfs)
end
def swf_image_dir def swf_image_dir
@swf_image_dir ||= Rails.root.join('tmp', 'asset_images_before_upload', self.id.to_s) @swf_image_dir ||= Rails.root.join('tmp', 'asset_images_before_upload', self.id.to_s)
end end
@ -100,10 +93,6 @@ class SwfAsset < ApplicationRecord
self.body_id = new_body_id self.body_id = new_body_id
end end
def local_url
'/' + File.join(PUBLIC_ASSET_DIR, local_path_within_outfit_swfs)
end
def as_json(options={}) def as_json(options={})
json = { json = {
:id => remote_id, :id => remote_id,
@ -119,11 +108,6 @@ class SwfAsset < ApplicationRecord
:has_image => true, :has_image => true,
:images => images :images => images
} }
if options[:for] == 'wardrobe'
json[:local_path] = local_url
else
json[:local_url] = local_url
end
json[:parent_id] = options[:parent_id] if options[:parent_id] json[:parent_id] = options[:parent_id] if options[:parent_id]
json json
end end
@ -179,31 +163,6 @@ class SwfAsset < ApplicationRecord
)) ))
end end
before_create do
uri = URI.parse(url)
begin
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.instance_of? URI::HTTPS
response = http.get(uri.request_uri)
rescue Exception => e
raise DownloadError, e.message
end
if response.is_a? Net::HTTPSuccess
new_local_path = File.join(LOCAL_ASSET_DIR, local_path_within_outfit_swfs)
new_local_dir = File.dirname new_local_path
FileUtils.mkdir_p new_local_dir
File.binwrite(new_local_path, response.body)
else
begin
response.error!
rescue Exception => e
raise DownloadError, "Error loading SWF at #{url}: #{e.message}"
else
raise DownloadError, "Error loading SWF at #{url}. Response: #{response.inspect}"
end
end
end
before_save do before_save do
# If an asset body ID changes, that means more than one body ID has been # If an asset body ID changes, that means more than one body ID has been
# linked to it, meaning that it's probably wearable by all bodies. # linked to it, meaning that it's probably wearable by all bodies.
@ -211,14 +170,4 @@ class SwfAsset < ApplicationRecord
end end
class DownloadError < Exception;end class DownloadError < Exception;end
private
def local_path_within_outfit_swfs
uri = URI.parse(url)
pieces = uri.path.split('/')
relevant_pieces = pieces[4..7]
relevant_pieces.unshift pieces[2]
File.join(relevant_pieces)
end
end end

View file

@ -1,2 +0,0 @@
*
!.gitignore