defensive code
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
Enhancement: Create a Space using the Graph API
|
||||||
|
|
||||||
|
Spaces can now be created on `POST /drive/{drive-name}`. Only users with the `create-space` permissions can perform this operation.
|
||||||
|
|
||||||
|
Allowed body form values are:
|
||||||
|
|
||||||
|
- `quota` (bytes) maximum amount of bytes stored in the space.
|
||||||
|
- `maxQuotaFiles` (integer) maximum amount of files supported by the space.
|
||||||
|
|
||||||
|
https://github.com/owncloud/ocis/pull/2471
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||||
@@ -144,6 +145,8 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.ParseForm()
|
||||||
|
|
||||||
s := sproto.NewPermissionService("com.owncloud.api.settings", grpc.DefaultClient)
|
s := sproto.NewPermissionService("com.owncloud.api.settings", grpc.DefaultClient)
|
||||||
|
|
||||||
_, err := s.GetPermissionByID(r.Context(), &sproto.GetPermissionByIDRequest{
|
_, err := s.GetPermissionByID(r.Context(), &sproto.GetPermissionByIDRequest{
|
||||||
@@ -162,14 +165,28 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
spaceName := chi.URLParam(r, "drive-name")
|
spaceName := chi.URLParam(r, "drive-name")
|
||||||
|
if spaceName == "" {
|
||||||
|
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, fmt.Errorf("invalid name").Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
quota, _ := strconv.ParseUint(r.Form.Get("quota"), 10, 64)
|
||||||
|
if quota == 0 {
|
||||||
|
quota = 65536 // set default quota if no form value was sent.
|
||||||
|
}
|
||||||
|
|
||||||
|
quotaMaxFiles, _ := strconv.ParseUint(r.Form.Get("quotaMaxFiles"), 10, 64)
|
||||||
|
if quotaMaxFiles == 0 {
|
||||||
|
quotaMaxFiles = 20 // set default quotaMaxFiles if no form value was sent.
|
||||||
|
}
|
||||||
|
|
||||||
csr := provider.CreateStorageSpaceRequest{
|
csr := provider.CreateStorageSpaceRequest{
|
||||||
Owner: us,
|
Owner: us,
|
||||||
Type: "share",
|
Type: "share",
|
||||||
Name: spaceName,
|
Name: spaceName,
|
||||||
Quota: &provider.Quota{
|
Quota: &provider.Quota{
|
||||||
QuotaMaxBytes: 65536,
|
QuotaMaxBytes: quota,
|
||||||
QuotaMaxFiles: 20,
|
QuotaMaxFiles: quotaMaxFiles,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user