You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/file/public.go

57 lines
1.2 KiB
Go

3 years ago
package file
import (
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
"net/http"
"strconv"
)
/**
* @name: user
* @author: veypi <i@veypi.com>
* @date: 2021-12-04 11:49
* @descriptionuser
**/
3 years ago
func pubFileChecker(w http.ResponseWriter, r *http.Request) (prefix string, mountPoint string, ownerID string, actorID string, err error) {
3 years ago
m := w.(OneBD.Meta)
3 years ago
if r.Method == rfc.MethodGet {
mountPoint = ""
prefix = ""
ownerID = "public"
actorID = "public"
return
}
3 years ago
uuid := m.Params("uuid")
p := &oalib.PayLoad{}
h := r.Header.Get("auth_token")
if h == "" {
h = m.Query("auth_token")
}
var ok bool
ok, err = p.ParseToken(h, cfg.CFG.APPKey)
if !ok {
err = oerr.NoAuth
return
}
l := p.GetAuth(auth.APP, uuid)
if !l.CanDelete() && r.Method == rfc.MethodDelete {
err = oerr.NoAuth
}
if !l.CanUpdate() && (r.Method == "PUT" || r.Method == "MKCOL" || r.Method == "COPY" || r.Method == "MOVE") {
err = oerr.NoAuth
}
if err != nil {
return
}
actorID = strconv.Itoa(int(p.ID))
ownerID = uuid
3 years ago
mountPoint = "app/" + uuid
prefix = "app/" + uuid
3 years ago
return
}