mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-28 19:22:31 +01:00
feature (share): backend of the sharing feature
This commit is contained in:
parent
346cec3130
commit
d1686c3aa2
1 changed files with 51 additions and 0 deletions
51
server/ctrl/share.go
Normal file
51
server/ctrl/share.go
Normal file
|
|
@ -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"], "", ""}
|
||||
}
|
||||
Loading…
Reference in a new issue