diff --git a/server/ctrl/share.go b/server/ctrl/share.go new file mode 100644 index 00000000..8c423b1f --- /dev/null +++ b/server/ctrl/share.go @@ -0,0 +1,51 @@ +package ctrl + +import ( + "github.com/mickael-kerjean/mux" + . "github.com/mickael-kerjean/nuage/server/common" + "github.com/mickael-kerjean/nuage/server/model" + "net/http" +) + +type ShareAPI struct { + Id string `json:"id"` + Path string `json:"path"` + Role string `json:"role"` + Password string `json:"password"` + Users []string `json:"users"` + CanManageOwn bool `json:"can_manage_own"` + CanShare bool `json:"can_share"` + Expire int `json:"expire"` + Link string `json:"link"` +} + +func ShareList(ctx App, res http.ResponseWriter, req *http.Request) { + p := extractParams(req) + listOfSharedLinks := model.ShareList(p) + SendSuccessResults(res, listOfSharedLinks) +} + +func ShareUpsert(ctx App, res http.ResponseWriter, req *http.Request) { + p := extractParams(req) + err := model.ShareUpsert(p, model.ShareParams{}) + if err != nil { + SendErrorResult(res, err) + return + } + SendSuccessResult(res, nil) +} + +func ShareDelete(ctx App, res http.ResponseWriter, req *http.Request) { + p := extractParams(req) + err := model.ShareDelete(p) + if err != nil { + SendErrorResult(res, err) + return + } + SendSuccessResult(res, nil) +} + +func extractParams(req *http.Request) model.ShareKey { + vars := mux.Vars(req) + return model.ShareKey{vars["id"], "", ""} +}