-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.go
166 lines (145 loc) · 5.08 KB
/
types.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
package api
import (
"time"
"github.com/Masterminds/semver/v3"
"github.com/minepkg/minepkg/pkg/manifest"
)
const (
// TypeMod indicates a mod
TypeMod = "mod"
// TypeModpack indicates a modpack
TypeModpack = "modpack"
)
// User describes a registered user
type User struct {
DisplayName string `json:"displayName"`
Email string `json:"email"`
}
// Project is a project
type Project struct {
client *MinepkgAPI
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
Readme string `json:"readme,omitempty"`
Links struct {
Source string `json:"source,omitempty"`
Homepage string `json:"homepage,omitempty"`
} `json:"links,omitempty"`
Stats *ProjectStats `json:"stats,omitempty"`
Unofficial bool `json:"unofficial,omitempty"`
}
// ProjectStats contains statistics for a project
type ProjectStats struct {
TotalDownloads uint32 `json:"totalDownloads"`
}
// ReleaseMeta is metadata for a release. found in the `meta` field
type ReleaseMeta struct {
IPFSHash string `json:"ipfsHash,omitempty"`
Sha256 string `json:"sha256,omitempty"`
Published bool `json:"published"`
Unofficial *bool `json:"unofficial,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
}
// Release is a released version of a project
type Release struct {
*manifest.Manifest
client *MinepkgAPI
Meta *ReleaseMeta `json:"meta,omitempty"`
Tests map[string]ReleaseTest `json:"tests,omitempty"`
}
// NewRelease returns a `Release` object. Only exists locally. Can be used to POST a new release to the API
func (a *MinepkgAPI) NewRelease(m *manifest.Manifest) *Release {
return &Release{
Manifest: m,
client: a,
}
}
// NewUnpublishedRelease returns a `Release` object that has `Meta.published` set to false.
// should be used if you want to upload an artifact after publishing this release
// Only exists locally. Can be used to POST a new release to the API
func (a *MinepkgAPI) NewUnpublishedRelease(m *manifest.Manifest) *Release {
return &Release{
Manifest: m,
client: a,
Meta: &ReleaseMeta{Published: false},
}
}
// ReleaseTest is a test of the package
type ReleaseTest struct {
ID string `json:"_id"`
Minecraft string `json:"minecraft"`
Works bool `json:"works"`
}
func (rt *ReleaseTest) worksWithMCVersion(mcVersion *semver.Version) bool {
return rt.Works && (mcVersion == nil || mcVersion.Equal(mcVersion))
}
// Requirements contains the wanted Minecraft version
// and either the required Forge or Fabric version
type Requirements struct {
Minecraft string `json:"minecraft"`
Forge string `json:"forge,omitempty"`
Fabric string `json:"fabric,omitempty"`
}
// Dependency in verbose form
type Dependency struct {
client *MinepkgAPI
// Provider is only minepkg for now. Kept for future extensions
Provider string `json:"provider"`
// Name is the name of the package (eg. storage-drawers)
Name string `json:"name"`
// VersionRequirement is a semver version Constraint
// Example: `^2.9.22` or `5.x.x`
VersionRequirement string `json:"versionRequirement"`
}
// ForgeVersion is a release of forge
type ForgeVersion struct {
Branch string `json:"branch"`
Build int `json:"build"`
Files [][]string `json:"files"`
McVersion string `json:"mcversion"`
Modified int `json:"modified"`
Version string `json:"version"`
Recommended bool `json:"recommended"`
}
// MinepkgError is the json response if the response
// was not successful
type MinepkgError struct {
StatusCode uint16 `json:"statusCode"`
Status string `json:"error"`
Message string `json:"message"`
// ResolveError is only present for release queries
ResolveError string `json:"resolveError"`
}
func (m MinepkgError) Error() string {
return m.Status + ": " + m.Message
}
// CrashReportPackage is a package in a crash report
type CrashReportPackage struct {
Name string `json:"name"`
Platform string `json:"platform"`
Version string `json:"version"`
}
// CrashReportFabricDetail is a the fabric part of the crash report
type CrashReportFabricDetail struct {
Loader string `json:"loader"`
Mapping string `json:"mapping"`
}
// CrashReportForgeDetail is a the forge part of the crash report
type CrashReportForgeDetail struct {
Loader string `json:"loader"`
}
// CrashReport is a crash report
type CrashReport struct {
Package CrashReportPackage `json:"package"`
Fabric *CrashReportFabricDetail `json:"fabric,omitempty"`
Forge *CrashReportForgeDetail `json:"forge,omitempty"`
MinecraftVersion string `json:"minecraftVersion"`
Server bool `json:"server"`
Mods map[string]string `json:"mods"`
Logs string `json:"logs,omitempty"`
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
JavaVersion string `json:"javaVersion,omitempty"`
ExitCode int `json:"exitCode,omitempty"`
}