crowdin / crowdin-api-client-go

Go client library for Crowdin API
MIT License
5 stars 2 forks source link

report add storage method bug #52

Closed vino-hank closed 1 month ago

vino-hank commented 1 month ago

Behavior

upload file by add storage method would earse exited file content(exited file content was removed).

Replay

Env:

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/crowdin/crowdin-api-client-go/crowdin"
    "github.com/crowdin/crowdin-api-client-go/crowdin/model"
    "github.com/pkg/errors"
)

func main(){
    client, err := crowdin.NewClient(
        os.Getenv("CROWDIN_ACCESS_TOKEN"),
    )
    if err != nil {
        log.Fatal("NewClientErr: ", err)
    }

      // add storage for update file.
    filePath := "./test.json"
    file, err := os.Open(filePath)
    if err != nil {
        log.Fatal("Open file err: ", err)
    }
    addStorage, resp, err := client.Storages.Add(context.Background(), file)
    fmt.Println("AddStorages: ", res.Status)
    if err != nil {
        log.Fatal("NewClientErr: ", err)
    }
    // Output:
    // AddStorages:  201 Created
    // {
    //    "id": 21***837,
    //    "fileName": "test.json"
    // }

    // update file content, I confirm there are some entry from test.json file  before update by browser dashboard. and file was empty after execute below update method.
    projectID := 4****3
    updateFile, resp, err := client.SourceFiles.UpdateOrRestoreFile(context.Background(), projectID, 24384, &model.FileUpdateRestoreRequest{
        StorageID:    addStorage.ID,
        UpdateOption: "clear_translations_and_approvals",
    })
}

bug trace:

image image image

vorobeyme commented 1 month ago

Hi @vino-hank,

Thank you for reporting this issue.

The problem is that if body is an os.File, it can't be encoded into JSON directly.

I've submitted a pull request with this fix, and you can review the changes in PR #54