Skip to content

Commit

Permalink
word
Browse files Browse the repository at this point in the history
  • Loading branch information
tanfarming committed May 21, 2024
1 parent 8e068c8 commit d142d9c
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions lib/ret/scene.ex
Original file line number Diff line number Diff line change
Expand Up @@ -219,44 +219,46 @@ defmodule Ret.Scene do
end)

Repo.transaction(fn ->
Enum.each(scene_stream, fn scene ->
try do
%Scene{
scene_owned_file: old_scene_owned_file,
model_owned_file: old_model_owned_file,
account: account
} = scene

new_scene_owned_file =
Storage.create_new_owned_file_with_replaced_string(
old_scene_owned_file,
account,
old_domain_url,
new_domain_url
)

{:ok, new_model_owned_file} =
Storage.duplicate_and_transform(old_model_owned_file, account, fn glb_stream,
_total_bytes ->
GLTFUtils.replace_in_glb(glb_stream, old_domain_url, new_domain_url)
end)

scene
|> change()
|> put_change(:scene_owned_file_id, new_scene_owned_file.owned_file_id)
|> put_change(:model_owned_file_id, new_model_owned_file.owned_file_id)
|> Repo.update!()

for old_owned_file <- [old_scene_owned_file, old_model_owned_file] do
OwnedFile.set_inactive(old_owned_file)
Storage.rm_files_for_owned_file(old_owned_file)
Repo.delete(old_owned_file)
Repo.transaction(fn ->
Enum.each(scene_stream, fn scene ->
try do
%Scene{
scene_owned_file: old_scene_owned_file,
model_owned_file: old_model_owned_file,
account: account
} = scene

new_scene_owned_file =
Storage.create_new_owned_file_with_replaced_string(
old_scene_owned_file,
account,
old_domain_url,
new_domain_url
)

{:ok, new_model_owned_file} =
Storage.duplicate_and_transform(old_model_owned_file, account, fn glb_stream, _total_bytes ->
GLTFUtils.replace_in_glb(glb_stream, old_domain_url, new_domain_url)
end)

scene
|> change()
|> put_change(:scene_owned_file_id, new_scene_owned_file.owned_file_id)
|> put_change(:model_owned_file_id, new_model_owned_file.owned_file_id)
|> Repo.update!()

for old_owned_file <- [old_scene_owned_file, old_model_owned_file] do
OwnedFile.set_inactive(old_owned_file)
Storage.rm_files_for_owned_file(old_owned_file)
Repo.delete(old_owned_file)
end
rescue
e ->
IO.warn("Failed to process scene due to an error: #{inspect(e)}")
end
rescue
e ->
IO.warn("Failed to process scene due to an error: #{inspect(e)}")
end)

end)

:ok
end)
end
Expand Down

0 comments on commit d142d9c

Please sign in to comment.