diff --git a/.gitignore b/.gitignore index a263e4d..3a99980 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ data/ node_modules/ .DS_Store ./tusd +cmd/tusd/tusd diff --git a/cmd/tusd/cli/flags.go b/cmd/tusd/cli/flags.go index 35aaeec..54e7649 100644 --- a/cmd/tusd/cli/flags.go +++ b/cmd/tusd/cli/flags.go @@ -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.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.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.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") diff --git a/cmd/tusd/cli/hooks.go b/cmd/tusd/cli/hooks.go index dec2f1b..0a69029 100644 --- a/cmd/tusd/cli/hooks.go +++ b/cmd/tusd/cli/hooks.go @@ -104,7 +104,7 @@ func SetupPreHooks(config *handler.Config) error { config.PreUploadCreateCallback = preCreateCallback config.PreFinishResponseCallback = preFinishCallback - config.PreGetResponseCallback = preGetCallback + config.PreGetCallback = preGetCallback 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)) case hooks.HookPostTerminate: logEv(stdout, "UploadTerminated", "id", id) + case hooks.HookPreGet: + logEv(stdout, "PreGet", "id", id) } if hookHandler == nil { diff --git a/pkg/handler/unrouted_handler.go b/pkg/handler/unrouted_handler.go index 88d4d11..825f165 100644 --- a/pkg/handler/unrouted_handler.go +++ b/pkg/handler/unrouted_handler.go @@ -719,6 +719,16 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) 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 { lock, err := handler.lockUpload(id) if err != nil { @@ -741,13 +751,6 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) 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 w.Header().Set("Content-Length", strconv.FormatInt(info.Offset, 10))