bump reva

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2024-08-23 17:50:35 +02:00
parent 5698bf2d43
commit 23adc13156
14 changed files with 146 additions and 157 deletions
-20
View File
@@ -199,7 +199,6 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
if origin := r.Header.Get("Origin"); !cors.Disable && origin != "" {
originIsAllowed := cors.AllowOrigin.MatchString(origin)
if !originIsAllowed {
fmt.Println("ORIGIN IS NOT ALLOWED", origin)
handler.sendError(c, ErrOriginNotAllowed)
return
}
@@ -692,14 +691,12 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
// PatchFile adds a chunk to an upload. This operation is only allowed
// if enough space in the upload is left.
func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request) {
fmt.Println("PATCH FILE")
c := handler.getContext(w, r)
isTusV1 := !handler.usesIETFDraft(r)
// Check for presence of application/offset+octet-stream
if isTusV1 && r.Header.Get("Content-Type") != "application/offset+octet-stream" {
fmt.Println("WRONG CONTENT TYPE")
handler.sendError(c, ErrInvalidContentType)
return
}
@@ -707,14 +704,12 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
// Check for presence of a valid Upload-Offset Header
offset, err := strconv.ParseInt(r.Header.Get("Upload-Offset"), 10, 64)
if err != nil || offset < 0 {
fmt.Println("WRONG OFFSET")
handler.sendError(c, ErrInvalidOffset)
return
}
id, err := extractIDFromPath(r.URL.Path)
if err != nil {
fmt.Println("WRONG ID")
handler.sendError(c, err)
return
}
@@ -723,7 +718,6 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
if handler.composer.UsesLocker {
lock, err := handler.lockUpload(c, id)
if err != nil {
fmt.Println("WRONG LOCK")
handler.sendError(c, err)
return
}
@@ -733,27 +727,23 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
upload, err := handler.composer.Core.GetUpload(c, id)
if err != nil {
fmt.Println("WRONG UPLOAD")
handler.sendError(c, err)
return
}
info, err := upload.GetInfo(c)
if err != nil {
fmt.Println("WRONG INFO")
handler.sendError(c, err)
return
}
// Modifying a final upload is not allowed
if info.IsFinal {
fmt.Println("WRONG FINAL")
handler.sendError(c, ErrModifyFinal)
return
}
if offset != info.Offset {
fmt.Println("WRONG INFO OFFSET")
handler.sendError(c, ErrMismatchOffset)
return
}
@@ -770,32 +760,27 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
// Do not proxy the call to the data store if the upload is already completed
if !info.SizeIsDeferred && info.Offset == info.Size {
resp.Header["Upload-Offset"] = strconv.FormatInt(offset, 10)
fmt.Println("UPLOAD ALREADY COMPLETED")
handler.sendResp(c, resp)
return
}
if r.Header.Get("Upload-Length") != "" {
if !handler.composer.UsesLengthDeferrer {
fmt.Println("UPLOAD LENGTH DEFERRER")
handler.sendError(c, ErrNotImplemented)
return
}
if !info.SizeIsDeferred {
fmt.Println("UPLOAD LENGTH NOT DEFERED")
handler.sendError(c, ErrInvalidUploadLength)
return
}
uploadLength, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
if err != nil || uploadLength < 0 || uploadLength < info.Offset || (handler.config.MaxSize > 0 && uploadLength > handler.config.MaxSize) {
fmt.Println("UPLOAD LENGTH INVALID")
handler.sendError(c, ErrInvalidUploadLength)
return
}
lengthDeclarableUpload := handler.composer.LengthDeferrer.AsLengthDeclarableUpload(upload)
if err := lengthDeclarableUpload.DeclareLength(c, uploadLength); err != nil {
fmt.Println("UPLOAD LENGTH DECLARED")
handler.sendError(c, err)
return
}
@@ -806,7 +791,6 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
resp, err = handler.writeChunk(c, resp, upload, info)
if err != nil {
fmt.Println("CANT WRITE CHUNK")
handler.sendError(c, err)
return
}
@@ -815,7 +799,6 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
if willCompleteUpload && info.SizeIsDeferred {
info, err = upload.GetInfo(c)
if err != nil {
fmt.Println("CANT GET INFO")
handler.sendError(c, err)
return
}
@@ -824,7 +807,6 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
lengthDeclarableUpload := handler.composer.LengthDeferrer.AsLengthDeclarableUpload(upload)
if err := lengthDeclarableUpload.DeclareLength(c, uploadLength); err != nil {
fmt.Println("CANT UPLOAD LENGTH")
handler.sendError(c, err)
return
}
@@ -834,14 +816,12 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
resp, err = handler.finishUploadIfComplete(c, resp, upload, info)
if err != nil {
fmt.Println("CANT COMPLETE")
handler.sendError(c, err)
return
}
}
handler.sendResp(c, resp)
fmt.Println("PATCH COMPLETE")
}
// writeChunk reads the body from the requests r and appends it to the upload