-
Notifications
You must be signed in to change notification settings - Fork 7
/
media.go
46 lines (40 loc) · 1.14 KB
/
media.go
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
package ankiconnect
import (
"github.com/privatesquare/bkst-go-utils/utils/errors"
)
const (
ActionRetrieveMedia = "retrieveMediaFile"
// TODO
// storeMediaFile
// getMediaFileNames
// deleteMediaFile
)
type (
// Media describes the interface that can be used to perform operations stored media.
MediaManager interface {
// Returns the contents of the file encoded in base64
RetrieveMediaFile(filename string) (*string, *errors.RestErr)
}
ParamsRetrieveMediaFile struct {
Filename string `json:"filename,omitempty"`
}
// mediaManager implements MediaManager.
mediaManager struct {
Client *Client
}
)
// RetrieveMediaFile retrieve the contents of the named file from Anki.
// The result is a string with the base64-encoded contents.
// The method returns an error if:
// - the api request to ankiconnect fails.
// - the api returns a http error.
func (mm *mediaManager) RetrieveMediaFile(filename string) (*string, *errors.RestErr) {
params := ParamsRetrieveMediaFile{
Filename: filename,
}
result, restErr := post[string](mm.Client, ActionRetrieveMedia, ¶ms)
if restErr != nil {
return nil, restErr
}
return result, nil
}