2011-02-01 09:57:29 +08:00
|
|
|
#
|
2017-04-28 03:48:44 +08:00
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
2011-02-01 09:57:29 +08:00
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
class Thumbnail < ActiveRecord::Base
|
|
|
|
belongs_to :attachment, :foreign_key => "parent_id"
|
2011-05-05 22:30:05 +08:00
|
|
|
|
|
|
|
# the ":keep_profile => true" part is in here so that we tell mini_magic to not try to pass the command line option -strip.
|
|
|
|
# this is because on the servers we are actually using graphics_magic not image_magic's mogrify and graphics_magick doesn't
|
2011-02-01 09:57:29 +08:00
|
|
|
# support -strip. you'd get something like:
|
|
|
|
# MiniMagick::Error (Command ("mogrify -strip -resize \"200x50\" \"/tmp/mini_magick23816-1\"") failed: {:status_code=>1, :output=>"mogrify: Unrecognized option (-strip).\n"}):#012
|
2013-03-15 00:20:57 +08:00
|
|
|
has_attachment(
|
|
|
|
:content_type => :image,
|
|
|
|
:storage => (Attachment.local_storage? ? :file_system : :s3),
|
|
|
|
:path_prefix => Attachment.file_store_config['path_prefix'],
|
2016-10-18 01:46:33 +08:00
|
|
|
:s3_access => 'private',
|
2015-02-19 02:33:40 +08:00
|
|
|
:keep_profile => true,
|
2015-05-06 01:13:49 +08:00
|
|
|
:thumbnail_max_image_size_pixels => Setting.get('thumbnail_max_image_size_pixels', 100_000_000).to_i
|
2013-03-15 00:20:57 +08:00
|
|
|
)
|
2011-05-05 22:30:05 +08:00
|
|
|
|
2014-08-20 06:31:40 +08:00
|
|
|
before_save :set_namespace
|
|
|
|
def set_namespace
|
|
|
|
self.namespace = attachment.namespace
|
|
|
|
end
|
|
|
|
|
2013-03-15 00:20:57 +08:00
|
|
|
def local_storage_path
|
|
|
|
"#{HostUrl.context_host(attachment.context)}/images/thumbnails/show/#{id}/#{uuid}"
|
2011-05-05 22:30:05 +08:00
|
|
|
end
|
|
|
|
|
2013-03-08 03:28:42 +08:00
|
|
|
def bucket
|
|
|
|
self.attachment.bucket
|
2012-05-23 02:45:51 +08:00
|
|
|
end
|
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
def cached_s3_url
|
2016-10-18 01:46:33 +08:00
|
|
|
@cached_s3_url = authenticated_s3_url(expires_in: 144.hours)
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
|
|
|
|
2011-05-05 22:30:05 +08:00
|
|
|
before_save :assign_uuid
|
|
|
|
def assign_uuid
|
2014-07-11 01:22:01 +08:00
|
|
|
self.uuid ||= CanvasSlug.generate_securish_uuid
|
2011-05-05 22:30:05 +08:00
|
|
|
end
|
|
|
|
protected :assign_uuid
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|