Skip to content

Commit 712a901

Browse files
committed
Finish convert to s3
1 parent 33e717d commit 712a901

File tree

7 files changed

+112
-61
lines changed

7 files changed

+112
-61
lines changed

app/controllers/object_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def show
1919
zip_kit_stream(filename: "#{druid}.zip") do |zip|
2020
files.each do |stacks_file|
2121
zip.write_file(stacks_file.file_name, modification_time: stacks_file.mtime) do |sink|
22-
File.open(stacks_file.path, "rb") { |file_input| IO.copy_stream(file_input, sink) }
22+
stacks_file.s3_object do |chunk|
23+
sink.write(chunk)
24+
end
2325
end
2426
end
2527
end

app/models/stacks_file.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ 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)
2829
end
2930

3031
def s3_object(&)
31-
S3ClientFactory.create_client.get_object(bucket: Settings.s3.bucket, key: storage_root.relative_path, &)
32+
@s3_object ||= S3ClientFactory.create_client.get_object(bucket: Settings.s3.bucket, key: storage_root.relative_path, &)
3233
rescue Aws::S3::Errors::NoSuchKey
33-
raise "Unable to find file at #{path}"
34+
raise "Unable to find file at #{storage_root.relative_path}"
3435
end
3536

3637
def mtime
37-
@mtime ||= File.mtime(path) if readable?
38+
@mtime ||= s3_object.last_modified
3839
end
3940

4041
def etag
@@ -53,10 +54,6 @@ def cocina_file
5354
@cocina_file ||= cocina.find_file(file_name)
5455
end
5556

56-
def path
57-
@path ||= storage_root.absolute_path
58-
end
59-
6057
# Used as the IIIF identifier for retrieving this file from the image server
6158
# return the content addressable path if available, otherwise the legacy path
6259
def cantaloupe_identifier

app/models/storage_root.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def relative_path
1515
@relative_path = File.join(treeified_id, druid, 'content', @md5)
1616
end
1717

18-
def absolute_path
19-
@absolute_path ||= File.join(Settings.stacks.storage_root, relative_path)
20-
end
18+
# def absolute_path
19+
# @absolute_path ||= File.join(Settings.stacks.storage_root, relative_path)
20+
# end
2121

2222
private
2323

spec/models/stacks_file_spec.rb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,4 @@
1717
expect { instance }.to raise_error ActiveModel::ValidationError
1818
end
1919
end
20-
21-
describe '#path' do
22-
it 'is the druid tree path to the file' do
23-
expect(instance.path).to eq(path)
24-
end
25-
end
26-
27-
describe '#readable?' do
28-
subject { instance.readable? }
29-
30-
before do
31-
allow(File).to receive(:world_readable?).with(path).and_return(permissions)
32-
end
33-
34-
context 'with a readable file' do
35-
let(:permissions) { 420 }
36-
37-
it { is_expected.to eq 420 }
38-
end
39-
40-
context 'with an unreadable file' do
41-
let(:permissions) { nil }
42-
43-
it { is_expected.to be_nil }
44-
end
45-
end
4620
end

spec/requests/download_spec.rb

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
require 'rails_helper'
44

55
RSpec.describe 'Downloading an object' do
6-
before do
7-
allow_any_instance_of(StacksFile).to receive(:path).and_return(Rails.root.join('Gemfile'))
8-
end
9-
106
let(:connection) { instance_double(Faraday::Connection) }
117

