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 {
2021-09-03 16:14:09 +02:00
Mode string ` json:"mode" `
Name string ` json:"name" `
2022-05-20 19:27:33 +02:00
Edition string ` json:"edition" `
2021-09-03 16:14:09 +02:00
Version string ` json:"version" `
Copyright string ` json:"copyright" `
Flags string ` json:"flags" `
BaseUri string ` json:"baseUri" `
StaticUri string ` json:"staticUri" `
2022-01-18 12:26:33 +01:00
CssUri string ` json:"cssUri" `
JsUri string ` json:"jsUri" `
ManifestUri string ` json:"manifestUri" `
2021-09-03 16:14:09 +02:00
ApiUri string ` json:"apiUri" `
ContentUri string ` json:"contentUri" `
2022-04-22 17:38:40 +02:00
WallpaperUri string ` json:"wallpaperUri" `
2021-09-03 16:14:09 +02:00
SiteUrl string ` json:"siteUrl" `
2021-12-14 15:47:30 +01:00
SiteDomain string ` json:"siteDomain" `
2021-11-21 16:36:42 +01:00
SiteAuthor string ` json:"siteAuthor" `
2021-09-03 16:14:09 +02:00
SiteTitle string ` json:"siteTitle" `
SiteCaption string ` json:"siteCaption" `
SiteDescription string ` json:"siteDescription" `
2021-11-21 16:36:42 +01:00
SitePreview string ` json:"sitePreview" `
2022-02-08 14:41:03 +01:00
Imprint string ` json:"imprint" `
ImprintUrl string ` json:"imprintUrl" `
2021-11-21 16:36:42 +01:00
AppName string ` json:"appName" `
AppMode string ` json:"appMode" `
AppIcon string ` json:"appIcon" `
2021-09-03 16:14:09 +02:00
Debug bool ` json:"debug" `
2022-04-12 19:14:21 +02:00
Trace bool ` json:"trace" `
2021-09-03 16:14:09 +02:00
Test bool ` json:"test" `
Demo bool ` json:"demo" `
Sponsor bool ` json:"sponsor" `
ReadOnly bool ` json:"readonly" `
UploadNSFW bool ` json:"uploadNSFW" `
Public bool ` json:"public" `
2022-10-12 18:11:20 +02:00
AuthMode string ` json:"authMode" `
2021-09-03 16:14:09 +02:00
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" `
2021-09-05 12:32:08 +02:00
Thumbs ThumbSizes ` json:"thumbs" `
2021-09-03 16:14:09 +02:00
Status string ` json:"status" `
MapKey string ` json:"mapKey" `
DownloadToken string ` json:"downloadToken" `
PreviewToken string ` json:"previewToken" `
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" `
2022-04-15 09:42:07 +02:00
Server env . Resources ` json:"server" `
2022-09-28 09:01:17 +02:00
Settings * customize . Settings ` json:"settings,omitempty" `
ACL acl . Grants ` json:"acl,omitempty" `
2022-07-05 23:13:34 +02:00
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
Backups bool ` json:"backups" `
WebDAV bool ` json:"webdav" `
Settings bool ` json:"settings" `
Places bool ` json:"places" `
ExifTool bool ` json:"exiftool" `
2021-09-24 03:00:37 +02:00
FFmpeg bool ` json:"ffmpeg" `
2022-04-06 17:46:41 +02:00
Raw bool ` json:"raw" `
2021-09-24 01:53:42 +02:00
Darktable bool ` json:"darktable" `
Rawtherapee bool ` json:"rawtherapee" `
Sips bool ` json:"sips" `
HeifConvert bool ` json:"heifconvert" `
2021-09-24 03:00:37 +02:00
TensorFlow bool ` json:"tensorflow" `
Faces bool ` json:"faces" `
Classification bool ` json:"classification" `
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" `
Private int ` json:"private" `
Review int ` json:"review" `
Stories int ` json:"stories" `
Albums int ` json:"albums" `
Moments int ` json:"moments" `
Months int ` json:"months" `
Folders int ` json:"folders" `
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" `
2020-06-08 18:32:51 +02:00
States int ` json:"states" `
2020-05-30 01:41:47 +02:00
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 ( ) ,
ACL : acl . Resources . Grants ( acl . RoleUnauthorized ) ,
2020-12-18 09:11:42 +01:00
Disable : ClientDisable {
2021-09-24 03:00:37 +02:00
Backups : true ,
WebDAV : true ,
Settings : c . DisableSettings ( ) ,
Places : c . DisablePlaces ( ) ,
ExifTool : true ,
FFmpeg : true ,
2022-04-06 17:46:41 +02:00
Raw : true ,
2021-09-24 03:00:37 +02:00
Darktable : true ,
Rawtherapee : true ,
Sips : true ,
HeifConvert : true ,
TensorFlow : true ,
Faces : true ,
Classification : true ,
2020-12-18 09:11:42 +01:00
} ,
2020-05-31 02:09:52 +02:00
Flags : strings . Join ( c . Flags ( ) , " " ) ,
2022-09-28 09:01:17 +02:00
Mode : string ( ClientPublic ) ,
2020-05-31 02:09:52 +02:00
Name : c . Name ( ) ,
2022-05-20 19:27:33 +02:00
Edition : c . Edition ( ) ,
2021-07-05 16:41:43 +02:00
BaseUri : c . BaseUri ( "" ) ,
StaticUri : c . StaticUri ( ) ,
2022-09-28 09:01:17 +02:00
CssUri : a . AppCssUri ( ) ,
JsUri : a . AppJsUri ( ) ,
2021-07-05 16:41:43 +02:00
ApiUri : c . ApiUri ( ) ,
ContentUri : c . ContentUri ( ) ,
2020-05-31 02:09:52 +02:00
SiteUrl : c . SiteUrl ( ) ,
2021-12-14 15:47:30 +01:00
SiteDomain : c . SiteDomain ( ) ,
2021-11-21 16:36:42 +01:00
SiteAuthor : c . SiteAuthor ( ) ,
2020-05-31 02:09:52 +02:00
SiteTitle : c . SiteTitle ( ) ,
SiteCaption : c . SiteCaption ( ) ,
SiteDescription : c . SiteDescription ( ) ,
2021-11-21 16:36:42 +01:00
SitePreview : c . SitePreview ( ) ,
2022-02-08 14:41:03 +01:00
Imprint : c . Imprint ( ) ,
ImprintUrl : c . ImprintUrl ( ) ,
2021-11-21 16:36:42 +01:00
AppName : c . AppName ( ) ,
AppMode : c . AppMode ( ) ,
AppIcon : c . AppIcon ( ) ,
2022-04-22 17:38:40 +02:00
WallpaperUri : c . WallpaperUri ( ) ,
2020-05-31 02:09:52 +02:00
Version : c . Version ( ) ,
Copyright : c . Copyright ( ) ,
Debug : c . Debug ( ) ,
2022-04-12 19:14:21 +02:00
Trace : c . Trace ( ) ,
2021-02-06 17:04:00 +01:00
Test : c . Test ( ) ,
2020-12-18 10:59:21 +01:00
Demo : c . Demo ( ) ,
2021-01-15 18:30:26 +01:00
Sponsor : c . Sponsor ( ) ,
2020-05-31 02:09:52 +02:00
ReadOnly : c . ReadOnly ( ) ,
Public : c . Public ( ) ,
2022-10-12 18:11:20 +02:00
AuthMode : c . AuthMode ( ) ,
2020-05-31 02:09:52 +02:00
Experimental : c . Experimental ( ) ,
2022-10-02 22:09:02 +02:00
Albums : entity . Albums { } ,
Cameras : entity . Cameras { } ,
Lenses : entity . Lenses { } ,
Countries : entity . Countries { } ,
People : entity . People { } ,
2020-10-04 22:22:53 +02:00
Status : "" ,
2020-10-04 04:47:54 +02:00
MapKey : "" ,
2020-07-13 17:25:27 +02:00
Thumbs : Thumbs ,
2020-05-31 02:09:52 +02:00
Colors : colors . All . List ( ) ,
2022-01-18 12:26:33 +01:00
ManifestUri : c . ClientManifestUri ( ) ,
2020-05-31 02:09:52 +02:00
Clip : txt . ClipDefault ,
PreviewToken : "public" ,
DownloadToken : "public" ,
2022-07-05 23:13:34 +02:00
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
Backups : true ,
WebDAV : c . DisableWebDAV ( ) ,
Settings : c . DisableSettings ( ) ,
Places : c . DisablePlaces ( ) ,
ExifTool : true ,
FFmpeg : true ,
2022-04-06 17:46:41 +02:00
Raw : true ,
2021-09-24 03:00:37 +02:00
Darktable : true ,
Rawtherapee : true ,
Sips : true ,
HeifConvert : true ,
TensorFlow : true ,
Faces : true ,
Classification : true ,
2020-12-18 09:11:42 +01:00
} ,
2021-11-18 00:46:34 +01:00
Flags : strings . Join ( c . Flags ( ) , " " ) ,
2022-09-28 09:01:17 +02:00
Mode : string ( ClientShare ) ,
2020-06-22 20:15:08 +02:00
Name : c . Name ( ) ,
2022-05-20 19:27:33 +02:00
Edition : c . Edition ( ) ,
2021-07-05 16:41:43 +02:00
BaseUri : c . BaseUri ( "" ) ,
StaticUri : c . StaticUri ( ) ,
2022-10-02 11:38:30 +02:00
CssUri : a . AppCssUri ( ) ,
2022-09-28 09:01:17 +02:00
JsUri : a . ShareJsUri ( ) ,
2021-07-05 16:41:43 +02:00
ApiUri : c . ApiUri ( ) ,
ContentUri : c . ContentUri ( ) ,
2020-06-22 20:15:08 +02:00
SiteUrl : c . SiteUrl ( ) ,
2021-12-14 15:47:30 +01:00
SiteDomain : c . SiteDomain ( ) ,
2021-11-21 16:36:42 +01:00
SiteAuthor : c . SiteAuthor ( ) ,
2020-06-22 20:15:08 +02:00
SiteTitle : c . SiteTitle ( ) ,
SiteCaption : c . SiteCaption ( ) ,
SiteDescription : c . SiteDescription ( ) ,
2021-11-21 16:36:42 +01:00
SitePreview : c . SitePreview ( ) ,
2022-02-08 14:41:03 +01:00
Imprint : c . Imprint ( ) ,
ImprintUrl : c . ImprintUrl ( ) ,
2021-11-21 16:36:42 +01:00
AppName : c . AppName ( ) ,
AppMode : c . AppMode ( ) ,
AppIcon : c . AppIcon ( ) ,
2022-04-22 17:38:40 +02:00
WallpaperUri : c . WallpaperUri ( ) ,
2020-06-22 20:15:08 +02:00
Version : c . Version ( ) ,
Copyright : c . Copyright ( ) ,
Debug : c . Debug ( ) ,
2022-04-12 19:14:21 +02:00
Trace : c . Trace ( ) ,
2021-02-06 17:04:00 +01:00
Test : c . Test ( ) ,
2020-12-18 10:59:21 +01:00
Demo : c . Demo ( ) ,
2021-01-15 18:30:26 +01:00
Sponsor : c . Sponsor ( ) ,
2022-10-02 11:38:30 +02:00
ReadOnly : c . ReadOnly ( ) ,
2020-06-22 20:15:08 +02:00
UploadNSFW : c . UploadNSFW ( ) ,
2022-10-02 11:38:30 +02:00
Public : c . Public ( ) ,
2022-10-12 18:11:20 +02:00
AuthMode : c . AuthMode ( ) ,
2022-10-02 11:38:30 +02:00
Experimental : c . Experimental ( ) ,
2022-10-02 22:09:02 +02:00
Albums : entity . Albums { } ,
Cameras : entity . Cameras { } ,
Lenses : entity . Lenses { } ,
Countries : entity . Countries { } ,
People : entity . People { } ,
2020-06-22 20:15:08 +02:00
Colors : colors . All . List ( ) ,
2020-07-13 17:25:27 +02:00
Thumbs : Thumbs ,
2020-12-04 13:10:32 +01:00
Status : c . Hub ( ) . Status ,
MapKey : c . Hub ( ) . MapKey ( ) ,
2020-06-22 20:15:08 +02:00
DownloadToken : c . DownloadToken ( ) ,
PreviewToken : c . PreviewToken ( ) ,
2022-01-18 12:26:33 +01:00
ManifestUri : c . ClientManifestUri ( ) ,
2020-06-22 20:15:08 +02:00
Clip : txt . ClipDefault ,
2022-09-28 09:01:17 +02:00
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
Backups : c . DisableBackups ( ) ,
WebDAV : c . DisableWebDAV ( ) ,
Settings : c . DisableSettings ( ) ,
Places : c . DisablePlaces ( ) ,
ExifTool : c . DisableExifTool ( ) ,
2021-09-24 03:00:37 +02:00
FFmpeg : c . DisableFFmpeg ( ) ,
2022-04-06 17:46:41 +02:00
Raw : c . DisableRaw ( ) ,
2021-09-24 01:53:42 +02:00
Darktable : c . DisableDarktable ( ) ,
Rawtherapee : c . DisableRawtherapee ( ) ,
Sips : c . DisableSips ( ) ,
HeifConvert : c . DisableHeifConvert ( ) ,
2021-09-24 03:00:37 +02:00
TensorFlow : c . DisableTensorFlow ( ) ,
Faces : c . DisableFaces ( ) ,
Classification : c . DisableClassification ( ) ,
2020-12-18 09:11:42 +01:00
} ,
2020-05-27 19:38:40 +02:00
Flags : strings . Join ( c . Flags ( ) , " " ) ,
2022-09-28 09:01:17 +02:00
Mode : string ( ClientUser ) ,
2020-05-27 19:38:40 +02:00
Name : c . Name ( ) ,
2022-05-20 19:27:33 +02:00
Edition : c . Edition ( ) ,
2021-07-05 16:41:43 +02:00
BaseUri : c . BaseUri ( "" ) ,
StaticUri : c . StaticUri ( ) ,
2022-09-28 09:01:17 +02:00
CssUri : a . AppCssUri ( ) ,
JsUri : a . AppJsUri ( ) ,
2021-07-05 16:41:43 +02:00
ApiUri : c . ApiUri ( ) ,
ContentUri : c . ContentUri ( ) ,
2020-05-31 02:09:52 +02:00
SiteUrl : c . SiteUrl ( ) ,
2021-12-14 15:47:30 +01:00
SiteDomain : c . SiteDomain ( ) ,
2021-11-21 16:36:42 +01:00
SiteAuthor : c . SiteAuthor ( ) ,
2020-05-31 02:09:52 +02:00
SiteTitle : c . SiteTitle ( ) ,
SiteCaption : c . SiteCaption ( ) ,
SiteDescription : c . SiteDescription ( ) ,
2021-11-21 16:36:42 +01:00
SitePreview : c . SitePreview ( ) ,
2022-02-08 14:41:03 +01:00
Imprint : c . Imprint ( ) ,
ImprintUrl : c . ImprintUrl ( ) ,
2021-11-21 16:36:42 +01:00
AppName : c . AppName ( ) ,
AppMode : c . AppMode ( ) ,
AppIcon : c . AppIcon ( ) ,
2022-04-22 17:38:40 +02:00
WallpaperUri : c . WallpaperUri ( ) ,
2020-05-27 19:38:40 +02:00
Version : c . Version ( ) ,
Copyright : c . Copyright ( ) ,
Debug : c . Debug ( ) ,
2022-04-12 19:14:21 +02:00
Trace : c . Trace ( ) ,
2021-02-06 17:04:00 +01:00
Test : c . Test ( ) ,
2020-12-18 10:59:21 +01:00
Demo : c . Demo ( ) ,
2021-01-15 18:30:26 +01:00
Sponsor : c . Sponsor ( ) ,
2020-05-27 19:38:40 +02:00
ReadOnly : c . ReadOnly ( ) ,
UploadNSFW : c . UploadNSFW ( ) ,
Public : c . Public ( ) ,
2022-10-12 18:11:20 +02:00
AuthMode : c . AuthMode ( ) ,
2020-05-27 19:38:40 +02:00
Experimental : c . Experimental ( ) ,
2022-10-02 22:09:02 +02:00
Albums : entity . Albums { } ,
Cameras : entity . Cameras { } ,
Lenses : entity . Lenses { } ,
Countries : entity . Countries { } ,
People : entity . People { } ,
2020-05-27 19:38:40 +02:00
Colors : colors . All . List ( ) ,
2020-07-13 17:25:27 +02:00
Thumbs : Thumbs ,
2020-12-04 13:10:32 +01:00
Status : c . Hub ( ) . Status ,
MapKey : c . Hub ( ) . MapKey ( ) ,
2020-05-27 19:38:40 +02:00
DownloadToken : c . DownloadToken ( ) ,
2020-05-27 19:56:56 +02:00
PreviewToken : c . PreviewToken ( ) ,
2022-01-18 12:26:33 +01:00
ManifestUri : c . ClientManifestUri ( ) ,
2020-05-27 19:38:40 +02:00
Clip : txt . ClipDefault ,
2022-04-15 09:42:07 +02:00
Server : env . Info ( ) ,
2022-07-05 23:13:34 +02:00
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, " +
"SUM(photo_quality = -1) AS hidden, SUM(photo_type IN ('image','raw','animated') AND photo_private = 0 AND photo_quality > -1) AS photos, " +
"SUM(photo_type IN ('image','raw','live','animated') AND photo_quality < 3 AND photo_quality > -1 AND photo_private = 0) AS review, " +
"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
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
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" ) .
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.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" ) .
Where ( "file_missing = 0 AND file_root = ?" , 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.
func ( c * Config ) ClientSession ( sess * entity . Session ) ClientConfig {
2022-09-30 00:42:19 +02:00
result := c . ClientUser ( false ) . ApplyACL ( acl . Resources , sess . User ( ) . AclRole ( ) )
2022-09-28 09:01:17 +02:00
result . Settings = c . SessionSettings ( sess )
2020-05-30 21:11:56 +02:00
2020-01-02 00:03:07 +01:00
return result
}