From 74e06ec1efaf4f4eb45ca0942056273535201a1a Mon Sep 17 00:00:00 2001 From: Yonah Date: Fri, 20 Mar 2026 03:19:36 +0900 Subject: [PATCH] cmd/streamdata: resolve un-mirrored asset Useful for uploading pending videos. Signed-off-by: Yonah --- cmd/streamdata/main.go | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/cmd/streamdata/main.go b/cmd/streamdata/main.go index 041a1cb..7f6d062 100644 --- a/cmd/streamdata/main.go +++ b/cmd/streamdata/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "cmp" "context" "errors" "fmt" @@ -11,6 +12,7 @@ import ( "os" "os/signal" "path" + "slices" "strings" "syscall" "time" @@ -228,6 +230,73 @@ func main() { }, ) + c.NewCommand( + "mirror", + "Populate mirror address of the next un-mirrored asset", + func([]string) (err error) { + if channel == nil { + return errors.New("mirror requires a channel selected") + } + + idents := slices.Collect(channel.All(&err, false)) + if err != nil { + return + } + slices.SortFunc(idents, func(a, b *streamdata.Ident) int { + return cmp.Compare(a.Serial, b.Serial) + }) + + unique := errors.New("entry already mirrored") + for _, ident := range idents { + if err = channel.Edit(ident, func(v *streamdata.VOD) (err error) { + if v.Mirror != "" { + return unique + } + + pathname := path.Join( + flagBase, + "upload"+streamdata.ChannelVODSuffix, + ) + if err = os.Symlink(path.Join( + "vod", + ident.String()+streamdata.ChannelVODSuffix, + ), pathname); err != nil { + return + } + log.Println("pending video at", pathname) + defer func() { + removeErr := os.Remove(pathname) + if err == nil { + err = removeErr + } + }() + + defer toErr(&err) + isattyStd() + br := bufio.NewReader(os.Stdin) + + retry: + fmt.Println(ident) + printVOD(v) + v.Mirror = require(promptTrimNoEmpty(br, "Mirror : ")) + if !require(promptBool(br, "Proceed? ", true)) { + v.Mirror = "" + goto retry + } + return nil + }); err != nil { + if err == unique { + err = nil + continue + } + return + } + break + } + return + }, + ) + c.MustParse(os.Args[1:], func(err error) { if channel != nil { if closeErr := channel.Close(); closeErr != nil {