2019-12-05 19:21:35 +01:00
|
|
|
package form
|
2018-08-15 09:59:51 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-11-26 13:59:10 +01:00
|
|
|
// SearchPhotos represents search form fields for "/api/v1/photos".
|
|
|
|
type SearchPhotos struct {
|
2020-12-19 19:15:32 +01:00
|
|
|
Query string `form:"q"`
|
2022-04-13 09:48:51 +02:00
|
|
|
Filter string `form:"filter" notes:"-"`
|
2021-12-16 11:42:57 +01:00
|
|
|
UID string `form:"uid"`
|
2020-12-19 19:15:32 +01:00
|
|
|
Type string `form:"type"`
|
|
|
|
Path string `form:"path"`
|
|
|
|
Folder string `form:"folder"` // Alias for Path
|
|
|
|
Name string `form:"name"`
|
|
|
|
Filename string `form:"filename"`
|
|
|
|
Original string `form:"original"`
|
|
|
|
Title string `form:"title"`
|
2022-04-13 09:48:51 +02:00
|
|
|
Hash string `form:"hash" example:"hash:2fd4e1c67a2d"`
|
2020-12-19 19:15:32 +01:00
|
|
|
Primary bool `form:"primary"`
|
|
|
|
Stack bool `form:"stack"`
|
|
|
|
Unstacked bool `form:"unstacked"`
|
|
|
|
Stackable bool `form:"stackable"`
|
|
|
|
Video bool `form:"video"`
|
2022-04-14 10:49:56 +02:00
|
|
|
Vector bool `form:"vector" notes:"Vector Graphics"`
|
|
|
|
Animated bool `form:"animated" notes:"Animated GIFs"`
|
|
|
|
Photo bool `form:"photo" notes:"No Videos"`
|
|
|
|
Raw bool `form:"raw" notes:"RAW Images"`
|
|
|
|
Live bool `form:"live" notes:"Live Photos, Short Videos"`
|
|
|
|
Scan bool `form:"scan" notes:"Scanned Images, Documents"`
|
|
|
|
Panorama bool `form:"panorama" notes:"Aspect Ratio > 1.9:1"`
|
2022-04-13 09:48:51 +02:00
|
|
|
Portrait bool `form:"portrait"`
|
|
|
|
Landscape bool `form:"landscape"`
|
|
|
|
Square bool `form:"square"`
|
2020-12-19 19:15:32 +01:00
|
|
|
Error bool `form:"error"`
|
|
|
|
Hidden bool `form:"hidden"`
|
|
|
|
Archived bool `form:"archived"`
|
|
|
|
Public bool `form:"public"`
|
|
|
|
Private bool `form:"private"`
|
|
|
|
Favorite bool `form:"favorite"`
|
|
|
|
Unsorted bool `form:"unsorted"`
|
|
|
|
Lat float32 `form:"lat"`
|
|
|
|
Lng float32 `form:"lng"`
|
|
|
|
Dist uint `form:"dist"`
|
|
|
|
Fmin float32 `form:"fmin"`
|
|
|
|
Fmax float32 `form:"fmax"`
|
|
|
|
Chroma uint8 `form:"chroma"`
|
|
|
|
Diff uint32 `form:"diff"`
|
|
|
|
Mono bool `form:"mono"`
|
|
|
|
Geo bool `form:"geo"`
|
2022-04-14 10:49:56 +02:00
|
|
|
Keywords string `form:"keywords"` // Filter by keyword(s)
|
|
|
|
Label string `form:"label"` // Label name
|
|
|
|
Category string `form:"category"` // Moments
|
|
|
|
Country string `form:"country"` // Moments
|
|
|
|
State string `form:"state"` // Moments
|
|
|
|
Year string `form:"year"` // Moments
|
|
|
|
Month string `form:"month"` // Moments
|
|
|
|
Day string `form:"day"` // Moments
|
|
|
|
Face string `form:"face"` // UIDs
|
|
|
|
Subject string `form:"subject"` // UIDs
|
|
|
|
Person string `form:"person"` // Alias for Subject
|
|
|
|
Subjects string `form:"subjects"` // People names
|
|
|
|
People string `form:"people"` // Alias for Subjects
|
|
|
|
Album string `form:"album" notes:"Single name with * wildcard"` // Album UIDs or name
|
|
|
|
Albums string `form:"albums" example:"albums:\"South Africa & Birds\"" notes:"Album names can be combined with & and |"` // Multi search with and/or
|
|
|
|
Color string `form:"color"` // Main color
|
|
|
|
Faces string `form:"faces"` // Find or exclude faces if detected.
|
|
|
|
Quality int `form:"quality"` // Photo quality score
|
|
|
|
Review bool `form:"review"` // Find photos in review
|
|
|
|
Camera string `form:"camera" example:"camera:canon"` // Camera UID or name
|
|
|
|
Lens string `form:"lens" example:"lens:ef24"` // Lens UID or name
|
|
|
|
Before time.Time `form:"before" time_format:"2006-01-02" notes:"Taken before this date"` // Finds images taken before date
|
|
|
|
After time.Time `form:"after" time_format:"2006-01-02" notes:"Taken after this date"` // Finds images taken after date
|
|
|
|
Count int `form:"count" binding:"required" serialize:"-"` // Result FILE limit
|
|
|
|
Offset int `form:"offset" serialize:"-"` // Result FILE offset
|
|
|
|
Order string `form:"order" serialize:"-"` // Sort order
|
|
|
|
Merged bool `form:"merged" serialize:"-"` // Merge FILES in response
|
2019-05-15 21:51:00 +02:00
|
|
|
}
|
|
|
|
|
2021-11-26 13:59:10 +01:00
|
|
|
func (f *SearchPhotos) GetQuery() string {
|
2020-01-15 04:04:33 +01:00
|
|
|
return f.Query
|
|
|
|
}
|
2019-05-15 21:51:00 +02:00
|
|
|
|
2021-11-26 13:59:10 +01:00
|
|
|
func (f *SearchPhotos) SetQuery(q string) {
|
2020-01-15 04:04:33 +01:00
|
|
|
f.Query = q
|
|
|
|
}
|
2019-05-15 23:07:25 +02:00
|
|
|
|
2021-11-26 13:59:10 +01:00
|
|
|
func (f *SearchPhotos) ParseQueryString() error {
|
2020-05-30 01:41:47 +02:00
|
|
|
if err := ParseQueryString(f); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-21 16:46:22 +02:00
|
|
|
|
|
|
|
if f.Path == "" && f.Folder != "" {
|
|
|
|
f.Path = f.Folder
|
2021-09-20 12:36:59 +02:00
|
|
|
f.Folder = ""
|
2020-05-21 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 12:36:59 +02:00
|
|
|
if f.Subject == "" && f.Person != "" {
|
|
|
|
f.Subject = f.Person
|
|
|
|
f.Person = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Subjects == "" && f.People != "" {
|
2021-08-29 16:16:49 +02:00
|
|
|
f.Subjects = f.People
|
2021-09-20 12:36:59 +02:00
|
|
|
f.People = ""
|
2021-08-29 16:16:49 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 01:41:47 +02:00
|
|
|
if f.Filter != "" {
|
|
|
|
if err := Unserialize(f, f.Filter); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-08-15 09:59:51 +02:00
|
|
|
}
|
2020-02-02 13:01:26 +01:00
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
// Serialize returns a string containing non-empty fields and values of a struct.
|
2021-11-26 13:59:10 +01:00
|
|
|
func (f *SearchPhotos) Serialize() string {
|
2020-05-23 20:58:58 +02:00
|
|
|
return Serialize(f, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SerializeAll returns a string containing all non-empty fields and values of a struct.
|
2021-11-26 13:59:10 +01:00
|
|
|
func (f *SearchPhotos) SerializeAll() string {
|
2020-05-23 20:58:58 +02:00
|
|
|
return Serialize(f, true)
|
|
|
|
}
|
|
|
|
|
2021-11-26 13:59:10 +01:00
|
|
|
func NewPhotoSearch(query string) SearchPhotos {
|
|
|
|
return SearchPhotos{Query: query}
|
2020-02-02 13:01:26 +01:00
|
|
|
}
|