-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathinstall_version_switch_queue.go
71 lines (55 loc) · 1.74 KB
/
install_version_switch_queue.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package install
import (
"fmt"
"github.com/itchio/butler/butlerd/messages"
itchio "github.com/itchio/go-itchio"
"github.com/itchio/butler/butlerd"
"github.com/itchio/butler/cmd/operate"
"github.com/pkg/errors"
)
func InstallVersionSwitchQueue(rc *butlerd.RequestContext, params *butlerd.InstallVersionSwitchQueueParams) (*butlerd.InstallVersionSwitchQueueResult, error) {
consumer := rc.Consumer
cave := operate.ValidateCave(rc, params.CaveID)
consumer.Infof("Looking for other versions of %s", operate.GameToString(cave.Game))
upload := cave.Upload
if upload == nil {
return nil, fmt.Errorf("No other versions available for %s", operate.GameToString(cave.Game))
}
credentials := operate.CredentialsForGameID(rc.DB(), cave.Game.ID)
client, err := operate.ClientFromCredentials(credentials)
if err != nil {
return nil, errors.WithStack(err)
}
buildsRes, err := client.ListUploadBuilds(&itchio.ListUploadBuildsParams{
UploadID: upload.ID,
DownloadKeyID: credentials.DownloadKey,
})
if err != nil {
return nil, errors.WithStack(err)
}
pickRes, err := messages.InstallVersionSwitchPick.Call(rc, &butlerd.InstallVersionSwitchPickParams{
Upload: upload,
Builds: buildsRes.Builds,
})
if err != nil {
return nil, errors.WithStack(err)
}
if pickRes.Index < 0 {
return nil, &butlerd.ErrAborted{}
}
build := buildsRes.Builds[pickRes.Index]
if true {
return nil, errors.New("We're up to InstallQueue and butler doesn't fully handle downloads yet :o")
}
_, err = InstallQueue(rc, &butlerd.InstallQueueParams{
CaveID: params.CaveID,
Game: cave.Game,
Upload: cave.Upload,
Build: build,
})
if err != nil {
return nil, errors.WithStack(err)
}
res := &butlerd.InstallVersionSwitchQueueResult{}
return res, nil
}