add custom appid specifying support

This commit is contained in:
matu6968 2024-11-21 12:11:12 +01:00
parent cabe4c1b42
commit 9795ee0e4b
2 changed files with 21 additions and 4 deletions

View File

@ -52,7 +52,7 @@ AUTH_TOKEN=bearer-token-here # Put your token generated from the server .env fil
Info: "This is a camera app", Info: "This is a camera app",
Pub: "matu6968", Pub: "matu6968",
} }
newApp, err := c.UploadApp(metadata, "./index.js") newApp, err := client.UploadApp(metadata, "./index.js", "123456789011") // custom app id is optional
if err != nil { if err != nil {
log.Fatal("Failed to upload app:", err) log.Fatal("Failed to upload app:", err)
} }

View File

@ -33,6 +33,12 @@ type AppMetadata struct {
Pub string `json:"pub"` Pub string `json:"pub"`
} }
// Extended metadata struct to include optional AppID
type uploadMetadata struct {
AppMetadata
AppID string `json:"appid,omitempty"`
}
// NewClient creates a new AppStore client // NewClient creates a new AppStore client
func NewClient(baseURL, authToken string) *AppStoreClient { func NewClient(baseURL, authToken string) *AppStoreClient {
return &AppStoreClient{ return &AppStoreClient{
@ -62,14 +68,20 @@ func (c *AppStoreClient) GetApps() ([]App, error) {
return apps, nil return apps, nil
} }
// UploadApp uploads a new app to the store // UploadApp uploads a new app to the store with an optional custom app ID
func (c *AppStoreClient) UploadApp(metadata AppMetadata, filePath string) (*App, error) { func (c *AppStoreClient) UploadApp(metadata AppMetadata, filePath string, customAppID string) (*App, error) {
// Create extended metadata with optional AppID
extendedMetadata := uploadMetadata{
AppMetadata: metadata,
AppID: customAppID, // Will be omitted from JSON if empty
}
// Create multipart form // Create multipart form
body := &bytes.Buffer{} body := &bytes.Buffer{}
writer := multipart.NewWriter(body) writer := multipart.NewWriter(body)
// Add metadata // Add metadata
metadataBytes, err := json.Marshal(metadata) metadataBytes, err := json.Marshal(extendedMetadata)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -124,6 +136,11 @@ func (c *AppStoreClient) UploadApp(metadata AppMetadata, filePath string) (*App,
return &newApp, nil return &newApp, nil
} }
// Backwards compatibility wrapper
func (c *AppStoreClient) UploadAppSimple(metadata AppMetadata, filePath string) (*App, error) {
return c.UploadApp(metadata, filePath, "")
}
// EditApp updates an existing app // EditApp updates an existing app
func (c *AppStoreClient) EditApp(appID string, metadata AppMetadata, filePath string) error { func (c *AppStoreClient) EditApp(appID string, metadata AppMetadata, filePath string) error {
body := &bytes.Buffer{} body := &bytes.Buffer{}