Pass info object as JSON blob to hook

This commit is contained in:
Marius 2016-02-22 13:59:28 +01:00
parent a949cb6b81
commit 0070379a91
2 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
echo "Upload finished"
printenv
echo "Upload $TUS_ID ($TUS_SIZE bytes) finished"
cat /dev/stdin | jq .

View File

@ -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