14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/jobs/analysis/file_conversion_job.rb', line 14
def perform(file_id, output_format)
file = ModelFile.find(file_id)
raise UnsupportedFormatError unless file.convertable?(to: output_format)
extension = Mime::EXTENSION_LOOKUP.select { |k, v| v.symbol == output_format }.keys.last
status[:step] = "jobs.analysis.file_conversion.loading_mesh" scene = file.scene
status[:step] = "jobs.analysis.file_conversion.exporting" new_file = ModelFile.new(
model: file.model,
filename: Pathname.new(file.filename).sub_ext(".#{extension}"),
presupported: file.presupported,
y_up: file.y_up,
previewable: file.previewable,
caption: file.caption,
notes: file.notes
)
dedup = 0
while new_file.exists_on_storage?
dedup += 1
new_file.filename = Pathname.new(file.filename).sub_ext("-#{dedup}.#{extension}")
end
Tempfile.create("", ModelFileUploader.find_storage(:cache).directory) do |outfile|
scene.export(extension, outfile.path)
new_file.attachment = ModelFileUploader.uploaded_file(
storage: :cache,
id: File.basename(outfile.path),
metadata: {
filename: new_file.filename,
size: File.size(outfile.path)
}
)
end
new_file.relationships << Relationship.new(subject: new_file, objekt: file, predicate: "alternative_format_of")
new_file.save
new_file.analyse_later
file.broadcast_refresh
rescue NonManifoldError
Problem.create_or_clear(
file,
:non_manifold,
true
)
ensure
if file
file.problems.where(category: :inefficient, in_progress: true).find_each do
it.update(in_progress: false)
end
end
end
|