Skip to content

Commit

Permalink
Update scene.ex (#720)
Browse files Browse the repository at this point in the history
minimal effort to make /api-internal/v1/rewrite_assets endpoint's handler to (on error) throw a warning and continue (instead of just throw)
  • Loading branch information
tanfarming authored May 21, 2024
1 parent ab51827 commit 6de55f9
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions lib/ret/scene.ex
Original file line number Diff line number Diff line change
Expand Up @@ -220,39 +220,43 @@ defmodule Ret.Scene do

Repo.transaction(fn ->
Enum.each(scene_stream, fn scene ->
%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)
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
end)

:ok
end)
end
Expand Down

0 comments on commit 6de55f9

Please sign in to comment.