From 8e068c8b2574ea00d7a79003e66da2d7457c5d75 Mon Sep 17 00:00:00 2001 From: tanfarming Date: Mon, 20 May 2024 16:48:46 -0400 Subject: [PATCH] word --- lib/ret/scene.ex | 68 ++++++++++++++++++++++++---------------------- lib/ret/storage.ex | 20 +++++--------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/lib/ret/scene.ex b/lib/ret/scene.ex index 134359490..c33a8fc0e 100644 --- a/lib/ret/scene.ex +++ b/lib/ret/scene.ex @@ -220,38 +220,42 @@ 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) - end - end) + 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) :ok end) diff --git a/lib/ret/storage.ex b/lib/ret/storage.ex index 0fda4fe84..05c064dcc 100644 --- a/lib/ret/storage.ex +++ b/lib/ret/storage.ex @@ -109,19 +109,13 @@ defmodule Ret.Storage do search_string, replacement_string ) do - case fetch(owned_file) do - {:ok, %{"content_type" => content_type}, file_stream} -> - file_stream - |> Enum.to_list() - |> Enum.join("") - |> String.replace(search_string, replacement_string) - |> store_string_as_owned_file(content_type, account) - - {:error, reason} -> - # Print a warning and ignore the error - IO.warn("Failed to fetch the file: #{inspect(reason)}") - :ignore - end + {:ok, %{"content_type" => content_type}, file_stream} = fetch(owned_file) + + file_stream + |> Enum.to_list() + |> Enum.join("") + |> String.replace(search_string, replacement_string) + |> store_string_as_owned_file(content_type, account) end def fetch(id, key) when is_binary(id) and is_binary(key) do