@@ -115,163 +115,3 @@ func NewImmichClient(endPoint string, key string, options ...clientOption) (*Imm
115115
116116 return & ic , nil
117117}
118-
119- // Ping server
120- func (ic * ImmichClient ) PingServer (ctx context.Context ) error {
121- r := PingResponse {}
122- b := bytes .NewBuffer (nil )
123- err := ic .newServerCall (ctx , EndPointPingServer ).do (getRequest ("/server/ping" , setAcceptJSON ()), responseCopy (b ), responseJSON (& r ))
124- if err != nil {
125- return fmt .Errorf ("unexpected response to the immich's ping API at this address: %s:\n %s" , ic .endPoint + "/server/ping" , b .String ())
126- }
127- if r .Res != "pong" {
128- return fmt .Errorf ("incorrect ping response: %s" , r .Res )
129- }
130- return nil
131- }
132-
133- // ValidateConnection
134- // Validate the connection by querying the identity of the user having the given key
135-
136- func (ic * ImmichClient ) ValidateConnection (ctx context.Context ) (User , error ) {
137- var user User
138-
139- err := ic .newServerCall (ctx , EndPointValidateConnection ).
140- do (getRequest ("/users/me" , setAcceptJSON ()), responseJSON (& user ))
141- if err != nil {
142- return user , err
143- }
144-
145- sm , err := ic .GetSupportedMediaTypes (ctx )
146- if err != nil {
147- return user , err
148- }
149- ic .supportedMediaTypes = sm
150- return user , nil
151- }
152-
153- type ServerStatistics struct {
154- Photos int `json:"photos"`
155- Videos int `json:"videos"`
156- Usage int64 `json:"usage"`
157- UsageByUser []struct {
158- UserID string `json:"userId"`
159- UserName string `json:"userName"`
160- Photos int `json:"photos"`
161- Videos int `json:"videos"`
162- Usage int64 `json:"usage"`
163- QuotaSizeInBytes any `json:"quotaSizeInBytes"`
164- } `json:"usageByUser"`
165- }
166-
167- // getServerStatistics
168- // Get server stats
169-
170- func (ic * ImmichClient ) GetServerStatistics (ctx context.Context ) (ServerStatistics , error ) {
171- var s ServerStatistics
172-
173- err := ic .newServerCall (ctx , EndPointGetServerStatistics ).do (getRequest ("/server/statistics" , setAcceptJSON ()), responseJSON (& s ))
174- return s , err
175- }
176-
177- // getAssetStatistics
178- // Get user's stats
179-
180- type UserStatistics struct {
181- Images int `json:"images"`
182- Videos int `json:"videos"`
183- Total int `json:"total"`
184- }
185-
186- func (ic * ImmichClient ) GetAssetStatistics (ctx context.Context ) (UserStatistics , error ) {
187- var s UserStatistics
188- err := ic .newServerCall (ctx , EndPointGetAssetStatistics ).do (getRequest ("/assets/statistics" , setAcceptJSON ()), responseJSON (& s ))
189- return s , err
190- }
191-
192- type SupportedMedia map [string ]string
193-
194- const (
195- TypeVideo = "video"
196- TypeImage = "image"
197- TypeSidecar = "sidecar"
198- TypeUnknown = ""
199- )
200-
201- var DefaultSupportedMedia = SupportedMedia {
202- ".3gp" : TypeVideo , ".avi" : TypeVideo , ".flv" : TypeVideo , ".insv" : TypeVideo , ".m2ts" : TypeVideo , ".m4v" : TypeVideo , ".mkv" : TypeVideo , ".mov" : TypeVideo , ".mp4" : TypeVideo , ".mpg" : TypeVideo , ".mts" : TypeVideo , ".webm" : TypeVideo , ".wmv" : TypeVideo ,
203- ".3fr" : TypeImage , ".ari" : TypeImage , ".arw" : TypeImage , ".avif" : TypeImage , ".bmp" : TypeImage , ".cap" : TypeImage , ".cin" : TypeImage , ".cr2" : TypeImage , ".cr3" : TypeImage , ".crw" : TypeImage , ".dcr" : TypeImage , ".dng" : TypeImage , ".erf" : TypeImage ,
204- ".fff" : TypeImage , ".gif" : TypeImage , ".heic" : TypeImage , ".heif" : TypeImage , ".hif" : TypeImage , ".iiq" : TypeImage , ".insp" : TypeImage , ".jpe" : TypeImage , ".jpeg" : TypeImage , ".jpg" : TypeImage ,
205- ".jxl" : TypeImage , ".k25" : TypeImage , ".kdc" : TypeImage , ".mrw" : TypeImage , ".nef" : TypeImage , ".orf" : TypeImage , ".ori" : TypeImage , ".pef" : TypeImage , ".png" : TypeImage , ".psd" : TypeImage , ".raf" : TypeImage , ".raw" : TypeImage , ".rw2" : TypeImage ,
206- ".rwl" : TypeImage , ".sr2" : TypeImage , ".srf" : TypeImage , ".srw" : TypeImage , ".tif" : TypeImage , ".tiff" : TypeImage , ".webp" : TypeImage , ".x3f" : TypeImage ,
207- ".xmp" : TypeSidecar ,
208- ".mp" : TypeVideo ,
209- }
210-
211- func (ic * ImmichClient ) GetSupportedMediaTypes (ctx context.Context ) (SupportedMedia , error ) {
212- var s map [string ][]string
213-
214- err := ic .newServerCall (ctx , EndPointGetSupportedMediaTypes ).do (getRequest ("/server/media-types" , setAcceptJSON ()), responseJSON (& s ))
215- if err != nil {
216- return nil , err
217- }
218- sm := make (SupportedMedia )
219- for t , l := range s {
220- for _ , e := range l {
221- sm [e ] = t
222- }
223- }
224- sm [".mp" ] = TypeVideo
225- return sm , err
226- }
227-
228- func (sm SupportedMedia ) TypeFromExt (ext string ) string {
229- ext = strings .ToLower (ext )
230- if strings .HasPrefix (ext , ".mp~" ) {
231- // #405
232- ext = ".mp4"
233- }
234- return sm [ext ]
235- }
236-
237- func (sm SupportedMedia ) IsMedia (ext string ) bool {
238- t := sm .TypeFromExt (ext )
239- return t == TypeVideo || t == TypeImage
240- }
241-
242- var (
243- _supportedExtension []string
244- initSupportedExtion sync.Once
245- )
246-
247- func (sm SupportedMedia ) IsExtensionPrefix (ext string ) bool {
248- initSupportedExtion .Do (func () {
249- _supportedExtension = make ([]string , len (sm ))
250- i := 0
251- for k := range sm {
252- _supportedExtension [i ] = k [:len (k )- 2 ]
253- i ++
254- }
255- sort .Strings (_supportedExtension )
256- })
257- ext = strings .ToLower (ext )
258- _ , b := slices .BinarySearch (_supportedExtension , ext )
259- return b
260- }
261-
262- func (sm SupportedMedia ) IsIgnoredExt (ext string ) bool {
263- t := sm .TypeFromExt (ext )
264- return t == ""
265- }
266-
267- func (ic * ImmichClient ) TypeFromExt (ext string ) string {
268- return ic .supportedMediaTypes .TypeFromExt (ext )
269- }
270-
271- func (ic * ImmichClient ) IsExtensionPrefix (ext string ) bool {
272- return ic .supportedMediaTypes .IsExtensionPrefix (ext )
273- }
274-
275- func (ic * ImmichClient ) IsIgnoredExt (ext string ) bool {
276- return ic .supportedMediaTypes .IsIgnoredExt (ext )
277- }
0 commit comments