mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-12 04:00:23 +08:00
add /api/getUserRegex
This commit is contained in:
26
backend/regex.go
Normal file
26
backend/regex.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/fumiama/paper-manager/backend/global"
|
||||
)
|
||||
|
||||
func getUserRegex(token string) (*global.Regex, error) {
|
||||
user := usertokens.Get(token)
|
||||
if user == nil {
|
||||
return nil, errInvalidToken
|
||||
}
|
||||
return global.UserDB.GetUserRegex(*user.ID)
|
||||
}
|
||||
|
||||
func init() {
|
||||
apimap["/api/getUserRegex"] = &apihandler{"GET", func(w http.ResponseWriter, r *http.Request) {
|
||||
reg, err := getUserRegex(r.Header.Get("Authorization"))
|
||||
if err != nil {
|
||||
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||
return
|
||||
}
|
||||
writeresult(w, codeSuccess, reg, messageOk, typeSuccess)
|
||||
}}
|
||||
}
|
||||
Reference in New Issue
Block a user