spaces: WIP CreateStorageSoace
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/graph/pkg/service/v0/errorcode"
|
||||
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
ctxpkg "github.com/cs3org/reva/pkg/ctx"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
@@ -50,6 +55,46 @@ func NewService(opts ...Option) Service {
|
||||
r.Get("/", svc.GetGroup)
|
||||
})
|
||||
})
|
||||
//POST /drives/{drive-id}/items/{parent-item-id}/children
|
||||
// POST /drives/marketing // creates a space called Marketing
|
||||
r.Route("/drives", func(r chi.Router) {
|
||||
r.Post("/{drive-id}", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
us, ok := ctxpkg.ContextGetUser(r.Context())
|
||||
if !ok {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusUnauthorized, "invalid user")
|
||||
return
|
||||
}
|
||||
|
||||
// do request
|
||||
// prepare ms graph response (https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0)
|
||||
|
||||
// get reva client
|
||||
client, err := svc.GetClient()
|
||||
if err != nil {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// prepare createspacerequest
|
||||
csr := provider.CreateStorageSpaceRequest{
|
||||
Owner: us,
|
||||
Type: "share",
|
||||
Name: chi.URLParam(r, "drive-id"),
|
||||
Quota: &provider.Quota{
|
||||
QuotaMaxBytes: 65536,
|
||||
QuotaMaxFiles: 20,
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.CreateStorageSpace(r.Context(), &csr)
|
||||
if err != nil {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(resp)
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user