diff --git a/src/photo/db/query.ts b/src/photo/db/query.ts index 07e73777..64f306d0 100644 --- a/src/photo/db/query.ts +++ b/src/photo/db/query.ts @@ -590,20 +590,18 @@ const outdatedWhereValues = [ MAKE_FUJIFILM, ]; -const needsAiTextWhereClauses = ( - AI_TEXT_GENERATION_ENABLED && - AI_TEXT_AUTO_GENERATED_FIELDS.length -) - ? AI_TEXT_AUTO_GENERATED_FIELDS - .map(field => { - switch (field) { - case 'title': return `(title <> '') IS NOT TRUE`; - case 'caption': return `(caption <> '') IS NOT TRUE`; - case 'tags': return `(tags IS NULL OR array_length(tags, 1) = 0)`; - case 'semantic': return `(semantic_description <> '') IS NOT TRUE`; - } - }) - : []; +const needsAiTextWhereClauses = + AI_TEXT_GENERATION_ENABLED + ? AI_TEXT_AUTO_GENERATED_FIELDS + .map(field => { + switch (field) { + case 'title': return `(title <> '') IS NOT TRUE`; + case 'caption': return `(caption <> '') IS NOT TRUE`; + case 'tags': return `(tags IS NULL OR array_length(tags, 1) = 0)`; + case 'semantic': return `(semantic_description <> '') IS NOT TRUE`; + } + }) + : []; const needsSyncWhereStatement = `WHERE ${outdatedWhereClauses.concat(needsAiTextWhereClauses).join(' OR ')}`; diff --git a/src/photo/sync.ts b/src/photo/sync.ts index c1a4d910..d801c0ec 100644 --- a/src/photo/sync.ts +++ b/src/photo/sync.ts @@ -1,6 +1,9 @@ import { MAKE_FUJIFILM } from '@/platforms/fujifilm'; import { Photo, PhotoDb } from '.'; -import { AI_TEXT_AUTO_GENERATED_FIELDS } from '@/app/config'; +import { + AI_TEXT_AUTO_GENERATED_FIELDS, + AI_TEXT_GENERATION_ENABLED, +} from '@/app/config'; import { AiAutoGeneratedField } from './ai'; export interface PhotoSyncStatus { @@ -26,18 +29,20 @@ const getMissingAiTextFields = ({ tags, semanticDescription, }: PhotoDb | Photo): AiAutoGeneratedField[] => - AI_TEXT_AUTO_GENERATED_FIELDS.reduce((fields, field) => { - switch (field) { - case 'title': - return !title ? [...fields, 'title'] : fields; - case 'caption': - return !caption ? [...fields, 'caption'] : fields; - case 'tags': - return (tags ?? []).length === 0 ? [...fields, 'tags'] : fields; - case 'semantic': - return !semanticDescription ? [...fields, 'semantic'] : fields; - } - }, [] as AiAutoGeneratedField[]); + AI_TEXT_GENERATION_ENABLED + ? AI_TEXT_AUTO_GENERATED_FIELDS.reduce((fields, field) => { + switch (field) { + case 'title': + return !title ? [...fields, 'title'] : fields; + case 'caption': + return !caption ? [...fields, 'caption'] : fields; + case 'tags': + return (tags ?? []).length === 0 ? [...fields, 'tags'] : fields; + case 'semantic': + return !semanticDescription ? [...fields, 'semantic'] : fields; + } + }, [] as AiAutoGeneratedField[]) + : []; export const generatePhotoSyncStatus = (photo: PhotoDb): PhotoSyncStatus => ({ isOutdated: isPhotoOutdated(photo),