Skip to content

Commit 99c69c8

Browse files
committed
POST /api/resource reconstruction
1 parent af111d9 commit 99c69c8

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

pkg/http/resource.go

+11-28
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"os"
1313
"path"
1414
"path/filepath"
15-
"strconv"
1615
"strings"
1716
"time"
1817

@@ -62,37 +61,21 @@ func resourceDeleteHandler(fileCache fileutils.FileCache) handleFunc {
6261
}
6362

6463
func resourcePostHandler(w http.ResponseWriter, r *http.Request, d *common.Data) (int, error) {
65-
srcType := r.URL.Query().Get("src")
66-
if srcType == "google" {
67-
_, status, err := drives.ResourcePostGoogle("", w, r, false)
68-
return status, err
69-
} else if srcType == "cloud" || srcType == "awss3" || srcType == "tencent" || srcType == "dropbox" {
70-
_, status, err := drives.ResourcePostCloudDrive("", w, r, false)
71-
return status, err
72-
}
64+
start := time.Now()
65+
klog.Infoln("Function resourcePostHandler starts at", start)
66+
defer func() {
67+
elapsed := time.Since(start)
68+
klog.Infof("Function resourcePostHandler execution time: %v\n", elapsed)
69+
}()
7370

74-
modeParam := r.URL.Query().Get("mode")
71+
srcType := r.URL.Query().Get("src")
7572

76-
mode, err := strconv.ParseUint(modeParam, 8, 32)
77-
if err != nil || modeParam == "" {
78-
mode = 0775
73+
handler, err := drives.GetResourceService(srcType)
74+
if err != nil {
75+
return http.StatusBadRequest, err
7976
}
8077

81-
fileMode := os.FileMode(mode)
82-
83-
// Directories creation on POST.
84-
if strings.HasSuffix(r.URL.Path, "/") {
85-
if err = files.DefaultFs.MkdirAll(r.URL.Path, fileMode); err != nil {
86-
klog.Errorln(err)
87-
return common.ErrToStatus(err), err
88-
}
89-
if err = fileutils.Chown(files.DefaultFs, r.URL.Path, 1000, 1000); err != nil {
90-
klog.Errorf("can't chown directory %s to user %d: %s", r.URL.Path, 1000, err)
91-
return common.ErrToStatus(err), err
92-
}
93-
return http.StatusOK, nil
94-
}
95-
return http.StatusBadRequest, fmt.Errorf("%s is not a valid directory path", r.URL.Path)
78+
return handler.PostHandler(w, r, d)
9679
}
9780

9881
func resourcePutHandler(w http.ResponseWriter, r *http.Request, d *common.Data) (int, error) {

0 commit comments

Comments
 (0)