From ad5e486ba076a8980a0ddba0ad84fb4e1144a0c6 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 8 Dec 2015 22:08:54 +0100 Subject: [PATCH] Merge master --- datastore.go | 6 ++++++ unrouted_handler.go | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/datastore.go b/datastore.go index 8c335dc..c918643 100644 --- a/datastore.go +++ b/datastore.go @@ -55,3 +55,9 @@ type DataStore interface { // and writing, must return os.ErrNotExist or similar. Terminate(id string) error } + +type FinisherDataStore interface { + DataStore + + FinishUpload(id string) error +} diff --git a/unrouted_handler.go b/unrouted_handler.go index a980752..3c6fe21 100644 --- a/unrouted_handler.go +++ b/unrouted_handler.go @@ -369,10 +369,21 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request newOffset := offset + bytesWritten w.Header().Set("Upload-Offset", strconv.FormatInt(newOffset, 10)) - // If the upload is completed, send the info out to the channel - if handler.config.NotifyCompleteUploads && newOffset == info.Size { - info.Size = newOffset - handler.CompleteUploads <- info + // If the upload is completed, ... + if newOffset == info.Size { + // ... allow custom mechanism to finish and cleanup the upload + if store, ok := handler.dataStore.(FinisherDataStore); ok { + if err := store.FinishUpload(id); err != nil { + handler.sendError(w, r, err) + return + } + } + + // ... send the info out to the channel + if handler.config.NotifyCompleteUploads { + info.Size = newOffset + handler.CompleteUploads <- info + } } w.WriteHeader(http.StatusNoContent)