fix: upload attachments with unique filename
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 3m14s
Test / build (map[name:stable]) (push) Successful in 3m46s
Release Please / Release-plz (push) Failing after 23s

This prevents any clashes with uploading two files with the same name at the same time.

Closes: kemitix/trello-to-deck#9
This commit is contained in:
Paul Campbell 2024-12-31 07:49:27 +00:00
parent 37f275d94b
commit 6e7244e1e4

View file

@ -51,10 +51,12 @@ impl Actor for ImportAttachmentActor {
this.trello_attachment.name
);
// - - - download the attachment from trello
let dir_path = this.ctx.temp_fs.base().join(&*this.trello_attachment.id);
let dir = this.ctx.temp_fs.dir(&dir_path);
dir.create()?; // FIXME: (#6) handle error
let file_path = dir_path.join(&*this.trello_attachment.name);
let file_name = f!(
"{}-{}",
this.trello_attachment.id,
this.trello_attachment.name
);
let file_path = this.ctx.temp_fs.base().join(&file_name);
ask!(this.rate_limit_actor, RequestToken)?; // FIXME: (#6) handle error
let attachment_path = this
.ctx
@ -101,8 +103,6 @@ impl Actor for ImportAttachmentActor {
attachment_file
.remove()
.with_context(|| f!("deleting temp file {attachment_file}"))?; // FIXME: (#6) handle error
dir.remove()
.with_context(|| f!("deleting temp dir {dir}"))?; // FIXME: (#6) handle error
tracing::info!("ImportAttachmentActor finished");
Ok(actor_ref.stop_gracefully().await?)