Repository navigation
Expand file tree
/
Copy pathfileversion.go
More file actions
112 lines (100 loc) · 3.88 KB
/
Copy pathfileversion.go
File metadata and controls
112 lines (100 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package imagekit
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"github.com/imagekit-developer/imagekit-go/v2/internal/requestconfig"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
// FileVersionService contains methods and other services that help with
// interacting with the ImageKit API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewFileVersionService] method instead.
type FileVersionService struct {
Options []option.RequestOption
}
// NewFileVersionService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewFileVersionService(opts ...option.RequestOption) (r FileVersionService) {
r = FileVersionService{}
r.Options = opts
return
}
// This API returns details of all versions of a file.
func (r *FileVersionService) List(ctx context.Context, fileID string, opts ...option.RequestOption) (res *[]File, err error) {
opts = slices.Concat(r.Options, opts)
if fileID == "" {
err = errors.New("missing required fileId parameter")
return nil, err
}
path := fmt.Sprintf("v1/files/%s/versions", fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// This API deletes a non-current file version permanently. The API returns an
// empty response.
//
// Note: If you want to delete all versions of a file, use the delete file API.
func (r *FileVersionService) Delete(ctx context.Context, versionID string, body FileVersionDeleteParams, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
if body.FileID == "" {
err = errors.New("missing required fileId parameter")
return err
}
if versionID == "" {
err = errors.New("missing required versionId parameter")
return err
}
path := fmt.Sprintf("v1/files/%s/versions/%s", body.FileID, versionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return err
}
// This API returns an object with details or attributes of a file version.
func (r *FileVersionService) Get(ctx context.Context, versionID string, query FileVersionGetParams, opts ...option.RequestOption) (res *File, err error) {
opts = slices.Concat(r.Options, opts)
if query.FileID == "" {
err = errors.New("missing required fileId parameter")
return nil, err
}
if versionID == "" {
err = errors.New("missing required versionId parameter")
return nil, err
}
path := fmt.Sprintf("v1/files/%s/versions/%s", query.FileID, versionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// This API restores a file version as the current file version.
func (r *FileVersionService) Restore(ctx context.Context, versionID string, body FileVersionRestoreParams, opts ...option.RequestOption) (res *File, err error) {
opts = slices.Concat(r.Options, opts)
if body.FileID == "" {
err = errors.New("missing required fileId parameter")
return nil, err
}
if versionID == "" {
err = errors.New("missing required versionId parameter")
return nil, err
}
path := fmt.Sprintf("v1/files/%s/versions/%s/restore", body.FileID, versionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, nil, &res, opts...)
return res, err
}
type FileVersionDeleteParams struct {
FileID string `path:"fileId" api:"required" json:"-"`
paramObj
}
type FileVersionGetParams struct {
FileID string `path:"fileId" api:"required" json:"-"`
paramObj
}
type FileVersionRestoreParams struct {
FileID string `path:"fileId" api:"required" json:"-"`
paramObj
}