From 0906fdbc9c8e6aaf3cf4fd798b761732ec3a882b Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 30 Sep 2026 21:59:31 +0200 Subject: [PATCH] add internal/app/ship.go --- internal/app/ship.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 internal/app/ship.go diff --git a/internal/app/ship.go b/internal/app/ship.go new file mode 100644 index 0000000..c9c4432 --- /dev/null +++ b/internal/app/ship.go @@ -0,0 +1,33 @@ +package app + +import ( + "fmt" + "os/exec" +) + +// scpArgs builds the scp command line. Files are uploaded in the given order; +// callers pass the playlist LAST so stream links never 404 before the files. +func scpArgs(files []string, target, keyPath string) []string { + args := []string{"-o", "StrictHostKeyChecking=accept-new", "-q"} + if keyPath != "" { + args = append(args, "-i", keyPath) + } + args = append(args, files...) + args = append(args, target) + return args +} + +// Ship uploads files to target (user@host:/path/) via scp. +func Ship(files []string, target, keyPath string) error { + if len(files) == 0 { + return nil + } + if target == "" { + return fmt.Errorf("ship target not configured") + } + out, err := exec.Command("scp", scpArgs(files, target, keyPath)...).CombinedOutput() + if err != nil { + return fmt.Errorf("scp to %s: %w: %s", target, err, out) + } + return nil +}