@@ -24,23 +24,30 @@ def id
2424
2525 # Some files exist but have unreadable permissions, treat these as non-existent
2626 def readable?
27- path && File . world_readable? ( path )
27+ true
28+ # path && File.world_readable?(path)
29+ end
30+
31+ def s3_object ( &)
32+ @s3_object ||= S3ClientFactory . create_client . get_object ( bucket : Settings . s3 . bucket , key : s3_key , &)
33+ rescue Aws ::S3 ::Errors ::NoSuchKey
34+ raise "Unable to find file at #{ s3_key } "
2835 end
2936
3037 def mtime
31- @mtime ||= File . mtime ( path ) if readable?
38+ @mtime ||= s3_object . last_modified
3239 end
3340
3441 def etag
3542 mtime &.to_i
3643 end
3744
3845 def content_length
39- @content_length ||= File . size ( path ) if readable?
46+ cocina_file [ ' size' ]
4047 end
4148
42- def path
43- @path ||= storage_root . absolute_path
49+ def content_type
50+ cocina_file [ 'hasMimeType' ]
4451 end
4552
4653 # Used as the IIIF identifier for retrieving this file from the image server
@@ -61,10 +68,6 @@ def wowza_identifier
6168 "#{ File . dirname ( file_path ) } /#{ streaming_url_file_segment } "
6269 end
6370
64- def storage_root
65- @storage_root ||= StorageRoot . new ( cocina :, file_name :)
66- end
67-
6871 def stacks_rights
6972 @stacks_rights ||= StacksRights . new ( cocina :, file_name :)
7073 end
@@ -76,4 +79,18 @@ def streamable?
7679 accepted_formats = [ ".mov" , ".mp4" , ".mpeg" , ".m4a" , ".mp3" ]
7780 accepted_formats . include? File . extname ( file_name )
7881 end
82+
83+ private
84+
85+ def cocina_file
86+ @cocina_file ||= cocina . find_file ( file_name )
87+ end
88+
89+ def s3_key
90+ @s3_key ||= storage_root . relative_path
91+ end
92+
93+ def storage_root
94+ @storage_root ||= StorageRoot . new ( cocina :, file_name :)
95+ end
7996end
0 commit comments