Skip to content

Commit 8e068c8

Browse files
committed
word
1 parent 10b621f commit 8e068c8

File tree

2 files changed

+43
-45
lines changed

2 files changed

+43
-45
lines changed

lib/ret/scene.ex

+36-32
Original file line numberDiff line numberDiff line change
@@ -220,38 +220,42 @@ defmodule Ret.Scene do
220220

221221
Repo.transaction(fn ->
222222
Enum.each(scene_stream, fn scene ->
223-
%Scene{
224-
scene_owned_file: old_scene_owned_file,
225-
model_owned_file: old_model_owned_file,
226-
account: account
227-
} = scene
228-
229-
new_scene_owned_file =
230-
Storage.create_new_owned_file_with_replaced_string(
231-
old_scene_owned_file,
232-
account,
233-
old_domain_url,
234-
new_domain_url
235-
)
236-
237-
{:ok, new_model_owned_file} =
238-
Storage.duplicate_and_transform(old_model_owned_file, account, fn glb_stream,
239-
_total_bytes ->
240-
GLTFUtils.replace_in_glb(glb_stream, old_domain_url, new_domain_url)
241-
end)
242-
243-
scene
244-
|> change()
245-
|> put_change(:scene_owned_file_id, new_scene_owned_file.owned_file_id)
246-
|> put_change(:model_owned_file_id, new_model_owned_file.owned_file_id)
247-
|> Repo.update!()
248-
249-
for old_owned_file <- [old_scene_owned_file, old_model_owned_file] do
250-
OwnedFile.set_inactive(old_owned_file)
251-
Storage.rm_files_for_owned_file(old_owned_file)
252-
Repo.delete(old_owned_file)
253-
end
254-
end)
223+
try do
224+
%Scene{
225+
scene_owned_file: old_scene_owned_file,
226+
model_owned_file: old_model_owned_file,
227+
account: account
228+
} = scene
229+
230+
new_scene_owned_file =
231+
Storage.create_new_owned_file_with_replaced_string(
232+
old_scene_owned_file,
233+
account,
234+
old_domain_url,
235+
new_domain_url
236+
)
237+
238+
{:ok, new_model_owned_file} =
239+
Storage.duplicate_and_transform(old_model_owned_file, account, fn glb_stream,
240+
_total_bytes ->
241+
GLTFUtils.replace_in_glb(glb_stream, old_domain_url, new_domain_url)
242+
end)
243+
244+
scene
245+
|> change()
246+
|> put_change(:scene_owned_file_id, new_scene_owned_file.owned_file_id)
247+
|> put_change(:model_owned_file_id, new_model_owned_file.owned_file_id)
248+
|> Repo.update!()
249+
250+
for old_owned_file <- [old_scene_owned_file, old_model_owned_file] do
251+
OwnedFile.set_inactive(old_owned_file)
252+
Storage.rm_files_for_owned_file(old_owned_file)
253+
Repo.delete(old_owned_file)
254+
end
255+
rescue
256+
e ->
257+
IO.warn("Failed to process scene due to an error: #{inspect(e)}")
258+
end)
255259

256260
:ok
257261
end)

lib/ret/storage.ex

+7-13
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,13 @@ defmodule Ret.Storage do
109109
search_string,
110110
replacement_string
111111
) do
112-
case fetch(owned_file) do
113-
{:ok, %{"content_type" => content_type}, file_stream} ->
114-
file_stream
115-
|> Enum.to_list()
116-
|> Enum.join("")
117-
|> String.replace(search_string, replacement_string)
118-
|> store_string_as_owned_file(content_type, account)
119-
120-
{:error, reason} ->
121-
# Print a warning and ignore the error
122-
IO.warn("Failed to fetch the file: #{inspect(reason)}")
123-
:ignore
124-
end
112+
{:ok, %{"content_type" => content_type}, file_stream} = fetch(owned_file)
113+
114+
file_stream
115+
|> Enum.to_list()
116+
|> Enum.join("")
117+
|> String.replace(search_string, replacement_string)
118+
|> store_string_as_owned_file(content_type, account)
125119
end
126120

127121
def fetch(id, key) when is_binary(id) and is_binary(key) do

0 commit comments

Comments
 (0)