@@ -15,9 +15,19 @@ import (
15
15
"github.com/the-egg-corp/thundergo/util"
16
16
)
17
17
18
+ const SUBMIT_ENDPOINT = "api/experimental/submission/submit"
19
+
18
20
const MAX_MARKDOWN_SIZE = 1000 * 100
19
21
const MAX_ICON_SIZE = 1024 * 1024 * 6
20
22
23
+ type ManifestMetadata struct {
24
+ Name string `json:"name"`
25
+ VersionNumber string `json:"version_number"`
26
+ WebsiteURL * string `json:"website_url"`
27
+ Description string `json:"description"`
28
+ Dependencies []string `json:"dependencies"`
29
+ }
30
+
21
31
type PackageSubmissionMetadata struct {
22
32
UUID string `json:"upload_uuid"`
23
33
Author string `json:"author_name"`
@@ -27,18 +37,28 @@ type PackageSubmissionMetadata struct {
27
37
HasNsfwContent bool `json:"has_nsfw_content"`
28
38
}
29
39
30
- type ManifestMetadata struct {
31
- Name string `json:"name"`
32
- VersionNumber string `json:"version_number"`
33
- WebsiteURL * string `json:"website_url"`
34
- Description string `json:"description"`
35
- Dependencies []string `json:"dependencies"`
40
+ type AvailableCommunity struct {
41
+ Community Community `json:"community"`
42
+ Categories []PackageCategory `json:"categories"`
43
+ URL string `json:"url"`
44
+ }
45
+
46
+ type PackageSubmissionResult struct {
47
+ PackageVersion PackageVersion `json:"package_version"`
48
+ AvailableCommunities []AvailableCommunity `json:"available_communities"`
36
49
}
37
50
38
- // TODO: Implement this. Should take an auth key which the user gathers from 'Service Accounts'
39
- // func SubmitPackage(data []byte) (bool, error) {
40
- // return false, nil
41
- // }
51
+ // Submits a package to Thunderstore given the zip file as bytes.
52
+ //
53
+ // An API key can be gathered via Settings -> Service Accounts. It is up to you to store and pass it safely.
54
+ func SubmitPackage (authKey string , metadata PackageSubmissionMetadata ) (* PackageSubmissionResult , error ) {
55
+ res , err := util .JsonPostRequest [PackageSubmissionMetadata , PackageSubmissionResult ](SUBMIT_ENDPOINT , metadata )
56
+ if err != nil {
57
+ return nil , errors .New ("error sending submission:\n " + err .Error ())
58
+ }
59
+
60
+ return & res , nil
61
+ }
42
62
43
63
func ValidateReadme (data []byte ) (bool , error ) {
44
64
if ! utf8 .Valid (data ) {
@@ -120,7 +140,7 @@ func ValidateManifest(author string, data []byte) (valid bool, errs []string, er
120
140
// - Is in the PNG format.
121
141
//
122
142
// - Dimensions match 256x256.
123
- func ValidateIcon (fileName string , data []byte ) (bool , error ) {
143
+ func ValidateIcon (data []byte ) (bool , error ) {
124
144
// Check bytes dont exceed
125
145
if len (data ) > MAX_ICON_SIZE {
126
146
return false , errors .New ("invalid icon: max file size is 6MB" )
0 commit comments