mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 18:19:11 +00:00
Hide faces from frontend if disabled
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
api "github.com/photoview/photoview/api/graphql"
|
||||
"github.com/photoview/photoview/api/graphql/auth"
|
||||
"github.com/photoview/photoview/api/graphql/models"
|
||||
"github.com/photoview/photoview/api/scanner/face_detection"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
@@ -228,6 +229,10 @@ func (r *mutationResolver) FavoriteMedia(ctx context.Context, mediaID int, favor
|
||||
}
|
||||
|
||||
func (r *mediaResolver) Faces(ctx context.Context, media *models.Media) ([]*models.ImageFace, error) {
|
||||
if face_detection.GlobalFaceDetector == nil {
|
||||
return []*models.ImageFace{}, nil
|
||||
}
|
||||
|
||||
if media.Faces != nil {
|
||||
return media.Faces, nil
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package resolvers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
api "github.com/photoview/photoview/api/graphql"
|
||||
"github.com/photoview/photoview/api/graphql/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -35,7 +32,3 @@ type queryResolver struct{ *Resolver }
|
||||
type subscriptionResolver struct {
|
||||
Resolver *Resolver
|
||||
}
|
||||
|
||||
func (r *queryResolver) SiteInfo(ctx context.Context) (*models.SiteInfo, error) {
|
||||
return models.GetSiteInfo(r.Database)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import (
|
||||
"github.com/photoview/photoview/api/scanner/face_detection"
|
||||
)
|
||||
|
||||
func (r *queryResolver) SiteInfo(ctx context.Context) (*models.SiteInfo, error) {
|
||||
return models.GetSiteInfo(r.Database)
|
||||
}
|
||||
|
||||
type SiteInfoResolver struct {
|
||||
*Resolver
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ type Query {
|
||||
"Get media owned by the logged in user, returned in GeoJson format"
|
||||
myMediaGeoJson: Any! @isAuthorized
|
||||
"Get the mapbox api token, returns null if mapbox is not enabled"
|
||||
mapboxToken: String
|
||||
mapboxToken: String @isAuthorized
|
||||
|
||||
shareToken(credentials: ShareTokenCredentials!): ShareToken!
|
||||
shareTokenValidatePassword(credentials: ShareTokenCredentials!): Boolean!
|
||||
|
||||
@@ -22,8 +22,8 @@ type FaceDetector struct {
|
||||
var GlobalFaceDetector *FaceDetector = nil
|
||||
|
||||
func InitializeFaceDetector(db *gorm.DB) error {
|
||||
if utils.EnvDisableRawProcessing.GetBool() {
|
||||
log.Printf("Face detection disabled (%s=1)\n", utils.EnvDisableRawProcessing.GetName())
|
||||
if utils.EnvDisableFaceRecognition.GetBool() {
|
||||
log.Printf("Face detection disabled (%s=1)\n", utils.EnvDisableFaceRecognition.GetName())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { NavLink } from 'react-router-dom'
|
||||
import { useQuery, gql } from '@apollo/client'
|
||||
import { authToken } from '../../helpers/authentication'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { mapboxEnabledQuery } from '../../__generated__/mapboxEnabledQuery'
|
||||
|
||||
export const MAPBOX_QUERY = gql`
|
||||
query mapboxEnabledQuery {
|
||||
@@ -10,6 +11,14 @@ export const MAPBOX_QUERY = gql`
|
||||
}
|
||||
`
|
||||
|
||||
export const FACE_DETECTION_ENABLED_QUERY = gql`
|
||||
query faceDetectionEnabled {
|
||||
siteInfo {
|
||||
faceDetectionEnabled
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
type MenuButtonProps = {
|
||||
to: string
|
||||
exact: boolean
|
||||
@@ -56,9 +65,16 @@ const MenuSeparator = () => (
|
||||
export const MainMenu = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const mapboxQuery = authToken() ? useQuery(MAPBOX_QUERY) : null
|
||||
const mapboxQuery = authToken()
|
||||
? useQuery<mapboxEnabledQuery>(MAPBOX_QUERY)
|
||||
: null
|
||||
const faceDetectionEnabledQuery = authToken()
|
||||
? useQuery(FACE_DETECTION_ENABLED_QUERY)
|
||||
: null
|
||||
|
||||
const mapboxEnabled = !!mapboxQuery?.data?.mapboxToken
|
||||
const faceDetectionEnabled =
|
||||
!!faceDetectionEnabledQuery?.data?.siteInfo?.faceDetectionEnabled
|
||||
|
||||
return (
|
||||
<div className="fixed w-full bottom-0 lg:bottom-auto lg:top-[84px] z-30 bg-white shadow-separator lg:shadow-none lg:w-[240px] lg:ml-8 lg:mr-5 flex-shrink-0">
|
||||
@@ -104,19 +120,21 @@ export const MainMenu = () => {
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
<MenuButton
|
||||
to="/people"
|
||||
exact
|
||||
label={t('sidemenu.people', 'People')}
|
||||
background="#fbcd78"
|
||||
activeClasses="ring-[#fff7e4] bg-[#fff7e4]"
|
||||
className="outline-none focus:ring-2 focus:ring-yellow-100 focus:ring-offset-2"
|
||||
icon={
|
||||
<svg viewBox="0 0 24 24" fill="white">
|
||||
<path d="M15.713873,14.2127622 C17.4283917,14.8986066 18.9087267,16.0457918 20.0014344,17.5008819 C20,19.1568542 18.6568542,20.5 17,20.5 L7,20.5 C5.34314575,20.5 4,19.1568542 4,17.5 L4.09169034,17.3788798 C5.17486154,15.981491 6.62020934,14.878942 8.28693513,14.2120314 C9.30685583,15.018595 10.5972088,15.5 12,15.5 C13.3092718,15.5 14.5205974,15.0806428 15.5069849,14.3689203 L15.713873,14.2127622 L15.713873,14.2127622 Z M12,4 C15.0375661,4 17.5,6.46243388 17.5,9.5 C17.5,12.5375661 15.0375661,15 12,15 C8.96243388,15 6.5,12.5375661 6.5,9.5 C6.5,6.46243388 8.96243388,4 12,4 Z"></path>
|
||||
</svg>
|
||||
}
|
||||
/>
|
||||
{faceDetectionEnabled ? (
|
||||
<MenuButton
|
||||
to="/people"
|
||||
exact
|
||||
label={t('sidemenu.people', 'People')}
|
||||
background="#fbcd78"
|
||||
activeClasses="ring-[#fff7e4] bg-[#fff7e4]"
|
||||
className="outline-none focus:ring-2 focus:ring-yellow-100 focus:ring-offset-2"
|
||||
icon={
|
||||
<svg viewBox="0 0 24 24" fill="white">
|
||||
<path d="M15.713873,14.2127622 C17.4283917,14.8986066 18.9087267,16.0457918 20.0014344,17.5008819 C20,19.1568542 18.6568542,20.5 17,20.5 L7,20.5 C5.34314575,20.5 4,19.1568542 4,17.5 L4.09169034,17.3788798 C5.17486154,15.981491 6.62020934,14.878942 8.28693513,14.2120314 C9.30685583,15.018595 10.5972088,15.5 12,15.5 C13.3092718,15.5 14.5205974,15.0806428 15.5069849,14.3689203 L15.713873,14.2127622 L15.713873,14.2127622 Z M12,4 C15.0375661,4 17.5,6.46243388 17.5,9.5 C17.5,12.5375661 15.0375661,15 12,15 C8.96243388,15 6.5,12.5375661 6.5,9.5 C6.5,6.46243388 8.96243388,4 12,4 Z"></path>
|
||||
</svg>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
<MenuSeparator />
|
||||
<MenuButton
|
||||
to="/settings"
|
||||
|
||||
@@ -330,18 +330,6 @@ const flashLookup = (t: TranslationFn): { [key: number]: string } => {
|
||||
}
|
||||
}
|
||||
|
||||
// From https://exiftool.org/TagNames/EXIF.html
|
||||
// const orientation = {
|
||||
// 1: 'Horizontal (normal)',
|
||||
// 2: 'Mirror horizontal',
|
||||
// 3: 'Rotate 180',
|
||||
// 4: 'Mirror vertical',
|
||||
// 5: 'Mirror horizontal and rotate 270 CW',
|
||||
// 6: 'Rotate 90 CW',
|
||||
// 7: 'Mirror horizontal and rotate 90 CW',
|
||||
// 8: 'Rotate 270 CW',
|
||||
// }
|
||||
|
||||
type SidebarContentProps = {
|
||||
media: MediaSidebarMedia
|
||||
hidePreview?: boolean
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
}
|
||||
},
|
||||
"photos_page": {
|
||||
"title": "Billeder"
|
||||
"title": "Tidslinje"
|
||||
},
|
||||
"places_page": {
|
||||
"title": "Kort"
|
||||
@@ -285,13 +285,13 @@
|
||||
"sidemenu": {
|
||||
"albums": "Albums",
|
||||
"people": "Personer",
|
||||
"photos": "Billeder",
|
||||
"photos": "Tidslinje",
|
||||
"places": "Kort",
|
||||
"settings": "Indstillinger"
|
||||
},
|
||||
"title": {
|
||||
"loading_album": "Loader album",
|
||||
"login": "Logind",
|
||||
"login": "Log ind",
|
||||
"people": "Personer",
|
||||
"settings": "Indstillinger"
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
}
|
||||
},
|
||||
"photos_page": {
|
||||
"title": "Photos"
|
||||
"title": "Timeline"
|
||||
},
|
||||
"places_page": {
|
||||
"title": "Places"
|
||||
@@ -285,7 +285,7 @@
|
||||
"sidemenu": {
|
||||
"albums": "Albums",
|
||||
"people": "People",
|
||||
"photos": "Photos",
|
||||
"photos": "Timeline",
|
||||
"places": "Places",
|
||||
"settings": "Settings"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user