Add experimental post-receive hook

This commit is contained in:
Marius 2017-01-26 22:34:14 +01:00
parent f5a2be33c8
commit 675f8fcf04
2 changed files with 11 additions and 1 deletions

8
.hooks/post-receive Executable file
View File

@ -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})"

View File

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