2019-12-05 19:21:35 +01:00
|
|
|
package form
|
2018-08-15 09:59:51 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-01-15 04:04:33 +01:00
|
|
|
// PhotoSearch represents search form fields for "/api/v1/photos".
|
2019-12-05 19:21:35 +01:00
|
|
|
type PhotoSearch struct {
|
2020-12-19 19:15:32 +01:00
|
|
|
Query string `form:"q"`
|
|
|
|
Filter string `form:"filter"`
|
|
|
|
ID string `form:"id"`
|
|
|
|
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"`
|
|
|
|
Hash string `form:"hash"`
|
|
|
|
Primary bool `form:"primary"`
|
|
|
|
Stack bool `form:"stack"`
|
|
|
|
Unstacked bool `form:"unstacked"`
|
|
|
|
Stackable bool `form:"stackable"`
|
|
|
|
Video bool `form:"video"`
|
|
|
|
Photo bool `form:"photo"`
|
|
|
|
Scan bool `form:"scan"`
|
|
|
|
Panorama bool `form:"panorama"`
|
|
|
|
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"`
|
|
|
|
Portrait bool `form:"portrait"`
|
|
|
|
Geo bool `form:"geo"`
|
2021-08-29 16:16:49 +02:00
|
|
|
Keywords string `form:"keywords"`
|
2020-12-19 19:15:32 +01:00
|
|
|
Label string `form:"label"`
|
|
|
|
Category string `form:"category"` // Moments
|
|
|
|
Country string `form:"country"` // Moments
|
|
|
|
State string `form:"state"` // Moments
|
2021-09-20 23:32:35 +02:00
|
|
|
Year string `form:"year"` // Moments
|
|
|
|
Month string `form:"month"` // Moments
|
|
|
|
Day string `form:"day"` // Moments
|
2021-09-18 15:32:39 +02:00
|
|
|
Face string `form:"face"` // UIDs
|
|
|
|
Subject string `form:"subject"` // UIDs
|
2021-09-20 12:36:59 +02:00
|
|
|
Person string `form:"person"` // Alias for Subject
|
2021-09-18 15:32:39 +02:00
|
|
|
Subjects string `form:"subjects"` // Text
|
|
|
|
People string `form:"people"` // Alias for Subjects
|
|
|
|
Album string `form:"album"` // UIDs
|
|
|
|
Albums string `form:"albums"` // Text
|
2020-12-19 19:15:32 +01:00
|
|
|
Color string `form:"color"`
|
2021-05-26 10:46:32 +02:00
|
|
|
Faces string `form:"faces"` // Find or exclude faces if detected.
|
2020-12-19 19:15:32 +01:00
|
|
|
Quality int `form:"quality"`
|
|
|
|
Review bool `form:"review"`
|
|
|
|
Camera int `form:"camera"`
|
|
|
|
Lens int `form:"lens"`
|
|
|
|
Before time.Time `form:"before" time_format:"2006-01-02"`
|
|
|
|
After time.Time `form:"after" time_format:"2006-01-02"`
|
|
|
|
Count int `form:"count" binding:"required" serialize:"-"`
|
|
|
|
Offset int `form:"offset" serialize:"-"`
|
|
|
|
Order string `form:"order" serialize:"-"`
|
|
|
|
Merged bool `form:"merged" serialize:"-"`
|
2019-05-15 21:51:00 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 04:04:33 +01:00
|
|
|
func (f *PhotoSearch) GetQuery() string {
|
|
|
|
return f.Query
|
|
|
|
}
|
2019-05-15 21:51:00 +02:00
|
|
|
|
2020-01-15 04:04:33 +01:00
|
|
|
func (f *PhotoSearch) SetQuery(q string) {
|
|
|
|
f.Query = q
|
|
|
|
}
|
2019-05-15 23:07:25 +02:00
|
|
|
|
2020-01-15 04:04:33 +01:00
|
|
|
func (f *PhotoSearch) 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.
|
|
|
|
func (f *PhotoSearch) Serialize() string {
|
|
|
|
return Serialize(f, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SerializeAll returns a string containing all non-empty fields and values of a struct.
|
|
|
|
func (f *PhotoSearch) SerializeAll() string {
|
|
|
|
return Serialize(f, true)
|
|
|
|
}
|
|
|
|
|
2020-02-02 13:01:26 +01:00
|
|
|
func NewPhotoSearch(query string) PhotoSearch {
|
|
|
|
return PhotoSearch{Query: query}
|
|
|
|
}
|