mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-02-14 15:38:42 -06:00
[server] Fix auto rename upload response with wrong id on conflict
This commit is contained in:
@@ -41,6 +41,10 @@ func handleUploadRequest(c *gin.Context) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
// Needed to be able to retreive the created resource
|
||||
if id == uuid.Nil {
|
||||
id, _ = uuid.NewV7()
|
||||
}
|
||||
|
||||
// TODO: Calculate and verify sha sum
|
||||
|
||||
@@ -77,7 +81,13 @@ func handleUploadRequest(c *gin.Context) {
|
||||
}
|
||||
|
||||
// id may have changed if this is an overwrite
|
||||
r, err := f.ResourceByPathWithRoot(params.Path)
|
||||
var r core.Resource
|
||||
if params.Conflict == core.ResourceBindConflictResolutionOverwrite || params.Conflict == core.ResourceBindConflictResolutionDelete {
|
||||
r, err = f.ResourceByPathWithRoot(params.Path)
|
||||
} else {
|
||||
r, err = f.ResourceByID(id)
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -180,6 +180,10 @@ func handlePartialUploadsFinalizeRequest(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if resourceID == uuid.Nil {
|
||||
resourceID, _ = uuid.NewV7()
|
||||
}
|
||||
|
||||
f := authenticator.GetFileSystem(c)
|
||||
err = func() error {
|
||||
// TODO: #perf disk I/O in tx
|
||||
@@ -206,7 +210,13 @@ func handlePartialUploadsFinalizeRequest(c *gin.Context) {
|
||||
}
|
||||
|
||||
// id may have changed if this is an overwrite
|
||||
r, err := f.ResourceByPathWithRoot(params.Path)
|
||||
var r core.Resource
|
||||
if params.Conflict == core.ResourceBindConflictResolutionOverwrite || params.Conflict == core.ResourceBindConflictResolutionDelete {
|
||||
r, err = f.ResourceByPathWithRoot(params.Path)
|
||||
} else {
|
||||
r, err = f.ResourceByID(resourceID)
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ import (
|
||||
type ResourceBindConflictResolution int32
|
||||
|
||||
const (
|
||||
ResourceBindConflictResolutionError = ResourceBindConflictResolution(0) // Error if exists
|
||||
ResourceBindConflictResolutionEnsure = ResourceBindConflictResolution(1) // Error if type mismatch
|
||||
ResourceBindConflictResolutionRename = ResourceBindConflictResolution(2) // Auto rename new resource
|
||||
ResourceBindConflictResolutionOverwrite = ResourceBindConflictResolution(3) // Delete existing resource only if type mismatch (preserves props)
|
||||
ResourceBindConflictResolutionDelete = ResourceBindConflictResolution(4) // Delete existing resource before creating
|
||||
ResourceBindConflictResolutionError = ResourceBindConflictResolution(0) // Error if exists. ID and path preserved
|
||||
ResourceBindConflictResolutionEnsure = ResourceBindConflictResolution(1) // Error if type mismatch. ID and path preserved
|
||||
ResourceBindConflictResolutionRename = ResourceBindConflictResolution(2) // Auto rename new resource. ID preserved, path may change
|
||||
ResourceBindConflictResolutionOverwrite = ResourceBindConflictResolution(3) // Delete existing resource only if type mismatch (preserves props). Path preserved, ID may change
|
||||
ResourceBindConflictResolutionDelete = ResourceBindConflictResolution(4) // Delete existing resource before creating. ID and path preserved
|
||||
)
|
||||
|
||||
func CheckResourceNameInvalid(s string) bool {
|
||||
|
||||
Reference in New Issue
Block a user