add enabled hook flag, call hook before getting file info
This commit is contained in:
parent
cb3c4e83c1
commit
8c0568b871
|
@ -4,3 +4,4 @@ data/
|
||||||
node_modules/
|
node_modules/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
./tusd
|
./tusd
|
||||||
|
cmd/tusd/tusd
|
||||||
|
|
|
@ -80,7 +80,7 @@ func ParseFlags() {
|
||||||
flag.StringVar(&Flags.AzBlobAccessTier, "azure-blob-access-tier", "", "Blob access tier when uploading new files (possible values: archive, cool, hot, '')")
|
flag.StringVar(&Flags.AzBlobAccessTier, "azure-blob-access-tier", "", "Blob access tier when uploading new files (possible values: archive, cool, hot, '')")
|
||||||
flag.StringVar(&Flags.AzObjectPrefix, "azure-object-prefix", "", "Prefix for Azure object names")
|
flag.StringVar(&Flags.AzObjectPrefix, "azure-object-prefix", "", "Prefix for Azure object names")
|
||||||
flag.StringVar(&Flags.AzEndpoint, "azure-endpoint", "", "Custom Endpoint to use for Azure BlockBlob Storage (requires azure-storage to be pass)")
|
flag.StringVar(&Flags.AzEndpoint, "azure-endpoint", "", "Custom Endpoint to use for Azure BlockBlob Storage (requires azure-storage to be pass)")
|
||||||
flag.StringVar(&Flags.EnabledHooksString, "hooks-enabled-events", "pre-create,post-create,post-receive,post-terminate,post-finish", "Comma separated list of enabled hook events (e.g. post-create,post-finish). Leave empty to enable default events")
|
flag.StringVar(&Flags.EnabledHooksString, "hooks-enabled-events", "pre-get,pre-create,post-create,post-receive,post-terminate,post-finish", "Comma separated list of enabled hook events (e.g. post-create,post-finish). Leave empty to enable default events")
|
||||||
flag.StringVar(&Flags.FileHooksDir, "hooks-dir", "", "Directory to search for available hooks scripts")
|
flag.StringVar(&Flags.FileHooksDir, "hooks-dir", "", "Directory to search for available hooks scripts")
|
||||||
flag.StringVar(&Flags.HttpHooksEndpoint, "hooks-http", "", "An HTTP endpoint to which hook events will be sent to")
|
flag.StringVar(&Flags.HttpHooksEndpoint, "hooks-http", "", "An HTTP endpoint to which hook events will be sent to")
|
||||||
flag.StringVar(&Flags.HttpHooksForwardHeaders, "hooks-http-forward-headers", "", "List of HTTP request headers to be forwarded from the client request to the hook endpoint")
|
flag.StringVar(&Flags.HttpHooksForwardHeaders, "hooks-http-forward-headers", "", "List of HTTP request headers to be forwarded from the client request to the hook endpoint")
|
||||||
|
|
|
@ -104,7 +104,7 @@ func SetupPreHooks(config *handler.Config) error {
|
||||||
|
|
||||||
config.PreUploadCreateCallback = preCreateCallback
|
config.PreUploadCreateCallback = preCreateCallback
|
||||||
config.PreFinishResponseCallback = preFinishCallback
|
config.PreFinishResponseCallback = preFinishCallback
|
||||||
config.PreGetResponseCallback = preGetCallback
|
config.PreGetCallback = preGetCallback
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,8 @@ func invokeHookSync(typ hooks.HookType, info handler.HookEvent, captureOutput bo
|
||||||
logEv(stdout, "UploadFinished", "id", id, "size", strconv.FormatInt(size, 10))
|
logEv(stdout, "UploadFinished", "id", id, "size", strconv.FormatInt(size, 10))
|
||||||
case hooks.HookPostTerminate:
|
case hooks.HookPostTerminate:
|
||||||
logEv(stdout, "UploadTerminated", "id", id)
|
logEv(stdout, "UploadTerminated", "id", id)
|
||||||
|
case hooks.HookPreGet:
|
||||||
|
logEv(stdout, "PreGet", "id", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hookHandler == nil {
|
if hookHandler == nil {
|
||||||
|
|
|
@ -719,6 +719,16 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// call the get hook before getting the file
|
||||||
|
if handler.config.PreGetCallback != nil {
|
||||||
|
if err := handler.config.PreGetCallback(newHookEvent(FileInfo{
|
||||||
|
ID: id,
|
||||||
|
}, r)); err != nil {
|
||||||
|
handler.sendError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if handler.composer.UsesLocker {
|
if handler.composer.UsesLocker {
|
||||||
lock, err := handler.lockUpload(id)
|
lock, err := handler.lockUpload(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -741,13 +751,6 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if handler.config.PreGetCallback != nil {
|
|
||||||
if err := handler.config.PreGetCallback(newHookEvent(info, r)); err != nil {
|
|
||||||
handler.sendError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set headers before sending responses
|
// Set headers before sending responses
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(info.Offset, 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(info.Offset, 10))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue