-
Notifications
You must be signed in to change notification settings - Fork 6
/
endpoints_uploads.go
266 lines (210 loc) · 7.41 KB
/
endpoints_uploads.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package itchio
import (
"context"
"encoding/json"
)
// GameCredentials is your one-stop shop for all the
// things that allow access to a game or its uploads, such as:
// a download key, a password (for restricted pages), a secret
// (for private pages).
type GameCredentials struct {
DownloadKeyID int64 `json:"downloadKeyId,omitempty"`
Password string `json:"password,omitempty"`
Secret string `json:"secret,omitempty"`
}
//-------------------------------------------------------
// ListGameUploadsParams : params for ListGameUploads
type ListGameUploadsParams struct {
GameID int64
// Optional
Credentials GameCredentials
}
// ListGameUploadsResponse : response
type ListGameUploadsResponse struct {
Uploads []*Upload `json:"uploads"`
}
// ListGameUploads lists the uploads for a game that we have access to with our API key
// and game credentials.
func (c *Client) ListGameUploads(ctx context.Context, p ListGameUploadsParams) (*ListGameUploadsResponse, error) {
q := NewQuery(c, "/games/%d/uploads", p.GameID)
q.AddGameCredentials(p.Credentials)
r := &ListGameUploadsResponse{}
return r, q.Get(ctx, r)
}
//-------------------------------------------------------
// GetUploadParams : params for GetUpload
type GetUploadParams struct {
UploadID int64
// Optional
Credentials GameCredentials
}
// GetUploadResponse : response for GetUpload
type GetUploadResponse struct {
Upload *Upload `json:"upload"`
}
// GetUpload retrieves information about a single upload, by ID.
func (c *Client) GetUpload(ctx context.Context, params GetUploadParams) (*GetUploadResponse, error) {
q := NewQuery(c, "/uploads/%d", params.UploadID)
q.AddGameCredentials(params.Credentials)
r := &GetUploadResponse{}
return r, q.Get(ctx, r)
}
//-------------------------------------------------------
// ListUploadBuildsParams : params for ListUploadBuilds
type ListUploadBuildsParams struct {
UploadID int64
// Optional
Credentials GameCredentials
}
// ListUploadBuildsResponse : response for ListUploadBuilds
type ListUploadBuildsResponse struct {
Builds []*Build `json:"builds"`
}
// ListUploadBuilds lists recent builds for a given upload, by ID.
func (c *Client) ListUploadBuilds(ctx context.Context, params ListUploadBuildsParams) (*ListUploadBuildsResponse, error) {
q := NewQuery(c, "/uploads/%d/builds", params.UploadID)
q.AddGameCredentials(params.Credentials)
r := &ListUploadBuildsResponse{}
return r, q.Get(ctx, r)
}
//-------------------------------------------------------
// GetBuildParams : params for GetBuild
type GetBuildParams struct {
BuildID int64
// Optional
Credentials GameCredentials
}
// GetBuildResponse : response for GetBuild
type GetBuildResponse struct {
Build *Build `json:"build"`
}
// GetBuild retrieves info about a single build, by ID.
func (c *Client) GetBuild(ctx context.Context, p GetBuildParams) (*GetBuildResponse, error) {
q := NewQuery(c, "/builds/%d", p.BuildID)
q.AddGameCredentials(p.Credentials)
r := &GetBuildResponse{}
return r, q.Get(ctx, r)
}
//-------------------------------------------------------
// GetBuildUpgradePathParams : params for GetBuildUpgradePath
type GetBuildUpgradePathParams struct {
CurrentBuildID int64
TargetBuildID int64
// Optional
Credentials GameCredentials
}
// GetBuildUpgradePathResponse : response for GetBuildUpgradePath
type GetBuildUpgradePathResponse struct {
UpgradePath *UpgradePath `json:"upgradePath"`
}
// UpgradePath is a series of builds for which a (n,n+1) patch exists,
type UpgradePath struct {
Builds []*Build `json:"builds"`
}
// GetBuildUpgradePath returns the complete list of builds one
// needs to go through to go from one version to another.
// It only works when upgrading (at the time of this writing).
func (c *Client) GetBuildUpgradePath(ctx context.Context, p GetBuildUpgradePathParams) (*GetBuildUpgradePathResponse, error) {
q := NewQuery(c, "/builds/%d/upgrade-paths/%d", p.CurrentBuildID, p.TargetBuildID)
q.AddGameCredentials(p.Credentials)
r := &GetBuildUpgradePathResponse{}
return r, q.Get(ctx, r)
}
//-------------------------------------------------------
// NewDownloadSessionParams : params for NewDownloadSession
type NewDownloadSessionParams struct {
GameID int64
Credentials GameCredentials
}
// NewDownloadSessionResponse : response for NewDownloadSession
type NewDownloadSessionResponse struct {
UUID string `json:"uuid"`
}
// NewDownloadSession creates a new download session. It is used
// for more accurate download analytics. Downloading multiple patch
// and signature files may all be part of the same "download session":
// upgrading a game to its latest version. It should only count as one download.
func (c *Client) NewDownloadSession(ctx context.Context, p NewDownloadSessionParams) (*NewDownloadSessionResponse, error) {
q := NewQuery(c, "/games/%d/download-sessions", p.GameID)
q.AddGameCredentials(p.Credentials)
r := &NewDownloadSessionResponse{}
return r, q.Post(ctx, r)
}
//-------------------------------------------------------
// MakeUploadDownloadURLParams : params for MakeUploadDownloadURL
type MakeUploadDownloadURLParams struct {
UploadID int64
// Optional
UUID string
// Optional
Credentials GameCredentials
}
// MakeUploadDownloadURL generates a download URL for an upload
func (c *Client) MakeUploadDownloadURL(p MakeUploadDownloadURLParams) string {
q := NewQuery(c, "uploads/%d/download", p.UploadID)
q.AddAPICredentials()
q.AddGameCredentials(p.Credentials)
q.AddStringIfNonEmpty("uuid", p.UUID)
return q.URL()
}
//-------------------------------------------------------
// MakeBuildDownloadURLParams : params for MakeBuildDownloadURL
type MakeBuildDownloadURLParams struct {
BuildID int64
Type BuildFileType
// Optional: Defaults to BuildFileSubTypeDefault
SubType BuildFileSubType
// Optional
UUID string
// Optional
Credentials GameCredentials
}
// MakeBuildDownloadURL generates as download URL for a specific build
func (c *Client) MakeBuildDownloadURL(p MakeBuildDownloadURLParams) string {
subType := p.SubType
if subType == "" {
subType = BuildFileSubTypeDefault
}
q := NewQuery(c, "builds/%d/download/%s/%s", p.BuildID, p.Type, subType)
q.AddAPICredentials()
q.AddGameCredentials(p.Credentials)
q.AddStringIfNonEmpty("uuid", p.UUID)
return q.URL()
}
type GetUploadScannedArchiveParams struct {
UploadID int64
// Optional
Credentials GameCredentials
}
type GetBuildScannedArchiveParams struct {
BuildID int64
// Optional
Credentials GameCredentials
}
type GetScannedArchiveResponse struct {
ScannedArchive ScannedArchive `json:"scannedArchive"`
}
type ScannedArchive struct {
ObjectID int64
ObjectType ScannedArchiveObjectType
ExtractedSize int64
LaunchTargets *json.RawMessage
Manifest *json.RawMessage
}
type ScannedArchiveObjectType = string
const (
ScannedArchiveObjectTypeUpload ScannedArchiveObjectType = "upload"
ScannedArchiveObjectTypeBuild ScannedArchiveObjectType = "build"
)
func (c *Client) GetUploadScannedArchive(ctx context.Context, p GetUploadScannedArchiveParams) (*GetScannedArchiveResponse, error) {
q := NewQuery(c, "/uploads/%d/scanned-archive", p.UploadID)
q.AddGameCredentials(p.Credentials)
r := &GetScannedArchiveResponse{}
return r, q.Get(ctx, r)
}
func (c *Client) GetBuildScannedArchive(ctx context.Context, p GetBuildScannedArchiveParams) (*GetScannedArchiveResponse, error) {
q := NewQuery(c, "/builds/%d/scanned-archive", p.BuildID)
q.AddGameCredentials(p.Credentials)
r := &GetScannedArchiveResponse{}
return r, q.Get(ctx, r)
}