Skip to content

Commit

Permalink
Add experimental post-receive hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Jan 26, 2017
1 parent f5a2be3 commit 675f8fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .hooks/post-receive
Original file line number Diff line number Diff line change
@@ -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})"
4 changes: 3 additions & 1 deletion cmd/tusd/cli/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type HookType string
const (
HookPostFinish HookType = "post-finish"
HookPostTerminate HookType = "post-terminate"
HookPostTerminate HookType = "post-terminate"
HookPreCreate HookType = "pre-create"
)

Expand Down Expand Up @@ -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)
}
}
}()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 675f8fc

Please sign in to comment.