From a922196f20a373432c126d5e310b0d62c15f62e9 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 16 Apr 2026 20:41:13 +0000 Subject: [PATCH] Add mailer file utilities --- platform/file/mailer.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 platform/file/mailer.go diff --git a/platform/file/mailer.go b/platform/file/mailer.go new file mode 100644 index 00000000..310229e3 --- /dev/null +++ b/platform/file/mailer.go @@ -0,0 +1,32 @@ +package file + +import ( + "fmt" + "io" + "os" + + "github.com/rs/zerolog/log" +) + +func MailerFromReader(public_id string, body io.Reader) error { + filepath := MailerPath(public_id) + + // Create file in configured directory + dst, err := os.Create(filepath) + if err != nil { + return fmt.Errorf("Failed to create image file %s: %w", filepath, err) + } + defer dst.Close() + + // Copy rest of request body to file + _, err = io.Copy(dst, body) + if err != nil { + return fmt.Errorf("Unable to save file %s: %w", filepath, err) + } + log.Info().Str("filepath", filepath).Str("collection", collectionName(CollectionMailerPDF)).Msg("Saved image file content to collection") + return nil +} +func MailerPath(public_id string) string { + collection := CollectionMailerPDF + return fileContentPath(collection, public_id) +}