diff --git a/app/models/screenshot.rb b/app/models/screenshot.rb index 985e83d..5402a70 100644 --- a/app/models/screenshot.rb +++ b/app/models/screenshot.rb @@ -11,23 +11,6 @@ class Screenshot < ActiveRecord::Base #path: :rails_root/public/system/:class/:attachment/:id_partition/:style/:filename validates_attachment_content_type :image, :content_type => /\Aimage\/png\Z/ - def image_url(size) - "#{Rails.configuration.images_path_prefix}/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png" - end - - # Get the URL leading to a screenshot of this package - def url(size) - if self.approved - # TODO: Make the path configurable - basepath = "/screenshots/" - else - # TODO: Choose a path that makes unapproved screenshots unavailable - basepath = "/screenshots/unapproved/" - end - - File.join(basepath, self.package.name[0], self.package.name, "#{self.id}_#{size}.png") - end - # Return caption for full-screen screenshots. # Takes the description of a screenshot if available. # Otherwise it falls back to the general description of its package. @@ -39,27 +22,9 @@ class Screenshot < ActiveRecord::Base end end - def image_file(size) - # Screenshot files are at e.g. - # .../public/screenshots/f/firefox/5871654_large.png - Rails.configuration.images_path.join(self.package.name[0], self.package.name, "#{self.id}_#{size}.png") end - # Delete all image files related to this screenshot - def delete_all_images - Rails.configuration.image_sizes.each do |size,dimensions| - image_file = self.image_file(size) - Rails.logger.info "(before_destroy) Deleting screenshot image '#{image_file}' from disk" - if File.exist?(image_file) - File.delete(image_file) - else - Rails.logger.error "(before_destroy) File '#{image_file}' not found - could not delete it" - end end - end - # Callback to delete image files from disk when a screenshot record gets destroyed - before_destroy do |screenshot| - screenshot.delete_all_images end end