From 9795ee0e4b84b4e0092d81e478aa7fcc4b37f802 Mon Sep 17 00:00:00 2001 From: matu6968 Date: Thu, 21 Nov 2024 12:11:12 +0100 Subject: [PATCH] add custom appid specifying support --- README.md | 2 +- webdesk-appmarket-golang.go | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1f3c63b..c3ac9e4 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ AUTH_TOKEN=bearer-token-here # Put your token generated from the server .env fil Info: "This is a camera app", 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 { log.Fatal("Failed to upload app:", err) } diff --git a/webdesk-appmarket-golang.go b/webdesk-appmarket-golang.go index b39b200..2c6793a 100644 --- a/webdesk-appmarket-golang.go +++ b/webdesk-appmarket-golang.go @@ -33,6 +33,12 @@ type AppMetadata struct { 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 func NewClient(baseURL, authToken string) *AppStoreClient { return &AppStoreClient{ @@ -62,14 +68,20 @@ func (c *AppStoreClient) GetApps() ([]App, error) { return apps, nil } -// UploadApp uploads a new app to the store -func (c *AppStoreClient) UploadApp(metadata AppMetadata, filePath string) (*App, error) { +// UploadApp uploads a new app to the store with an optional custom app ID +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 body := &bytes.Buffer{} writer := multipart.NewWriter(body) // Add metadata - metadataBytes, err := json.Marshal(metadata) + metadataBytes, err := json.Marshal(extendedMetadata) if err != nil { return nil, err } @@ -124,6 +136,11 @@ func (c *AppStoreClient) UploadApp(metadata AppMetadata, filePath string) (*App, 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 func (c *AppStoreClient) EditApp(appID string, metadata AppMetadata, filePath string) error { body := &bytes.Buffer{}