128
context 'when not logged in' do
@@ -37,21 +33,51 @@
3733
'access' => {
3834
'view' => 'world',
3935
'download' => 'world'
40-
}
36+
},
37+
"hasMessageDigests" => [
38+
{
39+
"type" => "sha1",
40+
"digest" => "aca42a32c00df5eadca47d01eabed4dad4768329"
41+
},
42+
{
43+
"type" => "md5",
44+
"digest" => "fdcb37ed3daeef288ce9b512cada6ded"
45+
}
46+
]
4147
},
4248
{
4349
'filename' => '36105116040556_0002.xml',
4450
'access' => {
4551
'view' => 'world',
4652
'download' => 'world'
47-
}
53+
},
54+
"hasMessageDigests" => [
55+
{
56+
"type" => "sha1",
57+
"digest" => "39a893f0592708ea39bb8a3321f7ab3185b86c42"
58+
},
59+
{
60+
"type" => "md5",
61+
"digest" => "bae4ac9f1a8aba1482bfb5f937338391"
62+
}
63+
]
4864
},
4965
{
5066
'filename' => '36105116040556_0002.jp2',
5167
'access' => {
5268
'view' => 'world',
5369
'download' => 'world'
54-
}
70+
},
71+
"hasMessageDigests" => [
72+
{
73+
"type" => "sha1",
74+
"digest" => "4285af92179f807a5f41a1d615c9fafd705097ac"
75+
},
76+
{
77+
"type" => "md5",
78+
"digest" => "3b8ecfb3b5a5ec9bfcfb9d85b88394bc"
79+
}
80+
]
5581
}
5682
]
5783
}
@@ -64,21 +90,51 @@
6490
'access' => {
6591
'view' => 'world',
6692
'download' => 'world'
67-
}
93+
},
94+
"hasMessageDigests" => [
95+
{
96+
"type" => "sha1",
97+
"digest" => "a8e9a51ef67c8bdeec28270b3bd1563b9c830448"
98+
},
99+
{
100+
"type" => "md5",
101+
"digest" => "a9270cbc4e5b96d3bd16ad00767632a5"
102+
}
103+
]
68104
},
69105
{
70106
'filename' => '36105116040556_0003.xml',
71107
'access' => {
72108
'view' => 'world',
73109
'download' => 'world'
74-
}
110+
},
111+
"hasMessageDigests" => [
112+
{
113+
"type" => "sha1",
114+
"digest" => "adfb92fe77712cfeab137e040040753b8de6af7e"
115+
},
116+
{
117+
"type" => "md5",
118+
"digest" => "cb91c2874bc066f521dafb82ee55a0c8"
119+
}
120+
]
75121
},
76122
{
77123
'filename' => '36105116040556_0003.jp2',
78124
'access' => {
79125
'view' => 'world',
80126
'download' => 'world'
81-
}
127+
},
128+
"hasMessageDigests" => [
129+
{
130+
"type" => "sha1",
131+
"digest" => "76c17fab28eeb58c4763a790a28eea3e65659582"
132+
},
133+
{
134+
"type" => "md5",
135+
"digest" => "ef4ecbc6b55cc6beb93857ff423b6930"
136+
}
137+
]
82138
}
83139
]
84140
}
@@ -182,14 +238,34 @@
182238
'access' => {
183239
'view' => 'stanford',
184240
'download' => 'stanford'
185-
}
241+
},
242+
"hasMessageDigests" => [
243+
{
244+
"type" => "sha1",
245+
"digest" => "b9174fd20be391b82b64981c92a58cb6865a7089"
246+
},
247+
{
248+
"type" => "md5",
249+
"digest" => "edcd7c37acde6f64a4e6a2735f478daf"
250+
}
251+
]
186252
},
187253
{
188254
'filename' => 'bb142ws0723_01_thumb.jp2',
189255
'access' => {
190256
'view' => 'stanford',
191257
'download' => 'stanford'
192-
}
258+
},
259+
"hasMessageDigests" => [
260+
{
261+
"type" => "sha1",
262+
"digest" => "05089813ddf83f70bf059eaf321bf53e0ec55f66"
263+
},
264+
{
265+
"type" => "md5",
266+
"digest" => "13e25faa7061023648611ad10cc304cc"
267+
}
268+
]
193269
}
194270
]
195271
}
@@ -202,7 +278,17 @@
202278
'access' => {
203279
'view' => 'world',
204280
'download' => 'world'
205-
}
281+
},
282+
"hasMessageDigests" => [
283+
{
284+
"type" => "sha1",
285+
"digest" => "bd6f715d3d086f102e9ed7fe2dc1ba2f78add828"
286+
},
287+
{
288+
"type" => "md5",
289+
"digest" => "be2d92be8f76906020e7918988bd26b2"
290+
}
291+
]
206292
}
207293
]
208294
}

spec/requests/file_auth_request_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010
let(:user_webauth_stanford_no_loc) { User.new(webauth_user: true, ldap_groups: %w[stanford:stanford]) }
1111
let(:druid) { 'nr349ct7889' }
1212
let(:file_name) { 'image.jp2' }
13-
let(:path) { storage_root.absolute_path }
1413
let(:storage_root) { StorageRoot.new(cocina:, file_name:) }
15-
let(:perms) { nil }
1614
let(:stacks_file) { StacksFile.new(file_name:, cocina:) }
1715
let(:cocina) { Cocina.new(public_json) }
1816

1917
before do
2018
allow(Cocina).to receive(:find).and_return(cocina)
21-
allow(File).to receive(:world_readable?).with(path).and_return(perms)
2219
end
2320

2421
describe "#show" do

spec/requests/metrics_spec.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@
2222

2323
context 'with an object' do
2424
let(:file) do
25-
instance_double(
26-
StacksFile,
27-
id: druid,
28-
file_name:,
29-
path: Rails.root.join('spec/fixtures/bb/000/cr/7262/bb000cr7262/content/8ff299eda08d7c506273840d52a03bf3'),
30-
mtime: Time.zone.now
31-
)
25+
instance_double(StacksFile)
3226
end
3327

3428
before do
3529
allow(StacksFile).to receive(:new).and_return(file)
30+
allow_any_instance_of(ObjectController).to receive(:zip_kit_stream).and_return(nil) # rubocop:disable RSpec/AnyInstance
3631
end
3732

3833
it 'tracks downloads' do

0 commit comments

Comments
 (0)