diff --git a/.hooks/postfinish b/.hooks/postfinish index 843e10d..03c059a 100755 --- a/.hooks/postfinish +++ b/.hooks/postfinish @@ -1,4 +1,4 @@ #!/bin/bash -echo "Upload finished" -printenv +echo "Upload $TUS_ID ($TUS_SIZE bytes) finished" +cat /dev/stdin | jq . diff --git a/cmd/tusd/main.go b/cmd/tusd/main.go index e71b5a1..a4fd4aa 100644 --- a/cmd/tusd/main.go +++ b/cmd/tusd/main.go @@ -1,6 +1,8 @@ package main import ( + "bytes" + "encoding/json" "flag" "fmt" "log" @@ -10,7 +12,6 @@ import ( "os/exec" "path/filepath" "strconv" - "strings" "time" "github.com/tus/tusd" @@ -151,11 +152,14 @@ func invokeHook(info tusd.FileInfo) { env = append(env, "TUS_ID="+info.ID) env = append(env, "TUS_SIZE="+strconv.FormatInt(info.Size, 10)) - for k, v := range info.MetaData { - k = strings.ToUpper(k) - env = append(env, "TUS_METADATA_"+k+"="+v) + jsonInfo, err := json.Marshal(info) + if err != nil { + stderr.Printf("Error encoding JSON for hook: %s", err) } + reader := bytes.NewReader(jsonInfo) + cmd.Stdin = reader + cmd.Env = env cmd.Dir = hooksDir cmd.Stdout = os.Stdout