-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
albums.go
144 lines (131 loc) · 5.04 KB
/
albums.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package immich
import (
"context"
"fmt"
)
type AlbumSimplified struct {
ID string `json:"id,omitempty"`
AlbumName string `json:"albumName"`
Description string `json:"description,omitempty"`
// OwnerID string `json:"ownerId"`
// CreatedAt time.Time `json:"createdAt"`
// UpdatedAt time.Time `json:"updatedAt"`
// AlbumThumbnailAssetID string `json:"albumThumbnailAssetId"`
// SharedUsers []string `json:"sharedUsers"`
// Owner User `json:"owner"`
// Shared bool `json:"shared"`
// AssetCount int `json:"assetCount"`
// LastModifiedAssetTimestamp time.Time `json:"lastModifiedAssetTimestamp"
AssetIds []string `json:"assetIds,omitempty"`
}
func (ic *ImmichClient) GetAllAlbums(ctx context.Context) ([]AlbumSimplified, error) {
var albums []AlbumSimplified
err := ic.newServerCall(ctx, EndPointGetAllAlbums).do(getRequest("/albums", setAcceptJSON()), responseJSON(&albums))
if err != nil {
return nil, err
}
return albums, nil
}
type AlbumContent struct {
ID string `json:"id,omitempty"`
// OwnerID string `json:"ownerId"`
AlbumName string `json:"albumName"`
Description string `json:"description"`
Shared bool `json:"shared"`
Assets []AssetSimplified `json:"assets,omitempty"`
AssetIDs []string `json:"assetIds,omitempty"`
// CreatedAt time.Time `json:"createdAt"`
// UpdatedAt time.Time `json:"updatedAt"`
// AlbumThumbnailAssetID string `json:"albumThumbnailAssetId"`
// SharedUsers []string `json:"sharedUsers"`
// Owner User `json:"owner"`
// AssetCount int `json:"assetCount"`
// LastModifiedAssetTimestamp time.Time `json:"lastModifiedAssetTimestamp"
}
// immich Asset simplified
type AssetSimplified struct {
ID string `json:"id"`
DeviceAssetID string `json:"deviceAssetId"`
// // OwnerID string `json:"ownerId"`
// DeviceID string `json:"deviceId"`
// Type string `json:"type"`
// OriginalPath string `json:"originalPath"`
// OriginalFileName string `json:"originalFileName"`
// // Resized bool `json:"resized"`
// // Thumbhash string `json:"thumbhash"`
// FileCreatedAt time.Time `json:"fileCreatedAt"`
// // FileModifiedAt time.Time `json:"fileModifiedAt"`
// UpdatedAt time.Time `json:"updatedAt"`
// // IsFavorite bool `json:"isFavorite"`
// // IsArchived bool `json:"isArchived"`
// // Duration string `json:"duration"`
// // ExifInfo ExifInfo `json:"exifInfo"`
// // LivePhotoVideoID any `json:"livePhotoVideoId"`
// // Tags []any `json:"tags"`
// Checksum string `json:"checksum"`
// JustUploaded bool `json:"-"`
}
func (ic *ImmichClient) GetAlbumInfo(ctx context.Context, id string, withoutAssets bool) (AlbumContent, error) {
var album AlbumContent
query := id
if withoutAssets {
query += "?withoutAssets=true"
}
err := ic.newServerCall(ctx, EndPointGetAlbumInfo).do(getRequest("/albums/"+query, setAcceptJSON()), responseJSON(&album))
return album, err
}
func (ic *ImmichClient) GetAssetsAlbums(ctx context.Context, id string) ([]AlbumSimplified, error) {
var albums []AlbumSimplified
err := ic.newServerCall(ctx, EndPointGetAlbumInfo).do(getRequest("/albums", setAcceptJSON()), responseJSON(&albums))
if err != nil {
return nil, err
}
return albums, nil
}
type UpdateAlbum struct {
IDS []string `json:"ids"`
}
type UpdateAlbumResult struct {
ID string `json:"id"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
func (ic *ImmichClient) AddAssetToAlbum(ctx context.Context, albumID string, assets []string) ([]UpdateAlbumResult, error) {
var r []UpdateAlbumResult
body := UpdateAlbum{
IDS: assets,
}
err := ic.newServerCall(ctx, EndPointAddAsstToAlbum).do(
putRequest(fmt.Sprintf("/albums/%s/assets", albumID), setAcceptJSON(),
setJSONBody(body)),
responseJSON(&r))
if err != nil {
return nil, err
}
return r, nil
}
func (ic *ImmichClient) CreateAlbum(ctx context.Context, name string, description string, assetsIDs []string) (AlbumSimplified, error) {
body := AlbumContent{
AlbumName: name,
Description: description,
AssetIDs: assetsIDs,
}
var r AlbumSimplified
err := ic.newServerCall(ctx, EndPointCreateAlbum).do(
postRequest("/albums", "application/json", setAcceptJSON(), setJSONBody(body)),
responseJSON(&r))
if err != nil {
return AlbumSimplified{}, err
}
return r, nil
}
func (ic *ImmichClient) GetAssetAlbums(ctx context.Context, id string) ([]AlbumSimplified, error) {
var r []AlbumSimplified
err := ic.newServerCall(ctx, EndPointGetAssetAlbums).do(
getRequest("/albums?assetId="+id, setAcceptJSON()),
responseJSON(&r))
return r, err
}
func (ic *ImmichClient) DeleteAlbum(ctx context.Context, id string) error {
return ic.newServerCall(ctx, EndPointDeleteAlbum).do(deleteRequest("/albums/" + id))
}