Skip to content

Commit

Permalink
create asset with area id
Browse files Browse the repository at this point in the history
  • Loading branch information
zscboy authored and TitanNet committed Aug 2, 2024
1 parent 5db6ae6 commit c7ac049
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func getTitanURLAndAPIKeyFromEnv() (string, string, error) {
return titanURL, apiKey, nil
}

func getAreaIDFromEnv() string {
return os.Getenv("AREA_ID")
}

var rootCmd = &cobra.Command{}
var currentWorkingGroup = 0

Expand Down Expand Up @@ -56,7 +60,7 @@ var uploadCmd = &cobra.Command{
log.Fatal(err)
}

s, err := storage.NewStorage(&storage.Config{TitanURL: titanURL, APIKey: apiKey})
s, err := storage.NewStorage(&storage.Config{TitanURL: titanURL, APIKey: apiKey, AreaID: getAreaIDFromEnv()})
if err != nil {
log.Fatal("NewStorage error ", err)
}
Expand Down
10 changes: 6 additions & 4 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type storage struct {
// Setting the directory for file uploads
// default is 0, 0 is root directory
groupID int
areaID string
}

type Config struct {
Expand All @@ -95,6 +96,7 @@ type Config struct {
// default is 0, 0 is root directory
GroupID int
UseFastNode bool
AreaID string
}

// NewStorage creates a new Storage instance
Expand Down Expand Up @@ -142,7 +144,7 @@ func NewStorage(cfg *Config) (Storage, error) {
}

}
return &storage{webAPI: webAPI, candidateID: fastNodeID, userID: vipInfo.UserID, groupID: 0}, nil
return &storage{webAPI: webAPI, candidateID: fastNodeID, userID: vipInfo.UserID, groupID: 0, areaID: cfg.AreaID}, nil
}

// UploadFilesWithPath uploads files from the specified path
Expand Down Expand Up @@ -197,7 +199,7 @@ func (s *storage) UploadFilesWithPath(ctx context.Context, filePath string, prog
GroupID: s.groupID,
}

req := client.CreateAssetReq{AssetProperty: assetProperty}
req := client.CreateAssetReq{AssetProperty: assetProperty, AreaID: s.areaID}
_, err = s.webAPI.CreateAsset(context.Background(), &req)
if err != nil {
return cid.Cid{}, fmt.Errorf("CreateAsset error %w", err)
Expand Down Expand Up @@ -254,7 +256,7 @@ func (s *storage) uploadFilesWithPathAndMakeCar(ctx context.Context, filePath st
GroupID: s.groupID,
}

req := client.CreateAssetReq{AssetProperty: assetProperty}
req := client.CreateAssetReq{AssetProperty: assetProperty, AreaID: s.areaID}
rsp, err := s.webAPI.CreateAsset(ctx, &req)
if err != nil {
return cid.Cid{}, fmt.Errorf("CreateAsset error %w", err)
Expand Down Expand Up @@ -397,7 +399,7 @@ func (s *storage) UploadStream(ctx context.Context, r io.Reader, name string, pr
GroupID: s.groupID,
}

req := client.CreateAssetReq{AssetProperty: assetProperty}
req := client.CreateAssetReq{AssetProperty: assetProperty, AreaID: s.areaID}
rsp, err := s.webAPI.CreateAsset(ctx, &req)
if err != nil {
return cid.Cid{}, fmt.Errorf("CreateAsset error %w", err)
Expand Down

0 comments on commit c7ac049

Please sign in to comment.