Add experimental post-receive hook
This commit is contained in:
parent
f5a2be33c8
commit
675f8fcf04
|
@ -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})"
|
|
@ -16,6 +16,7 @@ type HookType string
|
||||||
const (
|
const (
|
||||||
HookPostFinish HookType = "post-finish"
|
HookPostFinish HookType = "post-finish"
|
||||||
HookPostTerminate HookType = "post-terminate"
|
HookPostTerminate HookType = "post-terminate"
|
||||||
|
HookPostTerminate HookType = "post-terminate"
|
||||||
HookPreCreate HookType = "pre-create"
|
HookPreCreate HookType = "pre-create"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ func SetupPostHooks(handler *tusd.Handler) {
|
||||||
case info := <-handler.TerminatedUploads:
|
case info := <-handler.TerminatedUploads:
|
||||||
invokeHook(HookPostTerminate, info)
|
invokeHook(HookPostTerminate, info)
|
||||||
case info := <-handler.UploadProgress:
|
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 := os.Environ()
|
||||||
env = append(env, "TUS_ID="+info.ID)
|
env = append(env, "TUS_ID="+info.ID)
|
||||||
env = append(env, "TUS_SIZE="+strconv.FormatInt(info.Size, 10))
|
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)
|
jsonInfo, err := json.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue