Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.20.9
github.com/0chain/gosdk v1.20.10-0.20251207130329-236a4b0fb2f3
github.com/go-resty/resty/v2 v2.7.0
github.com/herumi/bls-go-binary v1.31.0
github.com/shopspring/decimal v1.3.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.20.9 h1:pt4dhlu605qjVQ5PvKcPfKgHjMCNdqnPYb4HOpCwnfg=
github.com/0chain/gosdk v1.20.9/go.mod h1:dwDhPmkbmcTqbOcTpFZqcuKPZBa7Eq79vz5bNLRtxxo=
github.com/0chain/gosdk v1.20.10-0.20251121073326-a9a97301edc9 h1:+ueIV8IUPDOmvSPz4lhEb+Ms3JGjgH+HBWgUTa8uR6g=
github.com/0chain/gosdk v1.20.10-0.20251121073326-a9a97301edc9/go.mod h1:dwDhPmkbmcTqbOcTpFZqcuKPZBa7Eq79vz5bNLRtxxo=
github.com/0chain/gosdk v1.20.10-0.20251207130329-236a4b0fb2f3 h1:f02irbxFclAzukSm3ozq8cKhjEYxRj6C8eZD+PkfHCY=
github.com/0chain/gosdk v1.20.10-0.20251207130329-236a4b0fb2f3/go.mod h1:dwDhPmkbmcTqbOcTpFZqcuKPZBa7Eq79vz5bNLRtxxo=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
Expand Down
25 changes: 25 additions & 0 deletions internal/api/model/zbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,31 @@ type ZboxJwtToken struct {
JwtToken string `json:"jwt_token"`
}

// TranscodingEntity represents the transcoding entity metadata
type TranscodingEntity struct {
ID int64 `json:"ID"`
UserID string `json:"UserID"`
ClientID string `json:"ClientID"`
Remotepath string `json:"Remotepath"`
FilePath string `json:"FilePath"`
AllocationID string `json:"AllocationID"`
FileName string `json:"FileName"`
Mode string `json:"Mode"`
FileSize int64 `json:"FileSize"`
DoThumbnail bool `json:"DoThumbnail"`
Status int `json:"Status"`
AppType int `json:"AppType"`
CreatedAt string `json:"CreatedAt"`
UpdatedAt string `json:"UpdatedAt"`
Deleted *string `json:"Deleted"`
}

// GetTranscodingEntityResponse wraps API responses for GET metadata endpoint
type GetTranscodingEntityResponse struct {
Message string `json:"message"`
Data TranscodingEntity `json:"data"`
}

type ReferralCodeOfUser struct {
ReferrerCode string `json:"referral_code"`
ReferrerLink string `json:"referral_link"`
Expand Down
138 changes: 138 additions & 0 deletions internal/api/util/client/zbox_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"encoding/json"
"fmt"
"strconv"

Expand Down Expand Up @@ -283,6 +284,11 @@
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/v2/wallet")

// t.Logf("wallet input: %v", wallet)

Check failure on line 287 in internal/api/util/client/zbox_client.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
// t.Logf("CreateWallet URL: %v", urlBuilder.String())
// t.Logf("CreateWallet Headers: %v", headers)
// t.Logf("CreateWallet Wallet: %v", wallet)

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &zboxWallet,
FormData: wallet,
Expand Down Expand Up @@ -1470,3 +1476,135 @@

return csrfToken, resp, err
}

// CreateMetadata posts transcoding metadata to the server and returns parsed response.
func (c *ZboxClient) CreateMetadata(t *test.SystemTest, headers map[string]string, body map[string]interface{}) (*model.TranscodingEntity, *resty.Response, error) {
t.Logf("creating transcoding metadata for user [%v] using 0box...", headers["X-App-User-ID"])

// Log request body
bodyJSON, err := json.Marshal(body)
if err == nil {
t.Logf("CreateMetadata request body: %s", string(bodyJSON))
} else {
t.Logf("CreateMetadata request body (marshal error): %v", body)
}

var res *model.GetTranscodingEntityResponse

urlBuilder := NewURLBuilder()
err = urlBuilder.MustShiftParse(c.zboxEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/v2/metadata")

// Ensure Content-Type is set to JSON
jsonHeaders := make(map[string]string)
for k, v := range headers {
jsonHeaders[k] = v
}
jsonHeaders["Content-Type"] = "application/json"

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &res,
Headers: jsonHeaders,
Body: body,
RequiredStatusCode: 201,
}, HttpPOSTMethod)

if err != nil {
t.Errorf("CreateMetadata response error: %v, response body: %s", err, string(resp.Body()))
return nil, resp, err
}

// Log response body
t.Logf("CreateMetadata response status: %d, response body: %s", resp.StatusCode(), string(resp.Body()))

if res != nil && res.Data.ID != 0 {
return &res.Data, resp, nil
}

return nil, resp, fmt.Errorf("transcoding entity not found in response")
}

// UpdateUploadStatus updates status for an uploaded file and returns parsed response.
func (c *ZboxClient) UpdateUploadStatus(t *test.SystemTest, headers map[string]string, body map[string]interface{}) (*model.TranscodingEntity, *resty.Response, error) {
t.Logf("updating upload status for user [%v] using 0box...", headers["X-App-User-ID"])

// Log request body
bodyJSON, err := json.Marshal(body)
if err == nil {
t.Logf("UpdateUploadStatus request body: %s", string(bodyJSON))
} else {
t.Logf("UpdateUploadStatus request body (marshal error): %v", body)
}

var res *model.GetTranscodingEntityResponse

urlBuilder := NewURLBuilder()
err = urlBuilder.MustShiftParse(c.zboxEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/v2/updateUploadStatus")

// Ensure Content-Type is set to JSON
jsonHeaders := make(map[string]string)
for k, v := range headers {
jsonHeaders[k] = v
}
jsonHeaders["Content-Type"] = "application/json"

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &res,
Headers: jsonHeaders,
Body: body,
RequiredStatusCode: 201,
}, HttpPUTMethod)

if err != nil {
t.Errorf("UpdateUploadStatus response error: %v, response body: %s", err, string(resp.Body()))
return nil, resp, err
}

// Log response body
t.Logf("UpdateUploadStatus response status: %d, response body: %s", resp.StatusCode(), string(resp.Body()))

if res != nil && res.Data.ID != 0 {
return &res.Data, resp, nil
}

return nil, resp, fmt.Errorf("transcoding entity not found in response")
}

// GetMetadata gets transcoding entity metadata and returns parsed response.
func (c *ZboxClient) GetMetadata(t *test.SystemTest, headers map[string]string, queryParams map[string]string) (*model.TranscodingEntity, *resty.Response, error) {

Check failure on line 1577 in internal/api/util/client/zbox_client.go

View workflow job for this annotation

GitHub Actions / lint

paramTypeCombine: func(t *test.SystemTest, headers map[string]string, queryParams map[string]string) (*model.TranscodingEntity, *resty.Response, error) could be replaced with func(t *test.SystemTest, headers, queryParams map[string]string) (*model.TranscodingEntity, *resty.Response, error) (gocritic)
t.Logf("getting transcoding metadata for user [%v] using 0box...", headers["X-App-User-ID"])

// Log query parameters
t.Logf("GetMetadata query params: %v", queryParams)

var res *model.GetTranscodingEntityResponse

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zboxEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/v2/metadata")

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &res,
Headers: headers,
QueryParams: queryParams,
RequiredStatusCode: 200,
}, HttpGETMethod)

if err != nil {
t.Errorf("GetMetadata response error: %v, response body: %s", err, string(resp.Body()))
return nil, resp, err
}

// Log response body
t.Logf("GetMetadata response status: %d, response body: %s", resp.StatusCode(), string(resp.Body()))

if res != nil && res.Data.ID != 0 {
return &res.Data, resp, nil
}

return nil, resp, fmt.Errorf("transcoding entity not found in response")
}
Loading
Loading