2020-01-02 00:03:07 +01:00
package config
import (
"strings"
"time"
2022-09-28 09:01:17 +02:00
"github.com/photoprism/photoprism/internal/acl"
"github.com/photoprism/photoprism/internal/customize"
2020-01-02 00:03:07 +01:00
"github.com/photoprism/photoprism/internal/entity"
2022-01-18 12:26:33 +01:00
"github.com/photoprism/photoprism/internal/query"
2020-01-13 11:07:09 +01:00
"github.com/photoprism/photoprism/pkg/colors"
2022-04-15 09:42:07 +02:00
"github.com/photoprism/photoprism/pkg/env"
2020-04-26 14:31:33 +02:00
"github.com/photoprism/photoprism/pkg/txt"
2020-01-02 00:03:07 +01:00
)
2022-07-05 23:13:34 +02:00
type ClientType string
const (
ClientPublic ClientType = "public"
2022-09-28 09:01:17 +02:00
ClientShare ClientType = "share"
2022-07-05 23:13:34 +02:00
ClientUser ClientType = "user"
)
2020-12-18 20:42:12 +01:00
// ClientConfig represents HTTP client / Web UI config options.
2020-05-27 19:38:40 +02:00
type ClientConfig struct {
2022-11-22 22:14:34 +01:00
Mode string ` json:"mode" `
Name string ` json:"name" `
About string ` json:"about" `
Edition string ` json:"edition" `
Version string ` json:"version" `
Copyright string ` json:"copyright" `
Flags string ` json:"flags" `
BaseUri string ` json:"baseUri" `
StaticUri string ` json:"staticUri" `
CssUri string ` json:"cssUri" `
JsUri string ` json:"jsUri" `
ManifestUri string ` json:"manifestUri" `
ApiUri string ` json:"apiUri" `
ContentUri string ` json:"contentUri" `
WallpaperUri string ` json:"wallpaperUri" `
SiteUrl string ` json:"siteUrl" `
SiteDomain string ` json:"siteDomain" `
SiteAuthor string ` json:"siteAuthor" `
SiteTitle string ` json:"siteTitle" `
SiteCaption string ` json:"siteCaption" `
SiteDescription string ` json:"siteDescription" `
SitePreview string ` json:"sitePreview" `
LegalInfo string ` json:"legalInfo" `
LegalUrl string ` json:"legalUrl" `
AppName string ` json:"appName" `
AppMode string ` json:"appMode" `
AppIcon string ` json:"appIcon" `
2023-02-10 15:53:01 +01:00
AppColor string ` json:"appColor" `
2022-11-22 22:14:34 +01:00
Debug bool ` json:"debug" `
Trace bool ` json:"trace" `
Test bool ` json:"test" `
Demo bool ` json:"demo" `
Sponsor bool ` json:"sponsor" `
ReadOnly bool ` json:"readonly" `
UploadNSFW bool ` json:"uploadNSFW" `
Public bool ` json:"public" `
AuthMode string ` json:"authMode" `
LoginUri string ` json:"loginUri" `
RegisterUri string ` json:"registerUri" `
PasswordLength int ` json:"passwordLength" `
PasswordResetUri string ` json:"passwordResetUri" `
Experimental bool ` json:"experimental" `
AlbumCategories [ ] string ` json:"albumCategories" `
Albums entity . Albums ` json:"albums" `
Cameras entity . Cameras ` json:"cameras" `
Lenses entity . Lenses ` json:"lenses" `
Countries entity . Countries ` json:"countries" `
People entity . People ` json:"people" `
Thumbs ThumbSizes ` json:"thumbs" `
2023-02-21 00:02:44 +01:00
License string ` json:"license" `
2022-11-27 18:00:55 +01:00
Customer string ` json:"customer" `
2022-11-22 22:14:34 +01:00
MapKey string ` json:"mapKey" `
DownloadToken string ` json:"downloadToken,omitempty" `
PreviewToken string ` json:"previewToken,omitempty" `
Disable ClientDisable ` json:"disable" `
Count ClientCounts ` json:"count" `
Pos ClientPosition ` json:"pos" `
Years Years ` json:"years" `
Colors [ ] map [ string ] string ` json:"colors" `
Categories CategoryLabels ` json:"categories" `
Clip int ` json:"clip" `
Server env . Resources ` json:"server" `
Settings * customize . Settings ` json:"settings,omitempty" `
ACL acl . Grants ` json:"acl,omitempty" `
Ext Values ` json:"ext" `
2020-05-27 19:38:40 +02:00
}
2022-09-30 00:42:19 +02:00
// ApplyACL updates the client config values based on the ACL and Role provided.
func ( c ClientConfig ) ApplyACL ( a acl . ACL , r acl . Role ) ClientConfig {
if c . Settings != nil {
c . Settings = c . Settings . ApplyACL ( a , r )
}
c . ACL = a . Grants ( r )
return c
}
2021-09-02 14:45:26 +02:00
// Years represents a list of years.
type Years [ ] int
2022-01-05 11:40:44 +01:00
// ClientDisable represents disabled client features a user cannot turn back on.
2020-12-18 09:11:42 +01:00
type ClientDisable struct {
2021-09-24 01:53:42 +02:00
WebDAV bool ` json:"webdav" `
Settings bool ` json:"settings" `
Places bool ` json:"places" `
2023-02-19 16:42:19 +01:00
Backups bool ` json:"backups" `
TensorFlow bool ` json:"tensorflow" `
Faces bool ` json:"faces" `
Classification bool ` json:"classification" `
Sips bool ` json:"sips" `
2021-09-24 03:00:37 +02:00
FFmpeg bool ` json:"ffmpeg" `
2023-02-19 16:42:19 +01:00
ExifTool bool ` json:"exiftool" `
2021-09-24 01:53:42 +02:00
Darktable bool ` json:"darktable" `
2023-02-11 20:18:04 +01:00
RawTherapee bool ` json:"rawtherapee" `
2023-02-19 16:42:19 +01:00
ImageMagick bool ` json:"imagemagick" `
2021-09-24 01:53:42 +02:00
HeifConvert bool ` json:"heifconvert" `
2023-02-19 16:42:19 +01:00
Vectors bool ` json:"vectors" `
JpegXL bool ` json:"jpegxl" `
Raw bool ` json:"raw" `
2020-12-18 09:11:42 +01:00
}
// ClientCounts represents photo, video and album counts for the client UI.
2020-05-27 19:38:40 +02:00
type ClientCounts struct {
2021-01-11 14:06:48 +01:00
All int ` json:"all" `
Photos int ` json:"photos" `
2021-11-30 12:37:43 +01:00
Live int ` json:"live" `
2021-01-11 14:06:48 +01:00
Videos int ` json:"videos" `
2020-05-30 01:41:47 +02:00
Cameras int ` json:"cameras" `
Lenses int ` json:"lenses" `
Countries int ` json:"countries" `
Hidden int ` json:"hidden" `
Favorites int ` json:"favorites" `
Review int ` json:"review" `
Stories int ` json:"stories" `
2023-02-21 00:02:44 +01:00
Private int ` json:"private" `
2020-05-30 01:41:47 +02:00
Albums int ` json:"albums" `
2023-02-21 00:02:44 +01:00
PrivateAlbums int ` json:"private_albums" `
2020-05-30 01:41:47 +02:00
Moments int ` json:"moments" `
2023-02-21 00:02:44 +01:00
PrivateMoments int ` json:"private_moments" `
2020-05-30 01:41:47 +02:00
Months int ` json:"months" `
2023-02-21 00:02:44 +01:00
PrivateMonths int ` json:"private_months" `
States int ` json:"states" `
PrivateStates int ` json:"private_states" `
2020-05-30 01:41:47 +02:00
Folders int ` json:"folders" `
2023-02-21 00:02:44 +01:00
PrivateFolders int ` json:"private_folders" `
2020-05-30 01:41:47 +02:00
Files int ` json:"files" `
2021-08-11 21:42:31 +02:00
People int ` json:"people" `
2020-05-30 01:41:47 +02:00
Places int ` json:"places" `
Labels int ` json:"labels" `
LabelMaxPhotos int ` json:"labelMaxPhotos" `
2020-05-27 19:38:40 +02:00
}
2021-09-02 14:45:26 +02:00
type CategoryLabels [ ] CategoryLabel
2020-05-27 19:38:40 +02:00
type CategoryLabel struct {
LabelUID string ` json:"UID" `
CustomSlug string ` json:"Slug" `
LabelName string ` json:"Name" `
}
type ClientPosition struct {
2020-07-11 23:43:29 +02:00
PhotoUID string ` json:"uid" `
2020-07-12 08:27:05 +02:00
CellID string ` json:"cid" `
2020-07-11 23:43:29 +02:00
TakenAt time . Time ` json:"utc" `
PhotoLat float64 ` json:"lat" `
PhotoLng float64 ` json:"lng" `
2020-05-27 19:38:40 +02:00
}
2020-01-02 00:03:07 +01:00
2020-04-12 18:00:31 +02:00
// Flags returns config flags as string slice.
func ( c * Config ) Flags ( ) ( flags [ ] string ) {
2020-01-22 16:54:01 +01:00
if c . Public ( ) {
flags = append ( flags , "public" )
}
2020-04-12 18:00:31 +02:00
2020-01-22 16:54:01 +01:00
if c . Debug ( ) {
flags = append ( flags , "debug" )
}
2020-04-12 18:00:31 +02:00
2022-03-16 17:34:09 +01:00
if c . Test ( ) {
flags = append ( flags , "test" )
}
if c . Demo ( ) {
flags = append ( flags , "demo" )
}
2021-11-18 00:46:34 +01:00
if c . Sponsor ( ) {
flags = append ( flags , "sponsor" )
}
2020-01-22 16:54:01 +01:00
if c . Experimental ( ) {
flags = append ( flags , "experimental" )
}
2020-04-12 18:00:31 +02:00
2020-01-22 16:54:01 +01:00
if c . ReadOnly ( ) {
flags = append ( flags , "readonly" )
}
2020-12-18 09:11:42 +01:00
if ! c . DisableSettings ( ) {
2020-04-12 18:00:31 +02:00
flags = append ( flags , "settings" )
}
2020-12-13 14:53:26 +01:00
if ! c . Settings ( ) . UI . Scrollbar {
flags = append ( flags , "hide-scrollbar" )
}
2020-04-12 18:00:31 +02:00
return flags
}
2022-09-28 09:01:17 +02:00
// ClientPublic returns config values for use by the JavaScript UI and other clients.
func ( c * Config ) ClientPublic ( ) ClientConfig {
2020-04-12 18:00:31 +02:00
if c . Public ( ) {
2022-09-30 00:42:19 +02:00
return c . ClientUser ( true ) . ApplyACL ( acl . Resources , acl . RoleAdmin )
2020-04-12 18:00:31 +02:00
}
2022-09-28 09:01:17 +02:00
a := c . ClientAssets ( )
2020-01-22 16:54:01 +01:00
2022-09-28 09:01:17 +02:00
cfg := ClientConfig {
Settings : c . PublicSettings ( ) ,
2022-10-13 22:11:02 +02:00
ACL : acl . Resources . Grants ( acl . RoleUnknown ) ,
2020-12-18 09:11:42 +01:00
Disable : ClientDisable {
2021-09-24 03:00:37 +02:00
WebDAV : true ,
Settings : c . DisableSettings ( ) ,
Places : c . DisablePlaces ( ) ,
2023-02-19 16:42:19 +01:00
Backups : true ,
TensorFlow : true ,
Faces : true ,
Classification : true ,
Sips : true ,
2021-09-24 03:00:37 +02:00
FFmpeg : true ,
2023-02-19 16:42:19 +01:00
ExifTool : true ,
2021-09-24 03:00:37 +02:00
Darktable : true ,
2023-02-11 20:18:04 +01:00
RawTherapee : true ,
2023-02-19 16:42:19 +01:00
ImageMagick : true ,
2021-09-24 03:00:37 +02:00
HeifConvert : true ,
2023-02-19 16:42:19 +01:00
Vectors : c . DisableVectors ( ) ,
JpegXL : true ,
Raw : true ,
2020-12-18 09:11:42 +01:00
} ,
2022-11-22 22:14:34 +01:00
Flags : strings . Join ( c . Flags ( ) , " " ) ,
Mode : string ( ClientPublic ) ,
Name : c . Name ( ) ,
2023-02-21 00:02:44 +01:00
About : c . About ( ) ,
Edition : c . Edition ( ) ,
2022-11-22 22:14:34 +01:00
BaseUri : c . BaseUri ( "" ) ,
StaticUri : c . StaticUri ( ) ,
CssUri : a . AppCssUri ( ) ,
JsUri : a . AppJsUri ( ) ,
ApiUri : c . ApiUri ( ) ,
ContentUri : c . ContentUri ( ) ,
SiteUrl : c . SiteUrl ( ) ,
SiteDomain : c . SiteDomain ( ) ,
SiteAuthor : c . SiteAuthor ( ) ,
SiteTitle : c . SiteTitle ( ) ,
SiteCaption : c . SiteCaption ( ) ,
SiteDescription : c . SiteDescription ( ) ,
SitePreview : c . SitePreview ( ) ,
LegalInfo : c . LegalInfo ( ) ,
LegalUrl : c . LegalUrl ( ) ,
AppName : c . AppName ( ) ,
AppMode : c . AppMode ( ) ,
AppIcon : c . AppIcon ( ) ,
2023-02-10 15:53:01 +01:00
AppColor : c . AppColor ( ) ,
2022-11-22 22:14:34 +01:00
WallpaperUri : c . WallpaperUri ( ) ,
Version : c . Version ( ) ,
Copyright : c . Copyright ( ) ,
Debug : c . Debug ( ) ,
Trace : c . Trace ( ) ,
Test : c . Test ( ) ,
Demo : c . Demo ( ) ,
Sponsor : c . Sponsor ( ) ,
ReadOnly : c . ReadOnly ( ) ,
Public : c . Public ( ) ,
AuthMode : c . AuthMode ( ) ,
LoginUri : c . LoginUri ( ) ,
RegisterUri : c . RegisterUri ( ) ,
PasswordResetUri : c . PasswordResetUri ( ) ,
Experimental : c . Experimental ( ) ,
Albums : entity . Albums { } ,
Cameras : entity . Cameras { } ,
Lenses : entity . Lenses { } ,
Countries : entity . Countries { } ,
People : entity . People { } ,
2023-02-21 00:02:44 +01:00
License : c . Hub ( ) . Status ,
Customer : "" ,
2022-11-22 22:14:34 +01:00
MapKey : "" ,
Thumbs : Thumbs ,
Colors : colors . All . List ( ) ,
ManifestUri : c . ClientManifestUri ( ) ,
Clip : txt . ClipDefault ,
PreviewToken : entity . TokenPublic ,
DownloadToken : entity . TokenPublic ,
Ext : ClientExt ( c , ClientPublic ) ,
2020-01-22 16:54:01 +01:00
}
2022-09-28 09:01:17 +02:00
return cfg
2020-01-22 16:54:01 +01:00
}
2022-09-28 09:01:17 +02:00
// ClientShare returns reduced client config values for share link visitors.
func ( c * Config ) ClientShare ( ) ClientConfig {
a := c . ClientAssets ( )
cfg := ClientConfig {
Settings : c . ShareSettings ( ) ,
ACL : acl . Resources . Grants ( acl . RoleVisitor ) ,
2020-12-18 09:11:42 +01:00
Disable : ClientDisable {
2021-09-24 03:00:37 +02:00
WebDAV : c . DisableWebDAV ( ) ,
Settings : c . DisableSettings ( ) ,
Places : c . DisablePlaces ( ) ,
2023-02-19 16:42:19 +01:00
Backups : true ,
TensorFlow : true ,
Faces : c . DisableFaces ( ) ,
Classification : c . DisableClassification ( ) ,
Sips : true ,
2021-09-24 03:00:37 +02:00
FFmpeg : true ,
2023-02-19 16:42:19 +01:00
ExifTool : true ,
2021-09-24 03:00:37 +02:00
Darktable : true ,
2023-02-11 20:18:04 +01:00
RawTherapee : true ,
2023-02-19 16:42:19 +01:00
ImageMagick : true ,
2021-09-24 03:00:37 +02:00
HeifConvert : true ,
2023-02-19 16:42:19 +01:00
Vectors : c . DisableVectors ( ) ,
JpegXL : c . DisableJpegXL ( ) ,
Raw : c . DisableRaw ( ) ,
2020-12-18 09:11:42 +01:00
} ,
2022-11-22 22:14:34 +01:00
Flags : strings . Join ( c . Flags ( ) , " " ) ,
Mode : string ( ClientShare ) ,
Name : c . Name ( ) ,
2023-02-21 00:02:44 +01:00
About : c . About ( ) ,
Edition : c . Edition ( ) ,
2022-11-22 22:14:34 +01:00
BaseUri : c . BaseUri ( "" ) ,
StaticUri : c . StaticUri ( ) ,
CssUri : a . AppCssUri ( ) ,
JsUri : a . ShareJsUri ( ) ,
ApiUri : c . ApiUri ( ) ,
ContentUri : c . ContentUri ( ) ,
SiteUrl : c . SiteUrl ( ) ,
SiteDomain : c . SiteDomain ( ) ,
SiteAuthor : c . SiteAuthor ( ) ,
SiteTitle : c . SiteTitle ( ) ,
SiteCaption : c . SiteCaption ( ) ,
SiteDescription : c . SiteDescription ( ) ,
SitePreview : c . SitePreview ( ) ,
LegalInfo : c . LegalInfo ( ) ,
LegalUrl : c . LegalUrl ( ) ,
AppName : c . AppName ( ) ,
AppMode : c . AppMode ( ) ,
AppIcon : c . AppIcon ( ) ,
2023-02-10 15:53:01 +01:00
AppColor : c . AppColor ( ) ,
2022-11-22 22:14:34 +01:00
WallpaperUri : c . WallpaperUri ( ) ,
Version : c . Version ( ) ,
Copyright : c . Copyright ( ) ,
Debug : c . Debug ( ) ,
Trace : c . Trace ( ) ,
Test : c . Test ( ) ,
Demo : c . Demo ( ) ,
Sponsor : c . Sponsor ( ) ,
ReadOnly : c . ReadOnly ( ) ,
UploadNSFW : c . UploadNSFW ( ) ,
Public : c . Public ( ) ,
AuthMode : c . AuthMode ( ) ,
LoginUri : c . LoginUri ( ) ,
RegisterUri : c . RegisterUri ( ) ,
PasswordResetUri : c . PasswordResetUri ( ) ,
Experimental : c . Experimental ( ) ,
Albums : entity . Albums { } ,
Cameras : entity . Cameras { } ,
Lenses : entity . Lenses { } ,
Countries : entity . Countries { } ,
People : entity . People { } ,
Colors : colors . All . List ( ) ,
Thumbs : Thumbs ,
2023-02-21 00:02:44 +01:00
License : c . Hub ( ) . Status ,
2022-11-27 18:00:55 +01:00
Customer : c . Hub ( ) . Customer ( ) ,
2023-02-21 00:02:44 +01:00
MapKey : c . Hub ( ) . MapKey ( ) ,
2022-11-22 22:14:34 +01:00
DownloadToken : c . DownloadToken ( ) ,
PreviewToken : c . PreviewToken ( ) ,
ManifestUri : c . ClientManifestUri ( ) ,
Clip : txt . ClipDefault ,
Ext : ClientExt ( c , ClientShare ) ,
2020-06-22 20:15:08 +02:00
}
2022-09-28 09:01:17 +02:00
return cfg
2020-06-22 20:15:08 +02:00
}
2022-09-28 09:01:17 +02:00
// ClientUser returns complete client config values for users with full access.
func ( c * Config ) ClientUser ( withSettings bool ) ClientConfig {
a := c . ClientAssets ( )
var s * customize . Settings
if withSettings {
s = c . Settings ( )
}
2022-01-18 12:26:33 +01:00
2022-09-28 09:01:17 +02:00
cfg := ClientConfig {
Settings : s ,
2020-12-18 09:11:42 +01:00
Disable : ClientDisable {
2021-09-24 01:53:42 +02:00
WebDAV : c . DisableWebDAV ( ) ,
Settings : c . DisableSettings ( ) ,
Places : c . DisablePlaces ( ) ,
2023-02-19 16:42:19 +01:00
Backups : c . DisableBackups ( ) ,
TensorFlow : c . DisableTensorFlow ( ) ,
Faces : c . DisableFaces ( ) ,
Classification : c . DisableClassification ( ) ,
Sips : c . DisableSips ( ) ,
2021-09-24 03:00:37 +02:00
FFmpeg : c . DisableFFmpeg ( ) ,
2023-02-19 16:42:19 +01:00
ExifTool : c . DisableExifTool ( ) ,
2021-09-24 01:53:42 +02:00
Darktable : c . DisableDarktable ( ) ,
2023-02-11 20:18:04 +01:00
RawTherapee : c . DisableRawTherapee ( ) ,
2023-02-19 16:42:19 +01:00
ImageMagick : c . DisableImageMagick ( ) ,
2021-09-24 01:53:42 +02:00
HeifConvert : c . DisableHeifConvert ( ) ,
2023-02-19 16:42:19 +01:00
Vectors : c . DisableVectors ( ) ,
JpegXL : c . DisableJpegXL ( ) ,
Raw : c . DisableRaw ( ) ,
2020-12-18 09:11:42 +01:00
} ,
2022-11-22 22:14:34 +01:00
Flags : strings . Join ( c . Flags ( ) , " " ) ,
Mode : string ( ClientUser ) ,
Name : c . Name ( ) ,
2023-02-21 00:02:44 +01:00
About : c . About ( ) ,
Edition : c . Edition ( ) ,
2022-11-22 22:14:34 +01:00
BaseUri : c . BaseUri ( "" ) ,
StaticUri : c . StaticUri ( ) ,
CssUri : a . AppCssUri ( ) ,
JsUri : a . AppJsUri ( ) ,
ApiUri : c . ApiUri ( ) ,
ContentUri : c . ContentUri ( ) ,
SiteUrl : c . SiteUrl ( ) ,
SiteDomain : c . SiteDomain ( ) ,
SiteAuthor : c . SiteAuthor ( ) ,
SiteTitle : c . SiteTitle ( ) ,
SiteCaption : c . SiteCaption ( ) ,
SiteDescription : c . SiteDescription ( ) ,
SitePreview : c . SitePreview ( ) ,
LegalInfo : c . LegalInfo ( ) ,
LegalUrl : c . LegalUrl ( ) ,
AppName : c . AppName ( ) ,
AppMode : c . AppMode ( ) ,
AppIcon : c . AppIcon ( ) ,
2023-02-10 15:53:01 +01:00
AppColor : c . AppColor ( ) ,
2022-11-22 22:14:34 +01:00
WallpaperUri : c . WallpaperUri ( ) ,
Version : c . Version ( ) ,
Copyright : c . Copyright ( ) ,
Debug : c . Debug ( ) ,
Trace : c . Trace ( ) ,
Test : c . Test ( ) ,
Demo : c . Demo ( ) ,
Sponsor : c . Sponsor ( ) ,
ReadOnly : c . ReadOnly ( ) ,
UploadNSFW : c . UploadNSFW ( ) ,
Public : c . Public ( ) ,
AuthMode : c . AuthMode ( ) ,
LoginUri : c . LoginUri ( ) ,
RegisterUri : c . RegisterUri ( ) ,
PasswordLength : c . PasswordLength ( ) ,
PasswordResetUri : c . PasswordResetUri ( ) ,
Experimental : c . Experimental ( ) ,
Albums : entity . Albums { } ,
Cameras : entity . Cameras { } ,
Lenses : entity . Lenses { } ,
Countries : entity . Countries { } ,
People : entity . People { } ,
Colors : colors . All . List ( ) ,
Thumbs : Thumbs ,
2023-02-21 00:02:44 +01:00
License : c . Hub ( ) . Status ,
2022-11-27 18:00:55 +01:00
Customer : c . Hub ( ) . Customer ( ) ,
2023-02-21 00:02:44 +01:00
MapKey : c . Hub ( ) . MapKey ( ) ,
2022-11-22 22:14:34 +01:00
DownloadToken : c . DownloadToken ( ) ,
PreviewToken : c . PreviewToken ( ) ,
ManifestUri : c . ClientManifestUri ( ) ,
Clip : txt . ClipDefault ,
Server : env . Info ( ) ,
Ext : ClientExt ( c , ClientUser ) ,
2020-01-02 00:03:07 +01:00
}
2022-09-28 09:01:17 +02:00
hidePrivate := c . Settings ( ) . Features . Private
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "photos" ) .
2020-07-12 08:27:05 +02:00
Select ( "photo_uid, cell_id, photo_lat, photo_lng, taken_at" ) .
2021-08-11 21:42:31 +02:00
Where ( "deleted_at IS NULL AND photo_lat <> 0 AND photo_lng <> 0" ) .
2020-01-02 00:03:07 +01:00
Order ( "taken_at DESC" ) .
Limit ( 1 ) . Offset ( 0 ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Pos )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "cameras" ) .
2020-05-29 18:04:30 +02:00
Where ( "camera_slug <> 'zz' AND camera_slug <> ''" ) .
Select ( "COUNT(*) AS cameras" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2020-05-29 18:04:30 +02:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "lenses" ) .
2020-05-29 18:04:30 +02:00
Where ( "lens_slug <> 'zz' AND lens_slug <> ''" ) .
Select ( "COUNT(*) AS lenses" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2020-01-02 00:03:07 +01:00
2022-09-28 09:01:17 +02:00
if hidePrivate {
2022-08-01 15:57:19 +02:00
c . Db ( ) .
Table ( "photos" ) .
Select ( "SUM(photo_type = 'video' AND photo_quality > -1 AND photo_private = 0) AS videos, " +
"SUM(photo_type = 'live' AND photo_quality > -1 AND photo_private = 0) AS live, " +
2023-02-11 20:18:04 +01:00
"SUM(photo_quality = -1) AS hidden, SUM(photo_type IN ('image','animated','vector','raw') AND photo_private = 0 AND photo_quality > -1) AS photos, " +
"SUM(photo_type IN ('image','live','animated','vector','raw') AND photo_quality < 3 AND photo_quality > -1 AND photo_private = 0) AS review, " +
2022-08-01 15:57:19 +02:00
"SUM(photo_favorite = 1 AND photo_private = 0 AND photo_quality > -1) AS favorites, " +
"SUM(photo_private = 1 AND photo_quality > -1) AS private" ) .
Where ( "photos.id NOT IN (SELECT photo_id FROM files WHERE file_primary = 1 AND (file_missing = 1 OR file_error <> ''))" ) .
Where ( "deleted_at IS NULL" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2022-08-01 15:57:19 +02:00
} else {
c . Db ( ) .
Table ( "photos" ) .
Select ( "SUM(photo_type = 'video' AND photo_quality > -1) AS videos, " +
"SUM(photo_type = 'live' AND photo_quality > -1) AS live, " +
"SUM(photo_quality = -1) AS hidden, SUM(photo_type IN ('image','raw','animated') AND photo_quality > -1) AS photos, " +
"SUM(photo_type IN ('image','raw','live','animated') AND photo_quality < 3 AND photo_quality > -1) AS review, " +
"SUM(photo_favorite = 1 AND photo_quality > -1) AS favorites, " +
"0 AS private" ) .
Where ( "photos.id NOT IN (SELECT photo_id FROM files WHERE file_primary = 1 AND (file_missing = 1 OR file_error <> ''))" ) .
Where ( "deleted_at IS NULL" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2022-08-01 15:57:19 +02:00
}
2020-01-02 00:03:07 +01:00
2023-02-03 08:23:46 +01:00
// Calculate total count.
2022-09-28 09:01:17 +02:00
cfg . Count . All = cfg . Count . Photos + cfg . Count . Live + cfg . Count . Videos
2021-01-11 14:06:48 +01:00
2023-02-03 08:23:46 +01:00
// Exclude pictures in review from total count.
if c . Settings ( ) . Features . Review {
cfg . Count . All = cfg . Count . All - cfg . Count . Review
}
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "labels" ) .
2021-10-01 19:23:08 +02:00
Select ( "MAX(photo_count) AS label_max_photos, COUNT(*) AS labels" ) .
2020-05-10 19:43:49 +02:00
Where ( "photo_count > 0" ) .
Where ( "deleted_at IS NULL" ) .
2020-06-01 09:45:24 +02:00
Where ( "(label_priority >= 0 OR label_favorite = 1)" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2020-01-02 00:03:07 +01:00
2022-09-28 09:01:17 +02:00
if hidePrivate {
2022-08-31 17:42:57 +02:00
c . Db ( ) .
Table ( "albums" ) .
2023-02-21 00:02:44 +01:00
Select ( "SUM(album_type = ?) AS albums, SUM(album_type = ?) AS moments, SUM(album_type = ?) AS months, SUM(album_type = ?) AS states, SUM(album_type = ?) AS folders, " +
"SUM(album_type = ? AND album_private = 1) AS private_albums, SUM(album_type = ? AND album_private = 1) AS private_moments, SUM(album_type = ? AND album_private = 1) AS private_months, SUM(album_type = ? AND album_private = 1) AS private_states, SUM(album_type = ? AND album_private = 1) AS private_folders" ,
entity . AlbumDefault , entity . AlbumMoment , entity . AlbumMonth , entity . AlbumState , entity . AlbumFolder , entity . AlbumDefault , entity . AlbumMoment , entity . AlbumMonth , entity . AlbumState , entity . AlbumFolder ) .
2022-08-31 17:42:57 +02:00
Where ( "deleted_at IS NULL AND (albums.album_type <> 'folder' OR albums.album_path IN (SELECT photos.photo_path FROM photos WHERE photos.photo_private = 0 AND photos.deleted_at IS NULL))" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2022-08-31 17:42:57 +02:00
} else {
c . Db ( ) .
Table ( "albums" ) .
Select ( "SUM(album_type = ?) AS albums, SUM(album_type = ?) AS moments, SUM(album_type = ?) AS months, SUM(album_type = ?) AS states, SUM(album_type = ?) AS folders" , entity . AlbumDefault , entity . AlbumMoment , entity . AlbumMonth , entity . AlbumState , entity . AlbumFolder ) .
Where ( "deleted_at IS NULL AND (albums.album_type <> 'folder' OR albums.album_path IN (SELECT photos.photo_path FROM photos WHERE photos.deleted_at IS NULL))" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2022-08-31 17:42:57 +02:00
}
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "files" ) .
2022-04-21 22:17:26 +02:00
Select ( "COUNT(*) AS files" ) .
2023-02-20 18:50:28 +01:00
Where ( "file_missing = 0 AND file_root = ? AND deleted_at IS NULL" , entity . RootOriginals ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2020-05-24 22:16:06 +02:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "countries" ) .
2020-01-02 00:03:07 +01:00
Select ( "(COUNT(*) - 1) AS countries" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "places" ) .
2020-05-10 16:12:15 +02:00
Select ( "SUM(photo_count > 0) AS places" ) .
2021-08-11 21:42:31 +02:00
Where ( "id <> 'zz'" ) .
2022-09-28 09:01:17 +02:00
Take ( & cfg . Count )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Order ( "country_slug" ) .
2022-09-28 09:01:17 +02:00
Find ( & cfg . Countries )
2020-01-02 00:03:07 +01:00
2021-09-03 16:14:09 +02:00
// People are subjects with type person.
2022-09-28 09:01:17 +02:00
cfg . Count . People , _ = query . PeopleCount ( )
cfg . People , _ = query . People ( )
2021-09-02 16:12:31 +02:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
2022-04-15 09:42:07 +02:00
Where ( "id IN (SELECT photos.camera_id FROM photos WHERE photos.photo_quality > -1 OR photos.deleted_at IS NULL)" ) .
2020-12-15 20:14:06 +01:00
Where ( "deleted_at IS NULL" ) .
2020-04-25 14:22:47 +02:00
Limit ( 10000 ) . Order ( "camera_slug" ) .
2022-09-28 09:01:17 +02:00
Find ( & cfg . Cameras )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Where ( "deleted_at IS NULL" ) .
2020-04-25 14:22:47 +02:00
Limit ( 10000 ) . Order ( "lens_slug" ) .
2022-09-28 09:01:17 +02:00
Find ( & cfg . Lenses )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Where ( "deleted_at IS NULL AND album_favorite = 1" ) .
2020-05-26 09:02:19 +02:00
Limit ( 20 ) . Order ( "album_title" ) .
2022-09-28 09:01:17 +02:00
Find ( & cfg . Albums )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "photos" ) .
2022-04-15 09:42:07 +02:00
Where ( "photo_year > 0 AND (photos.photo_quality > -1 OR photos.deleted_at IS NULL)" ) .
2020-01-02 00:03:07 +01:00
Order ( "photo_year DESC" ) .
2022-09-28 09:01:17 +02:00
Pluck ( "DISTINCT photo_year" , & cfg . Years )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "categories" ) .
2020-05-23 20:58:58 +02:00
Select ( "l.label_uid, l.custom_slug, l.label_name" ) .
2020-01-02 00:03:07 +01:00
Joins ( "JOIN labels l ON categories.category_id = l.id" ) .
2020-05-23 20:58:58 +02:00
Where ( "l.deleted_at IS NULL" ) .
Group ( "l.custom_slug" ) .
Order ( "l.custom_slug" ) .
2020-01-02 00:03:07 +01:00
Limit ( 1000 ) . Offset ( 0 ) .
2022-09-28 09:01:17 +02:00
Scan ( & cfg . Categories )
2020-01-02 00:03:07 +01:00
2020-12-15 20:14:06 +01:00
c . Db ( ) .
Table ( "albums" ) .
2020-05-30 21:11:56 +02:00
Select ( "album_category" ) .
Where ( "deleted_at IS NULL AND album_category <> ''" ) .
Group ( "album_category" ) .
Order ( "album_category" ) .
Limit ( 1000 ) . Offset ( 0 ) .
2022-09-28 09:01:17 +02:00
Pluck ( "album_category" , & cfg . AlbumCategories )
return cfg
}
// ClientRole provides the client config values for the specified user role.
func ( c * Config ) ClientRole ( role acl . Role ) ClientConfig {
2022-09-30 00:42:19 +02:00
return c . ClientUser ( true ) . ApplyACL ( acl . Resources , role )
2022-09-28 09:01:17 +02:00
}
// ClientSession provides the client config values for the specified session.
2022-10-13 22:11:02 +02:00
func ( c * Config ) ClientSession ( sess * entity . Session ) ( cfg ClientConfig ) {
if sess . User ( ) . IsVisitor ( ) {
cfg = c . ClientShare ( )
} else if sess . User ( ) . IsRegistered ( ) {
cfg = c . ClientUser ( false ) . ApplyACL ( acl . Resources , sess . User ( ) . AclRole ( ) )
cfg . Settings = c . SessionSettings ( sess )
} else {
cfg = c . ClientPublic ( )
}
if c . Public ( ) {
cfg . PreviewToken = entity . TokenPublic
cfg . DownloadToken = entity . TokenPublic
} else if sess . PreviewToken != "" || sess . DownloadToken != "" {
cfg . PreviewToken = sess . PreviewToken
cfg . DownloadToken = sess . DownloadToken
}
2020-05-30 21:11:56 +02:00
2022-10-13 22:11:02 +02:00
return cfg
2020-01-02 00:03:07 +01:00
}