mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
also upload gltf binary companion file
This commit is contained in:
1 parent
9785f3292d
commit
59bcf8b040
1 file changed
+52
-25
+52
-25
@@ -28,6 +28,7 @@ use crate::job_dependencies::JobDependencies;
|
||||
use crate::util::maybe_download_file_from_bucket::{maybe_download_file_from_bucket, MaybeDownloadArgs};
|
||||
|
||||
const BUCKET_FILE_EXTENSION : &str = ".gltf";
|
||||
const BUFFER_BIN_FILE_EXTENSION : &str = ".bin";
|
||||
|
||||
pub struct FbxToGltfJobArgs<'a> {
|
||||
pub job_dependencies: &'a JobDependencies,
|
||||
@@ -152,62 +153,88 @@ pub async fn process_job(args: FbxToGltfJobArgs<'_>) -> Result<JobSuccessResult,
|
||||
|
||||
// ==================== CHECK ALL FILES EXIST AND GET METADATA ==================== //
|
||||
|
||||
// NB: The actual name of the file will be this:
|
||||
let output_gltf_file = output_directory_actual.join("output.gltf"); // NB: FBX2GLTF creates multiple files in the directory
|
||||
// NB: FBX2GLTF creates multiple files in the directory
|
||||
// NB: The actual name of the file will be these:
|
||||
let output_gltf_file = output_directory_actual.join("output.gltf");
|
||||
let output_buffer_file = output_directory_actual.join("buffer.bin");
|
||||
|
||||
info!("Checking that output files exist...");
|
||||
|
||||
check_file_exists(&output_gltf_file).map_err(|e| ProcessSingleJobError::Other(e))?;
|
||||
check_file_exists(&output_buffer_file).map_err(|e| ProcessSingleJobError::Other(e))?;
|
||||
|
||||
info!("Interrogating result file properties...");
|
||||
|
||||
let file_size_bytes = file_size(&output_gltf_file)
|
||||
let gltf_file_size_bytes = file_size(&output_gltf_file)
|
||||
.map_err(|err| ProcessSingleJobError::Other(err))?;
|
||||
|
||||
let maybe_mimetype = get_mimetype_for_file(&output_gltf_file)
|
||||
let maybe_gltf_mimetype = get_mimetype_for_file(&output_gltf_file)
|
||||
.map_err(|err| ProcessSingleJobError::from_io_error(err))?
|
||||
.map(|mime| mime.to_string());
|
||||
|
||||
info!("Calculating sha256...");
|
||||
|
||||
let file_checksum = sha256_hash_file(&output_gltf_file)
|
||||
let gltf_file_checksum = sha256_hash_file(&output_gltf_file)
|
||||
.map_err(|err| {
|
||||
ProcessSingleJobError::Other(anyhow!("Error hashing file: {:?}", err))
|
||||
})?;
|
||||
|
||||
// ==================== UPLOAD AUDIO TO BUCKET ==================== //
|
||||
// ==================== UPLOAD GLTF TO BUCKET ==================== //
|
||||
|
||||
job_progress_reporter.log_status("uploading result")
|
||||
job_progress_reporter.log_status("uploading output.gltf")
|
||||
.map_err(|e| ProcessSingleJobError::Other(e))?;
|
||||
|
||||
let result_bucket_location = MediaFileBucketPath::generate_new(
|
||||
let result_gtlf_bucket_location = MediaFileBucketPath::generate_new(
|
||||
None,
|
||||
Some(BUCKET_FILE_EXTENSION));
|
||||
|
||||
let result_bucket_object_pathbuf = result_bucket_location.to_full_object_pathbuf();
|
||||
let result_gltf_bucket_object_pathbuf = result_gtlf_bucket_location.to_full_object_pathbuf();
|
||||
|
||||
info!("Destination bucket path: {:?}", &result_bucket_object_pathbuf);
|
||||
info!("Destination bucket path: {:?}", &result_gltf_bucket_object_pathbuf);
|
||||
|
||||
info!("Uploading media file...");
|
||||
info!("Uploading...");
|
||||
|
||||
args.job_dependencies.buckets.public_bucket_client.upload_filename_with_content_type(
|
||||
&result_bucket_object_pathbuf,
|
||||
&result_gltf_bucket_object_pathbuf,
|
||||
&output_gltf_file,
|
||||
"audio/wav")
|
||||
"model/gltf+json")
|
||||
.await
|
||||
.map_err(|e| ProcessSingleJobError::Other(e))?;
|
||||
|
||||
// ==================== UPLOAD BIN TO BUCKET ==================== //
|
||||
|
||||
job_progress_reporter.log_status("uploading buffer.bin")
|
||||
.map_err(|e| ProcessSingleJobError::Other(e))?;
|
||||
|
||||
// NB: Reuse same object hash, just change the extension.
|
||||
let result_buffer_bucket_location = MediaFileBucketPath::from_object_hash(
|
||||
result_gtlf_bucket_location.get_object_hash(),
|
||||
None,
|
||||
Some(BUFFER_BIN_FILE_EXTENSION));
|
||||
|
||||
let result_buffer_bucket_object_pathbuf = result_buffer_bucket_location.to_full_object_pathbuf();
|
||||
|
||||
info!("Destination bucket path: {:?}", &result_buffer_bucket_object_pathbuf);
|
||||
|
||||
info!("Uploading...");
|
||||
|
||||
args.job_dependencies.buckets.public_bucket_client.upload_filename_with_content_type(
|
||||
&result_buffer_bucket_object_pathbuf,
|
||||
&output_buffer_file,
|
||||
"application/octet-stream")
|
||||
.await
|
||||
.map_err(|e| ProcessSingleJobError::Other(e))?;
|
||||
|
||||
// ==================== CLEANUP FILES ==================== //
|
||||
|
||||
safe_delete_temp_file(&output_buffer_file);
|
||||
safe_delete_temp_file(&output_gltf_file);
|
||||
safe_delete_temp_directory(&output_directory_actual);
|
||||
|
||||
// ==================== DELETE DOWNLOADED FILE ==================== //
|
||||
|
||||
// NB: We should be using a tempdir, but to make absolutely certain we don't overflow the disk...
|
||||
safe_delete_temp_directory(&work_temp_dir);
|
||||
|
||||
// ==================== SAVE RECORDS ==================== //
|
||||
|
||||
info!("Saving record...");
|
||||
info!("Saving record (only gltf, not the buffer.bin) ...");
|
||||
|
||||
let (inference_result_token, id) = insert_media_file_generic(InsertArgs {
|
||||
pool: &args.job_dependencies.db.mysql_pool,
|
||||
@@ -218,30 +245,30 @@ pub async fn process_job(args: FbxToGltfJobArgs<'_>) -> Result<JobSuccessResult,
|
||||
maybe_origin_model_type: None,
|
||||
maybe_origin_model_token: None,
|
||||
maybe_origin_filename: None,
|
||||
maybe_mime_type: maybe_mimetype.as_deref(),
|
||||
file_size_bytes,
|
||||
maybe_mime_type: maybe_gltf_mimetype.as_deref(),
|
||||
file_size_bytes: gltf_file_size_bytes,
|
||||
maybe_duration_millis: None,
|
||||
maybe_audio_encoding: None,
|
||||
maybe_video_encoding: None,
|
||||
maybe_frame_width: None,
|
||||
maybe_frame_height: None,
|
||||
public_bucket_directory_hash: result_bucket_location.get_object_hash(),
|
||||
maybe_public_bucket_prefix: result_bucket_location.get_optional_prefix(),
|
||||
maybe_public_bucket_extension: result_bucket_location.get_optional_extension(),
|
||||
public_bucket_directory_hash: result_gtlf_bucket_location.get_object_hash(),
|
||||
maybe_public_bucket_prefix: result_gtlf_bucket_location.get_optional_prefix(),
|
||||
maybe_public_bucket_extension: result_gtlf_bucket_location.get_optional_extension(),
|
||||
extra_file_modification_info: None,
|
||||
maybe_creator_file_synthetic_id_category: IdCategory::MediaFile,
|
||||
maybe_creator_category_synthetic_id_category: IdCategory::MocapResult,
|
||||
maybe_mod_user_token: None,
|
||||
is_batch_generated: false,
|
||||
is_generated_on_prem: false,
|
||||
checksum_sha2: &file_checksum,
|
||||
checksum_sha2: &gltf_file_checksum,
|
||||
generated_by_worker: Some(&args.job_dependencies.job.info.container.hostname),
|
||||
generated_by_cluster: Some(&args.job_dependencies.job.info.container.cluster_name),
|
||||
})
|
||||
.await
|
||||
.map_err(|e| ProcessSingleJobError::Other(e))?;
|
||||
|
||||
info!("VC Done.");
|
||||
info!("Fbx2Gltf Done.");
|
||||
|
||||
//args.job_dependencies.clients.firehose_publisher.vc_inference_finished(
|
||||
// maybe_user_token.as_ref(),
|
||||
|
||||
Reference in new issue
Block a user