diff --git a/.hooks/post-receive b/.hooks/post-receive new file mode 100755 index 0000000..5f98009 --- /dev/null +++ b/.hooks/post-receive @@ -0,0 +1,8 @@ +#!/bin/bash + +id="$TUS_ID" +offset="$TUS_OFFSET" +size="$TUS_SIZE" +progress=$((100 * $offset/$size)) + +echo "Upload ${id} is at ${progress}% (${offset}/${size})" diff --git a/cmd/tusd/cli/hooks.go b/cmd/tusd/cli/hooks.go index cddf414..090b0d4 100644 --- a/cmd/tusd/cli/hooks.go +++ b/cmd/tusd/cli/hooks.go @@ -16,6 +16,7 @@ type HookType string const ( HookPostFinish HookType = "post-finish" HookPostTerminate HookType = "post-terminate" + HookPostTerminate HookType = "post-terminate" HookPreCreate HookType = "pre-create" ) @@ -45,7 +46,7 @@ func SetupPostHooks(handler *tusd.Handler) { case info := <-handler.TerminatedUploads: invokeHook(HookPostTerminate, info) case info := <-handler.UploadProgress: - fmt.Println(info.Size, info.Offset) + invokeHook(HookPostReceive, info) } } }() @@ -77,6 +78,7 @@ func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byt env := os.Environ() env = append(env, "TUS_ID="+info.ID) env = append(env, "TUS_SIZE="+strconv.FormatInt(info.Size, 10)) + env = append(env, "TUS_OFFSET="+strconv.FormatInt(info.Offset, 10)) jsonInfo, err := json.Marshal(info) if err != nil {