Skip to content

Commit

Permalink
Merge pull request #28 from appwrite/dev
Browse files Browse the repository at this point in the history
fix: pong response & chunked upload
  • Loading branch information
abnegate authored Jan 29, 2025
2 parents 029ca91 + 41d4ba5 commit 47bd930
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
# # Change Log

## 0.3.0

# # Change Log
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
13 changes: 7 additions & 6 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (srv *Account) CreateMfaChallenge(Factor string)(*models.MfaChallenge, erro
// password. To begin the flow, use
// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
// method.
func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*interface{}, error) {
func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*models.Session, error) {
path := "/account/mfa/challenge"
params := map[string]interface{}{}
params["challengeId"] = ChallengeId
Expand All @@ -550,16 +550,17 @@ func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*interfac
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

var parsed interface{}
parsed := models.Session{}.New(bytes)

err = json.Unmarshal(bytes, &parsed)
err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}
return &parsed, nil

return parsed, nil
}
var parsed interface{}
parsed, ok := resp.Result.(interface{})
var parsed models.Session
parsed, ok := resp.Result.(models.Session)
if !ok {
return nil, errors.New("unexpected response type")
}
Expand Down
10 changes: 5 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ type Client struct {
func New(optionalSetters ...ClientOption) Client {
headers := map[string]string{
"X-Appwrite-Response-Format" : "1.6.0",
"user-agent" : fmt.Sprintf("AppwriteGoSDK/0.3.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"user-agent" : fmt.Sprintf("AppwriteGoSDK/0.4.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"x-sdk-name": "Go",
"x-sdk-platform": "server",
"x-sdk-language": "go",
"x-sdk-version": "0.3.0",
"x-sdk-version": "0.4.0",=
}
httpClient, err := GetDefaultClient(defaultTimeout)
if err != nil {
Expand Down Expand Up @@ -155,15 +155,15 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par
numChunks++
}
var currentChunk int64 = 0
if uploadId != "" && uploadId != "unique()" {
if uploadId != "" {
resp, err := client.Call("GET", url+"/"+uploadId, nil, nil)
if err == nil {
currentChunk = int64(resp.Result.(map[string]interface{})["chunksUploaded"].(float64))
}
}

if fileInfo.Size() <= client.ChunkSize {
if uploadId != "" && uploadId != "unique()" {
if uploadId != "" {
headers["x-appwrite-id"] = uploadId
}
inputFile.Data = make([]byte, fileInfo.Size())
Expand Down Expand Up @@ -201,7 +201,7 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par
return nil, err
}
params[paramName] = inputFile
if uploadId != "" && uploadId != "unique()" {
if uploadId != "" {
headers["x-appwrite-id"] = uploadId
}
totalSize := fileInfo.Size()
Expand Down
14 changes: 12 additions & 2 deletions functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,12 @@ func (srv *Functions) WithCreateBuildBuildId(v string) CreateBuildOption {
}
}

// CreateBuild
// CreateBuild create a new build for an existing function deployment. This
// endpoint allows you to rebuild a deployment with the updated function
// configuration, including its entrypoint and build commands if they have
// been modified The build process will be queued and executed asynchronously.
// The original deployment's code will be preserved and used for the new
// build.
func (srv *Functions) CreateBuild(FunctionId string, DeploymentId string, optionalSetters ...CreateBuildOption)(*interface{}, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId)
path := r.Replace("/functions/{functionId}/deployments/{deploymentId}/build")
Expand Down Expand Up @@ -1032,7 +1037,12 @@ func (srv *Functions) CreateBuild(FunctionId string, DeploymentId string, option

}

// UpdateDeploymentBuild
// UpdateDeploymentBuild cancel an ongoing function deployment build. If the
// build is already in progress, it will be stopped and marked as canceled. If
// the build hasn't started yet, it will be marked as canceled without
// executing. You cannot cancel builds that have already completed (status
// 'ready') or failed. The response includes the final build status and
// details.
func (srv *Functions) UpdateDeploymentBuild(FunctionId string, DeploymentId string)(*models.Build, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId)
path := r.Replace("/functions/{functionId}/deployments/{deploymentId}/build")
Expand Down
2 changes: 1 addition & 1 deletion messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ func (srv *Messaging) WithUpdateSmsScheduledAt(v string) UpdateSmsOption {
}
}

// UpdateSms update an email message by its unique ID.
// UpdateSms update an SMS message by its unique ID.
func (srv *Messaging) UpdateSms(MessageId string, optionalSetters ...UpdateSmsOption)(*models.Message, error) {
r := strings.NewReplacer("{messageId}", MessageId)
path := r.Replace("/messaging/messages/sms/{messageId}")
Expand Down
13 changes: 6 additions & 7 deletions users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ func (srv *Users) UpdateMfa(UserId string, Mfa bool)(*models.User, error) {
}

// DeleteMfaAuthenticator delete an authenticator app.
func (srv *Users) DeleteMfaAuthenticator(UserId string, Type string)(*models.User, error) {
func (srv *Users) DeleteMfaAuthenticator(UserId string, Type string)(*interface{}, error) {
r := strings.NewReplacer("{userId}", UserId, "{type}", Type)
path := r.Replace("/users/{userId}/mfa/authenticators/{type}")
params := map[string]interface{}{}
Expand All @@ -1116,17 +1116,16 @@ func (srv *Users) DeleteMfaAuthenticator(UserId string, Type string)(*models.Use
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

parsed := models.User{}.New(bytes)
var parsed interface{}

err = json.Unmarshal(bytes, parsed)
err = json.Unmarshal(bytes, &parsed)
if err != nil {
return nil, err
}

return parsed, nil
return &parsed, nil
}
var parsed models.User
parsed, ok := resp.Result.(models.User)
var parsed interface{}
parsed, ok := resp.Result.(interface{})
if !ok {
return nil, errors.New("unexpected response type")
}
Expand Down

0 comments on commit 47bd930

Please sign in to comment.