2022-03-30 20:36:25 +02:00
|
|
|
package search
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2022-04-03 09:45:05 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
2022-03-30 20:36:25 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/thumb"
|
|
|
|
"github.com/photoprism/photoprism/internal/viewer"
|
|
|
|
)
|
|
|
|
|
2022-04-03 09:45:05 +02:00
|
|
|
// PhotosViewerResults finds photos based on the search form provided and returns them as viewer.Results.
|
|
|
|
func PhotosViewerResults(f form.SearchPhotos, contentUri, apiUri, previewToken, downloadToken string) (viewer.Results, int, error) {
|
|
|
|
if results, count, err := searchPhotos(f, PhotosColsView); err != nil {
|
|
|
|
return viewer.Results{}, count, err
|
|
|
|
} else {
|
|
|
|
return results.ViewerResults(contentUri, apiUri, previewToken, downloadToken), count, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-30 20:36:25 +02:00
|
|
|
// ViewerResult returns a new photo viewer result.
|
|
|
|
func (photo Photo) ViewerResult(contentUri, apiUri, previewToken, downloadToken string) viewer.Result {
|
|
|
|
return viewer.Result{
|
2022-03-31 17:09:08 +02:00
|
|
|
UID: photo.PhotoUID,
|
|
|
|
Title: photo.PhotoTitle,
|
|
|
|
TakenAtLocal: photo.TakenAtLocal,
|
|
|
|
Description: photo.PhotoDescription,
|
|
|
|
Favorite: photo.PhotoFavorite,
|
2022-04-13 22:17:59 +02:00
|
|
|
Playable: photo.IsPlayable(),
|
2022-03-31 17:09:08 +02:00
|
|
|
DownloadUrl: viewer.DownloadUrl(photo.FileHash, apiUri, downloadToken),
|
|
|
|
Width: photo.FileWidth,
|
|
|
|
Height: photo.FileHeight,
|
2022-07-06 23:01:54 +02:00
|
|
|
Thumbs: thumb.Public{
|
|
|
|
Fit720: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit720], contentUri, previewToken),
|
|
|
|
Fit1280: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit1280], contentUri, previewToken),
|
|
|
|
Fit1920: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit1920], contentUri, previewToken),
|
|
|
|
Fit2048: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit2048], contentUri, previewToken),
|
|
|
|
Fit2560: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit2560], contentUri, previewToken),
|
|
|
|
Fit3840: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit3840], contentUri, previewToken),
|
|
|
|
Fit4096: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit4096], contentUri, previewToken),
|
|
|
|
Fit7680: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit7680], contentUri, previewToken),
|
2022-03-31 17:09:08 +02:00
|
|
|
},
|
2022-03-30 20:36:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ViewerJSON returns the results as photo viewer JSON.
|
|
|
|
func (photos PhotoResults) ViewerJSON(contentUri, apiUri, previewToken, downloadToken string) ([]byte, error) {
|
|
|
|
return json.Marshal(photos.ViewerResults(contentUri, apiUri, previewToken, downloadToken))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ViewerResults returns the results photo viewer formatted.
|
|
|
|
func (photos PhotoResults) ViewerResults(contentUri, apiUri, previewToken, downloadToken string) (results viewer.Results) {
|
|
|
|
results = make(viewer.Results, 0, len(photos))
|
|
|
|
|
|
|
|
for _, p := range photos {
|
|
|
|
results = append(results, p.ViewerResult(contentUri, apiUri, previewToken, downloadToken))
|
|
|
|
}
|
|
|
|
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
// ViewerResult creates a new photo viewer result.
|
|
|
|
func (photo GeoResult) ViewerResult(contentUri, apiUri, previewToken, downloadToken string) viewer.Result {
|
|
|
|
return viewer.Result{
|
2022-03-31 17:09:08 +02:00
|
|
|
UID: photo.PhotoUID,
|
|
|
|
Title: photo.PhotoTitle,
|
|
|
|
TakenAtLocal: photo.TakenAtLocal,
|
|
|
|
Description: photo.PhotoDescription,
|
|
|
|
Favorite: photo.PhotoFavorite,
|
2022-04-13 22:17:59 +02:00
|
|
|
Playable: photo.IsPlayable(),
|
2022-03-31 17:09:08 +02:00
|
|
|
DownloadUrl: viewer.DownloadUrl(photo.FileHash, apiUri, downloadToken),
|
|
|
|
Width: photo.FileWidth,
|
|
|
|
Height: photo.FileHeight,
|
2022-07-06 23:01:54 +02:00
|
|
|
Thumbs: thumb.Public{
|
|
|
|
Fit720: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit720], contentUri, previewToken),
|
|
|
|
Fit1280: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit1280], contentUri, previewToken),
|
|
|
|
Fit1920: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit1920], contentUri, previewToken),
|
|
|
|
Fit2048: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit2048], contentUri, previewToken),
|
|
|
|
Fit2560: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit2560], contentUri, previewToken),
|
|
|
|
Fit3840: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit3840], contentUri, previewToken),
|
|
|
|
Fit4096: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit4096], contentUri, previewToken),
|
|
|
|
Fit7680: thumb.New(photo.FileWidth, photo.FileHeight, photo.FileHash, thumb.Sizes[thumb.Fit7680], contentUri, previewToken),
|
2022-03-31 17:09:08 +02:00
|
|
|
},
|
2022-03-30 20:36:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ViewerJSON returns the results as photo viewer JSON.
|
|
|
|
func (photos GeoResults) ViewerJSON(contentUri, apiUri, previewToken, downloadToken string) ([]byte, error) {
|
|
|
|
results := make(viewer.Results, 0, len(photos))
|
|
|
|
|
|
|
|
for _, p := range photos {
|
|
|
|
results = append(results, p.ViewerResult(contentUri, apiUri, previewToken, downloadToken))
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(results)
|
|
|
|
}
|