2018-09-24 19:14:15 +00:00
|
|
|
package api
|
2018-09-24 09:27:46 +00:00
|
|
|
|
|
|
|
import (
|
2018-10-31 06:14:33 +00:00
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
2018-09-24 09:27:46 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gin-gonic/gin/binding"
|
2020-07-04 10:54:35 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
2019-12-05 18:21:35 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
2020-07-04 10:54:35 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/query"
|
2018-09-24 09:27:46 +00:00
|
|
|
)
|
|
|
|
|
2018-11-06 09:43:59 +00:00
|
|
|
// GET /api/v1/photos
|
2018-11-06 09:28:44 +00:00
|
|
|
//
|
|
|
|
// Query:
|
2018-11-06 09:43:59 +00:00
|
|
|
// q: string Query string
|
2019-06-05 16:25:20 +00:00
|
|
|
// label: string Label
|
2018-11-06 09:43:59 +00:00
|
|
|
// cat: string Category
|
|
|
|
// country: string Country code
|
2019-12-09 07:04:41 +00:00
|
|
|
// camera: int UpdateCamera ID
|
2018-11-06 09:43:59 +00:00
|
|
|
// order: string Sort order
|
|
|
|
// count: int Max result count (required)
|
|
|
|
// offset: int Result offset
|
|
|
|
// before: date Find photos taken before (format: "2006-01-02")
|
|
|
|
// after: date Find photos taken after (format: "2006-01-02")
|
2020-05-14 17:03:12 +00:00
|
|
|
// favorite: bool Find favorites only
|
2020-06-25 12:54:04 +00:00
|
|
|
func GetPhotos(router *gin.RouterGroup) {
|
2018-09-24 09:27:46 +00:00
|
|
|
router.GET("/photos", func(c *gin.Context) {
|
2020-06-25 12:54:04 +00:00
|
|
|
s := Auth(SessionID(c), acl.ResourcePhotos, acl.ActionSearch)
|
|
|
|
|
|
|
|
if s.Invalid() {
|
2020-07-04 10:54:35 +00:00
|
|
|
AbortUnauthorized(c)
|
2020-01-22 12:43:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-05 18:21:35 +00:00
|
|
|
var f form.PhotoSearch
|
2019-05-16 06:41:16 +00:00
|
|
|
|
2019-12-05 18:21:35 +00:00
|
|
|
err := c.MustBindWith(&f, binding.Form)
|
2019-05-16 06:41:16 +00:00
|
|
|
|
2019-01-15 13:00:42 +00:00
|
|
|
if err != nil {
|
2020-07-04 10:54:35 +00:00
|
|
|
AbortBadRequest(c)
|
2019-01-15 13:00:42 +00:00
|
|
|
return
|
|
|
|
}
|
2018-09-24 09:27:46 +00:00
|
|
|
|
2020-06-26 10:16:13 +00:00
|
|
|
// Guests may only see public content in shared albums.
|
|
|
|
if s.Guest() {
|
|
|
|
if f.Album == "" || !s.HasShare(f.Album) {
|
2020-07-04 10:54:35 +00:00
|
|
|
AbortUnauthorized(c)
|
2020-06-26 10:16:13 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f.Public = true
|
|
|
|
f.Private = false
|
|
|
|
f.Hidden = false
|
|
|
|
f.Archived = false
|
|
|
|
f.Review = false
|
2020-06-25 12:54:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 17:10:44 +00:00
|
|
|
result, count, err := query.PhotoSearch(f)
|
2019-12-08 21:45:45 +00:00
|
|
|
|
2018-09-24 09:27:46 +00:00
|
|
|
if err != nil {
|
2020-07-04 10:54:35 +00:00
|
|
|
log.Error(err)
|
|
|
|
AbortBadRequest(c)
|
2019-01-15 13:00:42 +00:00
|
|
|
return
|
2018-09-24 09:27:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 18:07:58 +00:00
|
|
|
c.Header("X-Count", strconv.Itoa(count))
|
|
|
|
c.Header("X-Limit", strconv.Itoa(f.Count))
|
|
|
|
c.Header("X-Offset", strconv.Itoa(f.Offset))
|
2019-05-16 06:41:16 +00:00
|
|
|
|
2018-09-24 09:27:46 +00:00
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
})
|
2018-09-27 06:59:53 +00:00
|
|
|
}
|