2021-01-31 07:41:23 +01:00
|
|
|
package api
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// GetPhoto can be used to get a photo by UUID
|
|
|
|
//
|
|
|
|
//GET /api/v1/photos/:uuid
|
2021-01-31 07:41:23 +01:00
|
|
|
//
|
|
|
|
// Parameters:
|
2021-01-31 09:08:52 +01:00
|
|
|
// uuid: string PhotoUID as returned by the API
|
2021-02-10 01:00:02 +01:00
|
|
|
func (v1 *V1Client) GetPhoto(uuid string) (Photo, error) {
|
2021-02-12 03:04:53 +01:00
|
|
|
photo := Photo{
|
2021-01-31 09:08:52 +01:00
|
|
|
UUID: uuid,
|
|
|
|
}
|
2021-02-12 03:04:53 +01:00
|
|
|
err := v1.GET("/api/v1/photos/%s", uuid).JSON(&photo)
|
|
|
|
return photo, err
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// PhotoOptions is used while listing photos. These
|
|
|
|
// fields can be optionally set to query for specific
|
|
|
|
// photos.
|
2021-02-12 02:16:37 +01:00
|
|
|
type PhotoOptions struct {
|
|
|
|
Count int
|
|
|
|
Offset int
|
|
|
|
AlbumUID string
|
|
|
|
Filter string
|
|
|
|
Merged bool
|
|
|
|
Country string
|
|
|
|
Camera int
|
|
|
|
Order string
|
|
|
|
Q string
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
DefaultPhotoOptionsCount = 60
|
|
|
|
DefaultPhotoOptionsOffset = 0
|
|
|
|
DefaultPhotoOptionsMerged = true
|
|
|
|
DefaultPhotoOptionsCamera = 0
|
|
|
|
DefaultPhotoOptionsOrder = "oldest"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GET /api/v1/photos/
|
|
|
|
//
|
|
|
|
// http://localhost:8080/api/v1/photos?
|
|
|
|
// count=60&offset=0&album=aqoe4m9204aigugh&filter=&merged=true&country=&camera=0&order=oldest&q=
|
|
|
|
func (v1 *V1Client) GetPhotos(options *PhotoOptions) ([]Photo, error) {
|
|
|
|
var photos []Photo
|
|
|
|
if options == nil {
|
|
|
|
options = &PhotoOptions{
|
|
|
|
Count: DefaultPhotoOptionsCount,
|
|
|
|
Offset: DefaultPhotoOptionsOffset,
|
|
|
|
Merged: DefaultPhotoOptionsMerged,
|
|
|
|
Order: DefaultPhotoOptionsOrder,
|
|
|
|
Camera: DefaultPhotoOptionsCamera,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if options.Count == 0 {
|
|
|
|
return photos, nil
|
|
|
|
}
|
|
|
|
if options.Order == "" {
|
|
|
|
options.Order = DefaultPhotoOptionsOrder
|
|
|
|
}
|
|
|
|
err := v1.GET("/api/v1/photos?count=%d&offset=%d&album=%s&filter=%s&merged=%t&country=%s&camera=%d&order=%s&q=%s",
|
|
|
|
options.Count, options.Offset, options.AlbumUID, options.Filter, options.Merged, options.Country, options.Camera, options.Order, options.Q).JSON(&photos)
|
|
|
|
return photos, err
|
|
|
|
}
|
|
|
|
|
2021-01-31 07:41:23 +01:00
|
|
|
// PUT /api/v1/photos/:uid
|
2021-02-10 03:25:46 +01:00
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// uuid: string PhotoUUID as returned by the API
|
2021-02-12 03:04:53 +01:00
|
|
|
func (v1 *V1Client) UpdatePhoto(photo Photo) (Photo, error) {
|
|
|
|
err := v1.PUT(&photo, "/api/v1/photos/%s", photo.UUID).JSON(&photo)
|
|
|
|
return photo, err
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|
|
|
|
|
2021-01-31 09:08:52 +01:00
|
|
|
// GET /api/v1/photos/:uuid/dl
|
2021-01-31 07:41:23 +01:00
|
|
|
//
|
|
|
|
// Parameters:
|
2021-01-31 09:08:52 +01:00
|
|
|
// uuid: string PhotoUUID as returned by the API
|
2021-02-10 03:25:46 +01:00
|
|
|
func (v1 *V1Client) GetPhotoDownload(uuid string) ([]byte, error) {
|
|
|
|
resp := v1.GET("/api/v1/photos/%s/dl?t=%s", uuid, v1.downloadToken)
|
|
|
|
return resp.Body, resp.Error
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|
|
|
|
|
2021-01-31 09:08:52 +01:00
|
|
|
// GET /api/v1/photos/:uuid/yaml
|
2021-01-31 07:41:23 +01:00
|
|
|
//
|
|
|
|
// Parameters:
|
2021-01-31 09:08:52 +01:00
|
|
|
// uuid: string PhotoUUID as returned by the API
|
2021-02-10 03:25:46 +01:00
|
|
|
func (v1 *V1Client) GetPhotoYaml(uuid string) ([]byte, error) {
|
|
|
|
resp := v1.GET("/api/v1/photos/%s/yaml", uuid)
|
|
|
|
return resp.Body, resp.Error
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|
|
|
|
|
2021-01-31 09:08:52 +01:00
|
|
|
// POST /api/v1/photos/:uuid/approve
|
2021-01-31 07:41:23 +01:00
|
|
|
//
|
|
|
|
// Parameters:
|
2021-01-31 09:08:52 +01:00
|
|
|
// uuid: string PhotoUUID as returned by the API
|
2021-02-10 03:25:46 +01:00
|
|
|
func (v1 *V1Client) ApprovePhoto(uuid string) error {
|
|
|
|
resp := v1.POST(nil, "/api/v1/photos/%s/approve", uuid)
|
|
|
|
return resp.Error
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// POST /api/v1/photos/:uid/like
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// uid: string PhotoUID as returned by the API
|
2021-02-04 06:01:21 +01:00
|
|
|
func (v1 *V1Client) LikePhoto(uuid string) error {
|
2021-02-10 03:25:46 +01:00
|
|
|
resp := v1.POST(nil, "/api/v1/photos/%s/like", uuid)
|
|
|
|
return resp.Error
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|
|
|
|
|
2021-01-31 09:08:52 +01:00
|
|
|
// DELETE /api/v1/photos/:uuid/like
|
2021-01-31 07:41:23 +01:00
|
|
|
//
|
|
|
|
// Parameters:
|
2021-01-31 09:08:52 +01:00
|
|
|
// uuid: string PhotoUUID as returned by the API
|
2021-02-04 06:01:21 +01:00
|
|
|
func (v1 *V1Client) DislikePhoto(uuid string) error {
|
2021-02-10 03:25:46 +01:00
|
|
|
resp := v1.DELETE(nil, "/api/v1/photos/%s/approve", uuid)
|
|
|
|
return resp.Error
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// POST /api/v1/photos/:uid/files/:file_uid/primary
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// uid: string PhotoUID as returned by the API
|
|
|
|
// file_uid: string File UID as returned by the API
|
2021-02-04 06:01:21 +01:00
|
|
|
func (v1 *V1Client) PhotoPrimary(uuid, fileuuid string) error {
|
2021-02-10 03:25:46 +01:00
|
|
|
resp := v1.POST(nil, "/api/v1/photos/%s/files/%s/primary", uuid, fileuuid)
|
|
|
|
return resp.Error
|
2021-01-31 07:41:23 +01:00
|
|
|
}
|