diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc39564..c93c431e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## v0.15.0 + +* Rename `VCSDeploymentType` enum to `VCSReferenceType` +* Change `CreateTemplateDeployment` method signature: replace `Version` parameter with `Type` (TemplateReferenceType) and `Reference` parameters +* Add `GetScreenshot` method to `Avatars` service +* Add `Theme`, `Timezone` and `Output` enums + ## v0.14.0 * Add `total` parameter to list queries allowing skipping counting rows in a table for improved performance diff --git a/account/account.go b/account/account.go index 9174353e..cd8aee1a 100644 --- a/account/account.go +++ b/account/account.go @@ -635,7 +635,7 @@ func (srv *Account) DeleteMFAAuthenticator(Type string)(*interface{}, error) { // // Deprecated: This API has been deprecated since 1.8.0. Please use `Account.createMFAChallenge` instead. func (srv *Account) CreateMfaChallenge(Factor string)(*models.MfaChallenge, error) { - path := "/account/mfa/challenge" + path := "/account/mfa/challenges" params := map[string]interface{}{} params["factor"] = Factor headers := map[string]interface{}{ @@ -672,7 +672,7 @@ func (srv *Account) CreateMfaChallenge(Factor string)(*models.MfaChallenge, erro // [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) // method. func (srv *Account) CreateMFAChallenge(Factor string)(*models.MfaChallenge, error) { - path := "/account/mfa/challenge" + path := "/account/mfa/challenges" params := map[string]interface{}{} params["factor"] = Factor headers := map[string]interface{}{ @@ -712,7 +712,7 @@ func (srv *Account) CreateMFAChallenge(Factor string)(*models.MfaChallenge, erro // // Deprecated: This API has been deprecated since 1.8.0. Please use `Account.updateMFAChallenge` instead. func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*models.Session, error) { - path := "/account/mfa/challenge" + path := "/account/mfa/challenges" params := map[string]interface{}{} params["challengeId"] = ChallengeId params["otp"] = Otp @@ -751,7 +751,7 @@ func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*models.S // [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) // method. func (srv *Account) UpdateMFAChallenge(ChallengeId string, Otp string)(*models.Session, error) { - path := "/account/mfa/challenge" + path := "/account/mfa/challenges" params := map[string]interface{}{} params["challengeId"] = ChallengeId params["otp"] = Otp diff --git a/avatars/avatars.go b/avatars/avatars.go index 822332ab..0492f3bb 100644 --- a/avatars/avatars.go +++ b/avatars/avatars.go @@ -574,3 +574,267 @@ func (srv *Avatars) GetQR(Text string, optionalSetters ...GetQROption)(*[]byte, return &parsed, nil } +type GetScreenshotOptions struct { + Headers interface{} + ViewportWidth int + ViewportHeight int + Scale float64 + Theme string + UserAgent string + Fullpage bool + Locale string + Timezone string + Latitude float64 + Longitude float64 + Accuracy float64 + Touch bool + Permissions []string + Sleep int + Width int + Height int + Quality int + Output string + enabledSetters map[string]bool +} +func (options GetScreenshotOptions) New() *GetScreenshotOptions { + options.enabledSetters = map[string]bool{ + "Headers": false, + "ViewportWidth": false, + "ViewportHeight": false, + "Scale": false, + "Theme": false, + "UserAgent": false, + "Fullpage": false, + "Locale": false, + "Timezone": false, + "Latitude": false, + "Longitude": false, + "Accuracy": false, + "Touch": false, + "Permissions": false, + "Sleep": false, + "Width": false, + "Height": false, + "Quality": false, + "Output": false, + } + return &options +} +type GetScreenshotOption func(*GetScreenshotOptions) +func (srv *Avatars) WithGetScreenshotHeaders(v interface{}) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Headers = v + o.enabledSetters["Headers"] = true + } +} +func (srv *Avatars) WithGetScreenshotViewportWidth(v int) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.ViewportWidth = v + o.enabledSetters["ViewportWidth"] = true + } +} +func (srv *Avatars) WithGetScreenshotViewportHeight(v int) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.ViewportHeight = v + o.enabledSetters["ViewportHeight"] = true + } +} +func (srv *Avatars) WithGetScreenshotScale(v float64) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Scale = v + o.enabledSetters["Scale"] = true + } +} +func (srv *Avatars) WithGetScreenshotTheme(v string) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Theme = v + o.enabledSetters["Theme"] = true + } +} +func (srv *Avatars) WithGetScreenshotUserAgent(v string) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.UserAgent = v + o.enabledSetters["UserAgent"] = true + } +} +func (srv *Avatars) WithGetScreenshotFullpage(v bool) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Fullpage = v + o.enabledSetters["Fullpage"] = true + } +} +func (srv *Avatars) WithGetScreenshotLocale(v string) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Locale = v + o.enabledSetters["Locale"] = true + } +} +func (srv *Avatars) WithGetScreenshotTimezone(v string) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Timezone = v + o.enabledSetters["Timezone"] = true + } +} +func (srv *Avatars) WithGetScreenshotLatitude(v float64) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Latitude = v + o.enabledSetters["Latitude"] = true + } +} +func (srv *Avatars) WithGetScreenshotLongitude(v float64) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Longitude = v + o.enabledSetters["Longitude"] = true + } +} +func (srv *Avatars) WithGetScreenshotAccuracy(v float64) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Accuracy = v + o.enabledSetters["Accuracy"] = true + } +} +func (srv *Avatars) WithGetScreenshotTouch(v bool) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Touch = v + o.enabledSetters["Touch"] = true + } +} +func (srv *Avatars) WithGetScreenshotPermissions(v []string) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *Avatars) WithGetScreenshotSleep(v int) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Sleep = v + o.enabledSetters["Sleep"] = true + } +} +func (srv *Avatars) WithGetScreenshotWidth(v int) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Width = v + o.enabledSetters["Width"] = true + } +} +func (srv *Avatars) WithGetScreenshotHeight(v int) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Height = v + o.enabledSetters["Height"] = true + } +} +func (srv *Avatars) WithGetScreenshotQuality(v int) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Quality = v + o.enabledSetters["Quality"] = true + } +} +func (srv *Avatars) WithGetScreenshotOutput(v string) GetScreenshotOption { + return func(o *GetScreenshotOptions) { + o.Output = v + o.enabledSetters["Output"] = true + } +} + +// GetScreenshot use this endpoint to capture a screenshot of any website URL. +// This endpoint uses a headless browser to render the webpage and capture it +// as an image. +// +// You can configure the browser viewport size, theme, user agent, +// geolocation, permissions, and more. Capture either just the viewport or the +// full page scroll. +// +// When width and height are specified, the image is resized accordingly. If +// both dimensions are 0, the API provides an image at original size. If +// dimensions are not specified, the default viewport size is 1280x720px. +func (srv *Avatars) GetScreenshot(Url string, optionalSetters ...GetScreenshotOption)(*[]byte, error) { + path := "/avatars/screenshots" + options := GetScreenshotOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["url"] = Url + if options.enabledSetters["Headers"] { + params["headers"] = options.Headers + } + if options.enabledSetters["ViewportWidth"] { + params["viewportWidth"] = options.ViewportWidth + } + if options.enabledSetters["ViewportHeight"] { + params["viewportHeight"] = options.ViewportHeight + } + if options.enabledSetters["Scale"] { + params["scale"] = options.Scale + } + if options.enabledSetters["Theme"] { + params["theme"] = options.Theme + } + if options.enabledSetters["UserAgent"] { + params["userAgent"] = options.UserAgent + } + if options.enabledSetters["Fullpage"] { + params["fullpage"] = options.Fullpage + } + if options.enabledSetters["Locale"] { + params["locale"] = options.Locale + } + if options.enabledSetters["Timezone"] { + params["timezone"] = options.Timezone + } + if options.enabledSetters["Latitude"] { + params["latitude"] = options.Latitude + } + if options.enabledSetters["Longitude"] { + params["longitude"] = options.Longitude + } + if options.enabledSetters["Accuracy"] { + params["accuracy"] = options.Accuracy + } + if options.enabledSetters["Touch"] { + params["touch"] = options.Touch + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["Sleep"] { + params["sleep"] = options.Sleep + } + if options.enabledSetters["Width"] { + params["width"] = options.Width + } + if options.enabledSetters["Height"] { + params["height"] = options.Height + } + if options.enabledSetters["Quality"] { + params["quality"] = options.Quality + } + if options.enabledSetters["Output"] { + params["output"] = options.Output + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed []byte + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed []byte + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/client/client.go b/client/client.go index 461707a5..691fb291 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.8.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.14.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.15.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v0.14.0", + "x-sdk-version": "v0.15.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { diff --git a/docs/examples/avatars/get-screenshot.md b/docs/examples/avatars/get-screenshot.md new file mode 100644 index 00000000..9191ad88 --- /dev/null +++ b/docs/examples/avatars/get-screenshot.md @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := avatars.New(client) + +response, error := service.GetScreenshot( + "https://example.com", + avatars.WithGetScreenshotHeaders(map[string]interface{}{ + "Authorization": "Bearer token123", + "X-Custom-Header": "value" + }), + avatars.WithGetScreenshotViewportWidth(1920), + avatars.WithGetScreenshotViewportHeight(1080), + avatars.WithGetScreenshotScale(2), + avatars.WithGetScreenshotTheme("dark"), + avatars.WithGetScreenshotUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15"), + avatars.WithGetScreenshotFullpage(true), + avatars.WithGetScreenshotLocale("en-US"), + avatars.WithGetScreenshotTimezone("America/New_York"), + avatars.WithGetScreenshotLatitude(37.7749), + avatars.WithGetScreenshotLongitude(-122.4194), + avatars.WithGetScreenshotAccuracy(100), + avatars.WithGetScreenshotTouch(true), + avatars.WithGetScreenshotPermissions(interface{}{"geolocation","notifications"}), + avatars.WithGetScreenshotSleep(3), + avatars.WithGetScreenshotWidth(800), + avatars.WithGetScreenshotHeight(600), + avatars.WithGetScreenshotQuality(85), + avatars.WithGetScreenshotOutput("jpeg"), +) diff --git a/docs/examples/functions/create-template-deployment.md b/docs/examples/functions/create-template-deployment.md index 14f694ba..df9591f4 100644 --- a/docs/examples/functions/create-template-deployment.md +++ b/docs/examples/functions/create-template-deployment.md @@ -19,6 +19,7 @@ response, error := service.CreateTemplateDeployment( "", "", "", - "", + "commit", + "", functions.WithCreateTemplateDeploymentActivate(false), ) diff --git a/docs/examples/sites/create-template-deployment.md b/docs/examples/sites/create-template-deployment.md index 483d3e79..85bf2a3c 100644 --- a/docs/examples/sites/create-template-deployment.md +++ b/docs/examples/sites/create-template-deployment.md @@ -19,6 +19,7 @@ response, error := service.CreateTemplateDeployment( "", "", "", - "", + "branch", + "", sites.WithCreateTemplateDeploymentActivate(false), ) diff --git a/docs/examples/storage/create-bucket.md b/docs/examples/storage/create-bucket.md index 64e3c401..7bec2acb 100644 --- a/docs/examples/storage/create-bucket.md +++ b/docs/examples/storage/create-bucket.md @@ -25,4 +25,5 @@ response, error := service.CreateBucket( storage.WithCreateBucketCompression("none"), storage.WithCreateBucketEncryption(false), storage.WithCreateBucketAntivirus(false), + storage.WithCreateBucketTransformations(false), ) diff --git a/docs/examples/storage/update-bucket.md b/docs/examples/storage/update-bucket.md index bb5f7aa7..7092c688 100644 --- a/docs/examples/storage/update-bucket.md +++ b/docs/examples/storage/update-bucket.md @@ -25,4 +25,5 @@ response, error := service.UpdateBucket( storage.WithUpdateBucketCompression("none"), storage.WithUpdateBucketEncryption(false), storage.WithUpdateBucketAntivirus(false), + storage.WithUpdateBucketTransformations(false), ) diff --git a/functions/functions.go b/functions/functions.go index cebe1ba7..9ba882b3 100644 --- a/functions/functions.go +++ b/functions/functions.go @@ -956,13 +956,13 @@ func (srv *Functions) WithCreateTemplateDeploymentActivate(v bool) CreateTemplat o.enabledSetters["Activate"] = true } } - + // CreateTemplateDeployment create a deployment based on a template. // // Use this endpoint with combination of // [listTemplates](https://appwrite.io/docs/products/functions/templates) to // find the template details. -func (srv *Functions) CreateTemplateDeployment(FunctionId string, Repository string, Owner string, RootDirectory string, Version string, optionalSetters ...CreateTemplateDeploymentOption)(*models.Deployment, error) { +func (srv *Functions) CreateTemplateDeployment(FunctionId string, Repository string, Owner string, RootDirectory string, Type string, Reference string, optionalSetters ...CreateTemplateDeploymentOption)(*models.Deployment, error) { r := strings.NewReplacer("{functionId}", FunctionId) path := r.Replace("/functions/{functionId}/deployments/template") options := CreateTemplateDeploymentOptions{}.New() @@ -974,7 +974,8 @@ func (srv *Functions) CreateTemplateDeployment(FunctionId string, Repository str params["repository"] = Repository params["owner"] = Owner params["rootDirectory"] = RootDirectory - params["version"] = Version + params["type"] = Type + params["reference"] = Reference if options.enabledSetters["Activate"] { params["activate"] = options.Activate } diff --git a/models/bucket.go b/models/bucket.go index ef7af0a3..b4f05240 100644 --- a/models/bucket.go +++ b/models/bucket.go @@ -35,6 +35,8 @@ type Bucket struct { Encryption bool `json:"encryption"` // Virus scanning is enabled. Antivirus bool `json:"antivirus"` + // Image transformations are enabled. + Transformations bool `json:"transformations"` // Used by Decode() method data []byte diff --git a/sites/sites.go b/sites/sites.go index 0956c113..cd1864e4 100644 --- a/sites/sites.go +++ b/sites/sites.go @@ -806,7 +806,7 @@ func (srv *Sites) WithCreateDeploymentOutputDirectory(v string) CreateDeployment // CreateDeployment create a new site code deployment. Use this endpoint to // upload a new version of your site code. To activate your newly uploaded -// code, you'll need to update the function's deployment to use your new +// code, you'll need to update the site's deployment to use your new // deployment ID. func (srv *Sites) CreateDeployment(SiteId string, Code file.InputFile, Activate bool, optionalSetters ...CreateDeploymentOption)(*models.Deployment, error) { r := strings.NewReplacer("{siteId}", SiteId) @@ -913,13 +913,13 @@ func (srv *Sites) WithCreateTemplateDeploymentActivate(v bool) CreateTemplateDep o.enabledSetters["Activate"] = true } } - + // CreateTemplateDeployment create a deployment based on a template. // // Use this endpoint with combination of // [listTemplates](https://appwrite.io/docs/products/sites/templates) to find // the template details. -func (srv *Sites) CreateTemplateDeployment(SiteId string, Repository string, Owner string, RootDirectory string, Version string, optionalSetters ...CreateTemplateDeploymentOption)(*models.Deployment, error) { +func (srv *Sites) CreateTemplateDeployment(SiteId string, Repository string, Owner string, RootDirectory string, Type string, Reference string, optionalSetters ...CreateTemplateDeploymentOption)(*models.Deployment, error) { r := strings.NewReplacer("{siteId}", SiteId) path := r.Replace("/sites/{siteId}/deployments/template") options := CreateTemplateDeploymentOptions{}.New() @@ -931,7 +931,8 @@ func (srv *Sites) CreateTemplateDeployment(SiteId string, Repository string, Own params["repository"] = Repository params["owner"] = Owner params["rootDirectory"] = RootDirectory - params["version"] = Version + params["type"] = Type + params["reference"] = Reference if options.enabledSetters["Activate"] { params["activate"] = options.Activate } diff --git a/storage/storage.go b/storage/storage.go index f9598bca..0a19a5ee 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -108,6 +108,7 @@ type CreateBucketOptions struct { Compression string Encryption bool Antivirus bool + Transformations bool enabledSetters map[string]bool } func (options CreateBucketOptions) New() *CreateBucketOptions { @@ -120,6 +121,7 @@ func (options CreateBucketOptions) New() *CreateBucketOptions { "Compression": false, "Encryption": false, "Antivirus": false, + "Transformations": false, } return &options } @@ -172,6 +174,12 @@ func (srv *Storage) WithCreateBucketAntivirus(v bool) CreateBucketOption { o.enabledSetters["Antivirus"] = true } } +func (srv *Storage) WithCreateBucketTransformations(v bool) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.Transformations = v + o.enabledSetters["Transformations"] = true + } +} // CreateBucket create a new storage bucket. func (srv *Storage) CreateBucket(BucketId string, Name string, optionalSetters ...CreateBucketOption)(*models.Bucket, error) { @@ -207,6 +215,9 @@ func (srv *Storage) CreateBucket(BucketId string, Name string, optionalSetters . if options.enabledSetters["Antivirus"] { params["antivirus"] = options.Antivirus } + if options.enabledSetters["Transformations"] { + params["transformations"] = options.Transformations + } headers := map[string]interface{}{ "content-type": "application/json", } @@ -279,6 +290,7 @@ type UpdateBucketOptions struct { Compression string Encryption bool Antivirus bool + Transformations bool enabledSetters map[string]bool } func (options UpdateBucketOptions) New() *UpdateBucketOptions { @@ -291,6 +303,7 @@ func (options UpdateBucketOptions) New() *UpdateBucketOptions { "Compression": false, "Encryption": false, "Antivirus": false, + "Transformations": false, } return &options } @@ -343,6 +356,12 @@ func (srv *Storage) WithUpdateBucketAntivirus(v bool) UpdateBucketOption { o.enabledSetters["Antivirus"] = true } } +func (srv *Storage) WithUpdateBucketTransformations(v bool) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.Transformations = v + o.enabledSetters["Transformations"] = true + } +} // UpdateBucket update a storage bucket by its unique ID. func (srv *Storage) UpdateBucket(BucketId string, Name string, optionalSetters ...UpdateBucketOption)(*models.Bucket, error) { @@ -379,6 +398,9 @@ func (srv *Storage) UpdateBucket(BucketId string, Name string, optionalSetters . if options.enabledSetters["Antivirus"] { params["antivirus"] = options.Antivirus } + if options.enabledSetters["Transformations"] { + params["transformations"] = options.Transformations + } headers := map[string]interface{}{ "content-type": "application/json", }