Skip to content

Commit 520016c

Browse files
committed
Move to released uploadcare-go v2
1 parent 974264c commit 520016c

13 files changed

Lines changed: 78 additions & 140 deletions

File tree

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/spf13/cobra v1.10.2
99
github.com/spf13/pflag v1.0.10
1010
github.com/spf13/viper v1.21.0
11-
github.com/uploadcare/uploadcare-go/v2 v2.0.0-20260409071548-d58ba67da138
11+
github.com/uploadcare/uploadcare-go/v2 v2.0.0
1212
go.yaml.in/yaml/v3 v3.0.4
1313
)
1414

@@ -29,5 +29,3 @@ require (
2929
golang.org/x/sys v0.42.0 // indirect
3030
golang.org/x/text v0.28.0 // indirect
3131
)
32-
33-
replace github.com/uploadcare/uploadcare-go/v2 => github.com/uploadcare/uploadcare-go/v2 v2.0.0-20260409071548-d58ba67da138

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
5353
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
5454
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
5555
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
56-
github.com/uploadcare/uploadcare-go/v2 v2.0.0-20260409071548-d58ba67da138 h1:Aoe226G5RvIEdIZkk1LbdIPZ09X62gDTq6bh4/zlSog=
57-
github.com/uploadcare/uploadcare-go/v2 v2.0.0-20260409071548-d58ba67da138/go.mod h1:nVtcYFEeUnxMjXbEsXzDefko4MdJpXjzBGRJtxwoCjU=
56+
github.com/uploadcare/uploadcare-go/v2 v2.0.0 h1:tZc3OjMcZyhuKEWnb2OV4IaZaWTnu96JJqo32n9on88=
57+
github.com/uploadcare/uploadcare-go/v2 v2.0.0/go.mod h1:nVtcYFEeUnxMjXbEsXzDefko4MdJpXjzBGRJtxwoCjU=
5858
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
5959
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
6060
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

