Skip to content

Commit fe94726

Browse files
committed
Make sure we have a file to work with in the derivative generator
1 parent b4c2769 commit fe94726

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

app/uploaders/application_uploader.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ class ApplicationUploader < Shrine
2525
downloads: Shrine::Storage::FileSystem.new("tmp/downloads")
2626
}
2727

28+
F3D_OPTS = {
29+
output: "-",
30+
resolution: "512,512",
31+
filename: "0",
32+
"background-color": "0,0,0",
33+
"ambient-occlusion": "1",
34+
"grid-unit": "10",
35+
"grid-color": "0,255,255",
36+
"grid-subdivisions": 0,
37+
axis: "0"
38+
}.map { |k, v| "--#{k}=#{v}" }.join(" ").freeze
39+
2840
storage(/library_(\d+)/) do |m|
2941
Library.find(m[1]).storage # rubocop:disable Pundit/UsePolicyScope
3042
rescue ActiveRecord::RecordNotFound
@@ -101,21 +113,12 @@ def generate_location(io, record: nil, derivative: nil, metadata: {}, **)
101113
}
102114
end
103115
elsif SupportedMimeTypes.can_render?(context[:record].mime_type)
104-
f3d_opts = {
105-
output: "-",
106-
resolution: "512,512",
107-
filename: "0",
108-
"background-color": "0,0,0",
109-
"ambient-occlusion": "1",
110-
"grid-unit": "10",
111-
"grid-color": "0,255,255",
112-
"grid-subdivisions": 0,
113-
axis: "0"
114-
}.map { |k, v| "--#{k}=#{v}" }.join(" ").freeze
115-
render = StringIO.new(`f3d #{original.path} #{f3d_opts}`)
116-
{
117-
render: (render.length > 0) ? render : nil
118-
}.compact
116+
Shrine.with_file(original) do |it|
117+
render = StringIO.new(`f3d #{it.path} #{F3D_OPTS}`)
118+
{
119+
render: (render.length > 0) ? render : nil
120+
}.compact
121+
end
119122
else
120123
{}
121124
end

0 commit comments

Comments
 (0)