Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ff3309

Browse files
committedMar 17, 2025·
PATCH /api/resource reconstruction
1 parent fcbe1f3 commit 0ff3309

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed
 

‎pkg/fileutils/patch.go ‎pkg/common/patch.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package fileutils
1+
package common
22

33
import (
44
"context"
5-
"files/pkg/common"
65
"files/pkg/errors"
76
"files/pkg/files"
7+
"files/pkg/fileutils"
88
"files/pkg/preview"
99
"fmt"
1010
"github.com/spf13/afero"
@@ -49,10 +49,10 @@ func AddVersionSuffix(source string, fs afero.Fs, isDir bool) string {
4949
return source
5050
}
5151

52-
func PatchAction(ctx context.Context, action, src, dst string, d *common.Data, fileCache FileCache) error {
52+
func PatchAction(ctx context.Context, action, src, dst string, d *Data, fileCache fileutils.FileCache) error {
5353
switch action {
5454
case "copy":
55-
return Copy(files.DefaultFs, src, dst)
55+
return fileutils.Copy(files.DefaultFs, src, dst)
5656
case "rename":
5757
src = path.Clean("/" + src)
5858
dst = path.Clean("/" + dst)
@@ -74,7 +74,7 @@ func PatchAction(ctx context.Context, action, src, dst string, d *common.Data, f
7474
return err
7575
}
7676

77-
return MoveFile(files.DefaultFs, src, dst)
77+
return fileutils.MoveFile(files.DefaultFs, src, dst)
7878
default:
7979
return fmt.Errorf("unsupported action %s: %w", action, errors.ErrInvalidRequestParams)
8080
}

‎pkg/drives/base.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (rs *BaseResourceService) PatchHandler(fileCache fileutils.FileCache) handl
339339
return http.StatusForbidden, nil
340340
}
341341

342-
err = fileutils.CheckParent(src, dst)
342+
err = common.CheckParent(src, dst)
343343
if err != nil {
344344
return http.StatusBadRequest, err
345345
}
@@ -351,11 +351,11 @@ func (rs *BaseResourceService) PatchHandler(fileCache fileutils.FileCache) handl
351351
}
352352
}
353353
if rename {
354-
dst = fileutils.AddVersionSuffix(dst, files.DefaultFs, strings.HasSuffix(src, "/"))
354+
dst = common.AddVersionSuffix(dst, files.DefaultFs, strings.HasSuffix(src, "/"))
355355
}
356356

357357
klog.Infoln("Before patch action:", src, dst, action, rename)
358-
err = fileutils.PatchAction(r.Context(), action, src, dst, d, fileCache)
358+
err = common.PatchAction(r.Context(), action, src, dst, d, fileCache)
359359

360360
return common.ErrToStatus(err), err
361361
}

‎pkg/drives/sync.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,25 @@ func (rc *SyncResourceService) PutHandler(w http.ResponseWriter, r *http.Request
157157
return http.StatusNotImplemented, fmt.Errorf("sync drive does not supoort editing files for the time being")
158158
}
159159

160-
func (rc *SyncResourceService) PatchHandler(w http.ResponseWriter, r *http.Request, d *common.Data) (int, error) {
161-
src := r.URL.Path
162-
dst := r.URL.Query().Get("destination")
160+
func (rc *SyncResourceService) PatchHandler(fileCache fileutils.FileCache) handleFunc {
161+
return func(w http.ResponseWriter, r *http.Request, d *common.Data) (int, error) {
162+
src := r.URL.Path
163+
dst := r.URL.Query().Get("destination")
163164

164-
action := r.URL.Query().Get("action")
165-
var err error
166-
src, err = common.UnescapeURLIfEscaped(src)
167-
if err != nil {
168-
return common.ErrToStatus(err), err
169-
}
170-
dst, err = common.UnescapeURLIfEscaped(dst)
171-
if err != nil {
165+
action := r.URL.Query().Get("action")
166+
var err error
167+
src, err = common.UnescapeURLIfEscaped(src)
168+
if err != nil {
169+
return common.ErrToStatus(err), err
170+
}
171+
dst, err = common.UnescapeURLIfEscaped(dst)
172+
if err != nil {
173+
return common.ErrToStatus(err), err
174+
}
175+
176+
err = ResourceSyncPatch(action, src, dst, r)
172177
return common.ErrToStatus(err), err
173178
}
174-
175-
err = ResourceSyncPatch(action, src, dst, r)
176-
return common.ErrToStatus(err), err
177179
}
178180

179181
type Dirent struct {

‎pkg/files/file.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"crypto/sha512"
99
"encoding/hex"
1010
"encoding/json"
11-
"files/pkg/common"
1211
"fmt"
1312
"hash"
1413
"io"
@@ -27,7 +26,7 @@ import (
2726
"files/pkg/errors"
2827
)
2928

30-
var DefaultFs = afero.NewBasePathFs(afero.NewOsFs(), common.RootPrefix)
29+
var DefaultFs = afero.NewBasePathFs(afero.NewOsFs(), os.Getenv("ROOT_PREFIX"))
3130
var DefaultSorting = Sorting{
3231
By: "name",
3332
Asc: true,

0 commit comments

Comments
 (0)
Please sign in to comment.