internal/client/addon.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ func NewAddonService(publicKey, secretKey string, httpClient *http.Client, verbo
2222
PublicKey: publicKey,
2323
SecretKey: secretKey,
2424
}
25-
conf := &ucare.Config{
26-
APIVersion: ucare.APIv07,
27-
SignBasedAuthentication: true,
28-
HTTPClient: httpClient,
29-
UserAgent: UserAgent,
25+
conf, err := ucare.NewConfig(creds,
26+
ucare.WithSignBasedAuthentication(),
27+
ucare.WithHTTPClient(httpClient),
28+
ucare.WithUserAgent(UserAgent),
29+
)
30+
if err != nil {
31+
return nil, err
3032
}
3133
client, err := ucare.NewClient(creds, conf)
3234
if err != nil {
@@ -51,7 +53,7 @@ func (s *addonService) Execute(ctx context.Context, addonName, fileUUID string,
5153
}
5254

5355
s.verbose.Infof("executing addon %s on file %s", addonName, fileUUID)
54-
result, err := s.sdk.Execute(ctx, addonName, execParams)
56+
result, err := s.sdk.Execute(ctx, addon.Name(addonName), execParams)
5557
if err != nil {
5658
return nil, err
5759
}
@@ -62,7 +64,7 @@ func (s *addonService) Execute(ctx context.Context, addonName, fileUUID string,
6264
}
6365

6466
func (s *addonService) Status(ctx context.Context, addonName, requestID string) (*service.AddonStatus, error) {
65-
result, err := s.sdk.Status(ctx, addonName, requestID)
67+
result, err := s.sdk.Status(ctx, addon.Name(addonName), requestID)
6668
if err != nil {
6769
return nil, err
6870
}

internal/client/convert.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ func NewConvertService(publicKey, secretKey string, httpClient *http.Client, ver
2323
PublicKey: publicKey,
2424
SecretKey: secretKey,
2525
}
26-
conf := &ucare.Config{
27-
APIVersion: ucare.APIv07,
28-
SignBasedAuthentication: true,
29-
HTTPClient: httpClient,
30-
UserAgent: UserAgent,
26+
conf, err := ucare.NewConfig(creds,
27+
ucare.WithSignBasedAuthentication(),
28+
ucare.WithHTTPClient(httpClient),
29+
ucare.WithUserAgent(UserAgent),
30+
)
31+
if err != nil {
32+
return nil, err
3133
}
3234
client, err := ucare.NewClient(creds, conf)
3335
if err != nil {
@@ -50,7 +52,7 @@ func (s *convertService) Document(ctx context.Context, params service.DocConvert
5052
sdkParams.ToStore = ucare.String(conversion.ToStoreTrue)
5153
}
5254
if params.SaveInGroup {
53-
sdkParams.SaveInGroup = ucare.String("true")
55+
sdkParams.SaveInGroup = "1"
5456
}
5557

5658
result, err := s.sdk.Document(ctx, sdkParams)

internal/client/file.go

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8-
"strings"
98
"time"
109

1110
"github.com/uploadcare/uploadcare-cli/internal/output"
@@ -18,7 +17,6 @@ import (
1817
type fileService struct {
1918
sdkFileSvc file.Service
2019
sdkUploadSvc upload.Service
21-
cdnBase string
2220
verbose *output.VerboseLogger
2321
}
2422

@@ -30,12 +28,14 @@ func NewFileService(publicKey, secretKey, cdnBase string, httpClient *http.Clien
3028
PublicKey: publicKey,
3129
SecretKey: secretKey,
3230
}
33-
conf := &ucare.Config{
34-
APIVersion: ucare.APIv07,
35-
SignBasedAuthentication: true,
36-
CDNBase: cdnBase,
37-
HTTPClient: httpClient,
38-
UserAgent: UserAgent,
31+
conf, err := ucare.NewConfig(creds,
32+
ucare.WithSignBasedAuthentication(),
33+
ucare.WithCDNBase(cdnBase),
34+
ucare.WithHTTPClient(httpClient),
35+
ucare.WithUserAgent(UserAgent),
36+
)
37+
if err != nil {
38+
return nil, err
3939
}
4040
client, err := ucare.NewClient(creds, conf)
4141
if err != nil {
@@ -44,21 +44,10 @@ func NewFileService(publicKey, secretKey, cdnBase string, httpClient *http.Clien
4444
return &fileService{
4545
sdkFileSvc: file.NewService(client),
4646
sdkUploadSvc: upload.NewService(client),
47-
cdnBase: cdnBase,
4847
verbose: verbose,
4948
}, nil
5049
}
5150

52-
// setCDNURL overwrites OriginalFileURL with a URL built from the configured
53-
// CDN base and the file's UUID. This makes --cdn-base and per-project CDN
54-
// domains actually take effect, since the API always returns the legacy
55-
// ucarecdn.com URL regardless of project settings.
56-
func (s *fileService) setCDNURL(f *service.File) {
57-
if s.cdnBase != "" && f.OriginalFileURL != "" {
58-
f.OriginalFileURL = strings.TrimRight(s.cdnBase, "/") + "/" + f.UUID + "/"
59-
}
60-
}
61-
6251
func (s *fileService) Info(ctx context.Context, uuid string, includeAppData bool) (*service.File, error) {
6352
var params *file.InfoParams
6453
if includeAppData {
@@ -69,9 +58,7 @@ func (s *fileService) Info(ctx context.Context, uuid string, includeAppData bool
6958
if err != nil {
7059
return nil, err
7160
}
72-
f := mapFileInfo(info)
73-
s.setCDNURL(f)
74-
return f, nil
61+
return mapFileInfo(info), nil
7562
}
7663

7764
func mapFileInfo(info file.Info) *service.File {
@@ -145,9 +132,7 @@ func (s *fileService) List(ctx context.Context, opts service.FileListOptions) (*
145132
if err != nil {
146133
return nil, err
147134
}
148-
f := mapFileInfo(*info)
149-
s.setCDNURL(f)
150-
files = append(files, *f)
135+
files = append(files, *mapFileInfo(*info))
151136
}
152137

153138
return &service.FileListResult{
@@ -171,9 +156,7 @@ func (s *fileService) Iterate(ctx context.Context, opts service.FileListOptions,
171156
if err != nil {
172157
return err
173158
}
174-
f := mapFileInfo(*info)
175-
s.setCDNURL(f)
176-
if err := fn(*f); err != nil {
159+
if err := fn(*mapFileInfo(*info)); err != nil {
177160
return err
178161
}
179162
}
@@ -304,36 +287,25 @@ func (s *fileService) enrichUploadInfo(ctx context.Context, id string, fallback
304287
fileInfo, err := s.sdkFileSvc.Info(ctx, id, nil)
305288
if err != nil {
306289
s.verbose.Infof("file info fetch failed, using upload response: %v", err)
307-
s.setCDNURL(fallback)
308290
return fallback
309291
}
310-
f := mapFileInfo(fileInfo)
311-
s.setCDNURL(f)
312-
return f
292+
return mapFileInfo(fileInfo)
313293
}
314294

315295
func (s *fileService) Store(ctx context.Context, uuids []string) (*service.BatchResult, error) {
316296
batch, err := s.sdkFileSvc.BatchStore(ctx, uuids)
317297
if err != nil {
318298
return nil, err
319299
}
320-
result := mapBatchInfo(batch)
321-
for i := range result.Files {
322-
s.setCDNURL(&result.Files[i])
323-
}
324-
return result, nil
300+
return mapBatchInfo(batch), nil
325301
}
326302

327303
func (s *fileService) Delete(ctx context.Context, uuids []string) (*service.BatchResult, error) {
328304
batch, err := s.sdkFileSvc.BatchDelete(ctx, uuids)
329305
if err != nil {
330306
return nil, err
331307
}
332-
result := mapBatchInfo(batch)
333-
for i := range result.Files {
334-
s.setCDNURL(&result.Files[i])
335-
}
336-
return result, nil
308+
return mapBatchInfo(batch), nil
337309
}
338310

339311
func mapBatchInfo(batch file.BatchInfo) *service.BatchResult {
@@ -361,9 +333,7 @@ func (s *fileService) LocalCopy(ctx context.Context, params service.LocalCopyPar
361333
if err != nil {
362334
return nil, err
363335
}
364-
f := mapFileInfo(copyInfo.Result)
365-
s.setCDNURL(f)
366-
return f, nil
336+
return mapFileInfo(copyInfo.Result), nil
367337
}
368338

369339
func (s *fileService) RemoteCopy(ctx context.Context, params service.RemoteCopyParams) (*service.RemoteCopyResult, error) {

internal/client/file_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,6 @@ func TestNewFileService_WithCDNBase(t *testing.T) {
2525
}
2626
}
2727

28-
func TestSetCDNURL_RewritesOriginalFileURL(t *testing.T) {
29-
s := &fileService{cdnBase: "https://abc1234567.ucarecd.net"}
30-
f := &service.File{
31-
UUID: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
32-
OriginalFileURL: "https://ucarecdn.com/a1b2c3d4-e5f6-7890-abcd-ef1234567890/",
33-
}
34-
s.setCDNURL(f)
35-
want := "https://abc1234567.ucarecd.net/a1b2c3d4-e5f6-7890-abcd-ef1234567890/"
36-
if f.OriginalFileURL != want {
37-
t.Errorf("OriginalFileURL = %q, want %q", f.OriginalFileURL, want)
38-
}
39-
}
40-
41-
func TestSetCDNURL_NoOpWhenCDNBaseEmpty(t *testing.T) {
42-
s := &fileService{cdnBase: ""}
43-
f := &service.File{
44-
UUID: "a1b2c3d4",
45-
OriginalFileURL: "https://ucarecdn.com/a1b2c3d4/",
46-
}
47-
s.setCDNURL(f)
48-
if f.OriginalFileURL != "https://ucarecdn.com/a1b2c3d4/" {
49-
t.Errorf("OriginalFileURL should be unchanged, got %q", f.OriginalFileURL)
50-
}
51-
}
52-
53-
func TestSetCDNURL_NoOpWhenDeletedFile(t *testing.T) {
54-
s := &fileService{cdnBase: "https://abc1234567.ucarecd.net"}
55-
f := &service.File{
56-
UUID: "a1b2c3d4",
57-
OriginalFileURL: "", // API returns null for deleted files
58-
}
59-
s.setCDNURL(f)
60-
if f.OriginalFileURL != "" {
61-
t.Errorf("OriginalFileURL should remain empty for deleted file, got %q", f.OriginalFileURL)
62-
}
63-
}
64-
65-
func TestSetCDNURL_TrailingSlashNormalized(t *testing.T) {
66-
s := &fileService{cdnBase: "https://custom.example.com/"}
67-
f := &service.File{UUID: "abc123", OriginalFileURL: "https://ucarecdn.com/abc123/"}
68-
s.setCDNURL(f)
69-
if f.OriginalFileURL != "https://custom.example.com/abc123/" {
70-
t.Errorf("OriginalFileURL = %q, want no double slash", f.OriginalFileURL)
71-
}
72-
}
73-
7428
func TestNewFileService_EmptyKeys(t *testing.T) {
7529
// SDK validates credentials at client creation time.
7630
_, err := NewFileService("", "", "", nil, nil)

internal/client/group.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ type groupService struct {
1919
}
2020

2121
// NewGroupService creates a service.GroupService backed by the Uploadcare SDK.
22-
func NewGroupService(publicKey, secretKey string, httpClient *http.Client, verbose *output.VerboseLogger) (service.GroupService, error) {
22+
func NewGroupService(publicKey, secretKey, cdnBase string, httpClient *http.Client, verbose *output.VerboseLogger) (service.GroupService, error) {
2323
creds := ucare.APICreds{
2424
PublicKey: publicKey,
2525
SecretKey: secretKey,
2626
}
27-
conf := &ucare.Config{
28-
APIVersion: ucare.APIv07,
29-
SignBasedAuthentication: true,
30-
HTTPClient: httpClient,
31-
UserAgent: UserAgent,
27+
conf, err := ucare.NewConfig(creds,
28+
ucare.WithSignBasedAuthentication(),
29+
ucare.WithCDNBase(cdnBase),
30+
ucare.WithHTTPClient(httpClient),
31+
ucare.WithUserAgent(UserAgent),
32+
)
33+
if err != nil {
34+
return nil, err
3235
}
3336
client, err := ucare.NewClient(creds, conf)
3437
if err != nil {

internal/client/metadata.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ func NewMetadataService(publicKey, secretKey string, httpClient *http.Client, ve
2121
PublicKey: publicKey,
2222
SecretKey: secretKey,
2323
}
24-
conf := &ucare.Config{
25-
APIVersion: ucare.APIv07,
26-
SignBasedAuthentication: true,
27-
HTTPClient: httpClient,
28-
UserAgent: UserAgent,
24+
conf, err := ucare.NewConfig(creds,
25+
ucare.WithSignBasedAuthentication(),
26+
ucare.WithHTTPClient(httpClient),
27+
ucare.WithUserAgent(UserAgent),
28+
)
29+
if err != nil {
30+
return nil, err
2931
}
3032
client, err := ucare.NewClient(creds, conf)
3133
if err != nil {

internal/client/project.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ func NewProjectService(publicKey, secretKey string, httpClient *http.Client, ver
2121
PublicKey: publicKey,
2222
SecretKey: secretKey,
2323
}
24-
conf := &ucare.Config{
25-
APIVersion: ucare.APIv07,
26-
SignBasedAuthentication: true,
27-
HTTPClient: httpClient,
28-
UserAgent: UserAgent,
24+
conf, err := ucare.NewConfig(creds,
25+
ucare.WithSignBasedAuthentication(),
26+
ucare.WithHTTPClient(httpClient),
27+
ucare.WithUserAgent(UserAgent),
28+
)
29+
if err != nil {
30+
return nil, err
2931
}
3032
client, err := ucare.NewClient(creds, conf)
3133
if err != nil {

internal/client/usage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s *usageService) Combined(ctx context.Context, pubKey string, from, to str
5858
}
5959

6060
func (s *usageService) Metric(ctx context.Context, pubKey, metric string, from, to string) (*service.MetricResult, error) {
61-
m, err := s.sdk.GetUsageMetric(ctx, pubKey, metric, projectapi.UsageDateRange{
61+
m, err := s.sdk.GetUsageMetric(ctx, pubKey, projectapi.UsageMetricName(metric), projectapi.UsageDateRange{
6262
From: from,
6363
To: to,
6464
})
@@ -67,7 +67,7 @@ func (s *usageService) Metric(ctx context.Context, pubKey, metric string, from,
6767
}
6868

6969
result := &service.MetricResult{
70-
Metric: m.Metric,
70+
Metric: string(m.Metric),
7171
Unit: m.Unit,
7272
Data: make([]service.MetricDayData, len(m.Data)),
7373
}

0 commit comments

Comments
 (0)