2025-12-16 16:37:53 +00:00
|
|
|
package userfile
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
2026-02-08 04:36:12 +00:00
|
|
|
//"net/http"
|
2025-12-16 16:37:53 +00:00
|
|
|
"os"
|
|
|
|
|
|
2026-02-08 04:36:12 +00:00
|
|
|
//"github.com/Gleipnir-Technology/nidus-sync/config"
|
2025-12-16 16:37:53 +00:00
|
|
|
"github.com/google/uuid"
|
2026-01-16 14:52:11 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2025-12-16 16:37:53 +00:00
|
|
|
)
|
|
|
|
|
|
2026-02-08 04:36:12 +00:00
|
|
|
func FileContentWrite(body io.Reader, collection Collection, uid uuid.UUID) error {
|
2025-12-16 16:37:53 +00:00
|
|
|
// Create file in configured directory
|
2026-02-08 04:36:12 +00:00
|
|
|
filepath := fileContentPath(collection, uid)
|
2025-12-16 16:37:53 +00:00
|
|
|
dst, err := os.Create(filepath)
|
|
|
|
|
if err != nil {
|
2026-01-16 14:52:11 +00:00
|
|
|
log.Error().Err(err).Str("filepath", filepath).Msg("Failed to create audio file")
|
2025-12-16 16:37:53 +00:00
|
|
|
return fmt.Errorf("Failed to create audio file at %s: %v", 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 to create audio file at %s: %v", filepath, err)
|
|
|
|
|
}
|
2026-01-16 14:52:11 +00:00
|
|
|
log.Info().Str("filepath", filepath).Msg("Save audio file content")
|
2025-12-16 16:37:53 +00:00
|
|
|
return nil
|
|
|
|
|
}
|