-
Notifications
You must be signed in to change notification settings - Fork 54
/
fetch_user.go
38 lines (30 loc) 路 940 Bytes
/
fetch_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package fetch
import (
"crawshaw.io/sqlite"
"github.com/itchio/butler/butlerd"
"github.com/itchio/butler/database/models"
"github.com/itchio/butler/endpoints/fetch/lazyfetch"
itchio "github.com/itchio/go-itchio"
)
func FetchUser(rc *butlerd.RequestContext, params butlerd.FetchUserParams) (*butlerd.FetchUserResult, error) {
ft := models.FetchTargetForUser(params.UserID)
res := &butlerd.FetchUserResult{}
lazyfetch.Do(rc, ft, params, res, func(targets lazyfetch.Targets) {
_, client := rc.ProfileClient(params.ProfileID)
userRes, err := client.GetUser(itchio.GetUserParams{
UserID: params.UserID,
})
models.Must(err)
rc.WithConn(func(conn *sqlite.Conn) {
models.MustSave(conn, userRes.User)
})
})
rc.WithConn(func(conn *sqlite.Conn) {
res.User = models.UserByID(conn, params.UserID)
})
if res.User == nil && !params.Fresh {
params.Fresh = true
return FetchUser(rc, params)
}
return res, nil
}