diff --git a/src/backend/model/database/sql/PersonManager.ts b/src/backend/model/database/sql/PersonManager.ts index c040f7a6..987278d1 100644 --- a/src/backend/model/database/sql/PersonManager.ts +++ b/src/backend/model/database/sql/PersonManager.ts @@ -44,6 +44,15 @@ export class PersonManager implements IPersonManager { const hasAll = names.reduce((prev, name) => prev && !!this.samplePhotos[name], true); if (!hasAll) { const connection = await SQLConnection.getConnection(); + const namesObj: any = {}; + let queryStr = ''; + names.forEach((n, i) => { + if (i > 0) { + queryStr += ', '; + } + queryStr += ':n' + i + ' COLLATE utf8_general_ci'; + namesObj['n' + i] = n; + }); const rawAndEntities = await (connection .getRepository(MediaEntity) .createQueryBuilder('media') as SelectQueryBuilder) @@ -52,19 +61,19 @@ export class PersonManager implements IPersonManager { .leftJoin('media.directory', 'directory') .leftJoinAndSelect('media.metadata.faces', 'faces') .leftJoin('faces.person', 'person') - .groupBy('person.name') - .orWhere(`person.name IN (:...names) COLLATE utf8_general_ci`, {names: names}).getRawAndEntities(); + .groupBy('person.name, media.name, media.id, directory.name, faces.id') + .orWhere(`lower(person.name) IN (:...names)`, {names: names.map(n => n.toLowerCase())}).getRawAndEntities(); for (let i = 0; i < rawAndEntities.raw.length; ++i) { - this.samplePhotos[rawAndEntities.raw[i].person_name] = + this.samplePhotos[rawAndEntities.raw[i].person_name.toLowerCase()] = Utils.clone(rawAndEntities.entities.find(m => m.name === rawAndEntities.raw[i].media_name)); - this.samplePhotos[rawAndEntities.raw[i].person_name].metadata.faces = [FaceRegionEntry.fromRawToDTO(rawAndEntities.raw[i])]; + this.samplePhotos[rawAndEntities.raw[i].person_name.toLowerCase()].metadata.faces = [FaceRegionEntry.fromRawToDTO(rawAndEntities.raw[i])]; } } const photoMap: { [key: string]: PhotoDTO } = {}; - names.forEach(n => photoMap[n] = this.samplePhotos[n]); + names.forEach(n => photoMap[n] = this.samplePhotos[n.toLowerCase()]); return photoMap; } diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts index 00daa115..961bb632 100644 --- a/src/frontend/app/app.module.ts +++ b/src/frontend/app/app.module.ts @@ -128,7 +128,7 @@ export function translationsFactory(locale: string) { if (locale === 'en') { return ''; } - return (require(`raw-loader!../translate/messages.${locale}.xlf`)).default; + return (require(`raw-loader!../translate/ts-only-msg.fr.xlf`)).default; } @NgModule({ diff --git a/test/backend/unit/model/sql/PersonManager.ts b/test/backend/unit/model/sql/PersonManager.ts index 23af543b..cba14bdc 100644 --- a/test/backend/unit/model/sql/PersonManager.ts +++ b/test/backend/unit/model/sql/PersonManager.ts @@ -68,27 +68,45 @@ describe('PersonManager', (sqlHelper: SQLTestHelper) => { }); - it('should get sample photos', async () => { - const pm = new PersonManager(); + const mapPhoto = (photo: PhotoDTO) => { const map: { [key: string]: PhotoDTO } = {}; - p.metadata.faces.forEach(face => { + photo.metadata.faces.forEach(face => { map[face.name] = { - id: p.id, - name: p.name, + id: photo.id, + name: photo.name, directory: { - path: p.directory.path, - name: p.directory.name, + path: photo.directory.path, + name: photo.directory.name, }, metadata: { - size: p.metadata.size, - faces: [p.metadata.faces.find(f => f.name === face.name)] + size: photo.metadata.size, + faces: [photo.metadata.faces.find(f => f.name === face.name)] }, readyIcon: false, readyThumbnails: [] }; }); + return map; + }; + + it('should get sample photos', async () => { + const pm = new PersonManager(); + const map = mapPhoto(p); expect(await pm.getSamplePhotos(p.metadata.faces.map(f => f.name))).to.deep.equal(map); }); + + it('should get sample photos case insensitive', async () => { + const pm = new PersonManager(); + const map = mapPhoto(p); + for (const k of Object.keys(map)) { + if (k.toLowerCase() !== k) { + map[k.toLowerCase()] = map[k]; + delete map[k]; + } + } + expect(await pm.getSamplePhotos(p.metadata.faces.map(f => f.name.toLowerCase()))).to.deep.equal(map); + }); + });