mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-27 02:04:45 -07:00
Separate Conn and PrivateConn tracker interfaces
This commit is contained in:
35
http/api.go
35
http/api.go
@@ -102,11 +102,16 @@ func (t *Tracker) delTorrent(w http.ResponseWriter, r *http.Request, p httproute
|
||||
}
|
||||
|
||||
func (t *Tracker) getUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
|
||||
conn, err := t.pool.Get()
|
||||
base, err := t.pool.Get()
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
conn, private := base.(tracker.PrivateConn)
|
||||
if !private {
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
user, err := conn.FindUser(p.ByName("passkey"))
|
||||
if err == tracker.ErrUserDNE {
|
||||
return http.StatusNotFound, err
|
||||
@@ -136,11 +141,16 @@ func (t *Tracker) putUser(w http.ResponseWriter, r *http.Request, p httprouter.P
|
||||
return http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
conn, err := t.pool.Get()
|
||||
base, err := t.pool.Get()
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
conn, private := base.(tracker.PrivateConn)
|
||||
if !private {
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
err = conn.PutUser(&user)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
@@ -150,11 +160,16 @@ func (t *Tracker) putUser(w http.ResponseWriter, r *http.Request, p httprouter.P
|
||||
}
|
||||
|
||||
func (t *Tracker) delUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
|
||||
conn, err := t.pool.Get()
|
||||
base, err := t.pool.Get()
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
conn, private := base.(tracker.PrivateConn)
|
||||
if !private {
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
err = conn.DeleteUser(p.ByName("passkey"))
|
||||
if err == tracker.ErrUserDNE {
|
||||
return http.StatusNotFound, err
|
||||
@@ -166,11 +181,16 @@ func (t *Tracker) delUser(w http.ResponseWriter, r *http.Request, p httprouter.P
|
||||
}
|
||||
|
||||
func (t *Tracker) putClient(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
|
||||
conn, err := t.pool.Get()
|
||||
base, err := t.pool.Get()
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
conn, private := base.(tracker.PrivateConn)
|
||||
if !private {
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
err = conn.PutClient(p.ByName("clientID"))
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
@@ -180,11 +200,16 @@ func (t *Tracker) putClient(w http.ResponseWriter, r *http.Request, p httprouter
|
||||
}
|
||||
|
||||
func (t *Tracker) delClient(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
|
||||
conn, err := t.pool.Get()
|
||||
base, err := t.pool.Get()
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
conn, private := base.(tracker.PrivateConn)
|
||||
if !private {
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
err = conn.DeleteClient(p.ByName("clientID"))
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
|
||||
Reference in New Issue
Block a user