spaces: move all to its handler
This commit is contained in:
@@ -1,15 +1,21 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
ctxpkg "github.com/cs3org/reva/pkg/ctx"
|
||||||
|
|
||||||
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||||
|
v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||||
|
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/render"
|
"github.com/go-chi/render"
|
||||||
"github.com/owncloud/ocis/graph/pkg/service/v0/errorcode"
|
"github.com/owncloud/ocis/graph/pkg/service/v0/errorcode"
|
||||||
msgraph "github.com/owncloud/open-graph-api-go"
|
msgraph "github.com/owncloud/open-graph-api-go"
|
||||||
@@ -128,6 +134,42 @@ func (g Graph) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) {
|
|||||||
render.JSON(w, r, &listResponse{Value: files})
|
render.JSON(w, r, &listResponse{Value: files})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
||||||
|
us, ok := ctxpkg.ContextGetUser(r.Context())
|
||||||
|
if !ok {
|
||||||
|
errorcode.GeneralException.Render(w, r, http.StatusUnauthorized, "invalid user")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := g.GetClient()
|
||||||
|
if err != nil {
|
||||||
|
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
spaceName := chi.URLParam(r, "drive-name")
|
||||||
|
|
||||||
|
csr := provider.CreateStorageSpaceRequest{
|
||||||
|
Owner: us,
|
||||||
|
Type: "share",
|
||||||
|
Name: spaceName,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.GetStatus().GetCode() != v1beta11.Code_CODE_OK {
|
||||||
|
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, fmt.Errorf("").Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func cs3TimestampToTime(t *types.Timestamp) time.Time {
|
func cs3TimestampToTime(t *types.Timestamp) time.Time {
|
||||||
return time.Unix(int64(t.Seconds), int64(t.Nanos))
|
return time.Unix(int64(t.Seconds), int64(t.Nanos))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"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"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
)
|
)
|
||||||
@@ -55,45 +50,10 @@ func NewService(opts ...Option) Service {
|
|||||||
r.Get("/", svc.GetGroup)
|
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.Route("/drives", func(r chi.Router) {
|
||||||
r.Post("/{drive-id}", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
// This route is non-compliant with MS Graph implementation; creating a drive is not supported. There
|
||||||
us, ok := ctxpkg.ContextGetUser(r.Context())
|
// is no official MS SDK support for this method.
|
||||||
if !ok {
|
r.Post("/{drive-name}", svc.CreateDrive)
|
||||||
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