1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

fixing case sensitivity issue with PersonManager

This commit is contained in:
Patrik J. Braun 2020-01-01 20:26:59 +01:00
parent 0e52f149ee
commit 83f3def727
3 changed files with 42 additions and 15 deletions

View File

@ -44,6 +44,15 @@ export class PersonManager implements IPersonManager {
const hasAll = names.reduce((prev, name) => prev && !!this.samplePhotos[name], true); const hasAll = names.reduce((prev, name) => prev && !!this.samplePhotos[name], true);
if (!hasAll) { if (!hasAll) {
const connection = await SQLConnection.getConnection(); 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 const rawAndEntities = await (connection
.getRepository(MediaEntity) .getRepository(MediaEntity)
.createQueryBuilder('media') as SelectQueryBuilder<MediaEntity>) .createQueryBuilder('media') as SelectQueryBuilder<MediaEntity>)
@ -52,19 +61,19 @@ export class PersonManager implements IPersonManager {
.leftJoin('media.directory', 'directory') .leftJoin('media.directory', 'directory')
.leftJoinAndSelect('media.metadata.faces', 'faces') .leftJoinAndSelect('media.metadata.faces', 'faces')
.leftJoin('faces.person', 'person') .leftJoin('faces.person', 'person')
.groupBy('person.name') .groupBy('person.name, media.name, media.id, directory.name, faces.id')
.orWhere(`person.name IN (:...names) COLLATE utf8_general_ci`, {names: names}).getRawAndEntities(); .orWhere(`lower(person.name) IN (:...names)`, {names: names.map(n => n.toLowerCase())}).getRawAndEntities();
for (let i = 0; i < rawAndEntities.raw.length; ++i) { 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)); 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 } = {}; const photoMap: { [key: string]: PhotoDTO } = {};
names.forEach(n => photoMap[n] = this.samplePhotos[n]); names.forEach(n => photoMap[n] = this.samplePhotos[n.toLowerCase()]);
return photoMap; return photoMap;
} }

View File

@ -128,7 +128,7 @@ export function translationsFactory(locale: string) {
if (locale === 'en') { if (locale === 'en') {
return ''; return '';
} }
return (<any>require(`raw-loader!../translate/messages.${locale}.xlf`)).default; return (<any>require(`raw-loader!../translate/ts-only-msg.fr.xlf`)).default;
} }
@NgModule({ @NgModule({

View File

@ -68,27 +68,45 @@ describe('PersonManager', (sqlHelper: SQLTestHelper) => {
}); });
it('should get sample photos', async () => { const mapPhoto = (photo: PhotoDTO) => {
const pm = new PersonManager();
const map: { [key: string]: PhotoDTO } = {}; const map: { [key: string]: PhotoDTO } = {};
p.metadata.faces.forEach(face => { photo.metadata.faces.forEach(face => {
map[face.name] = <any>{ map[face.name] = <any>{
id: p.id, id: photo.id,
name: p.name, name: photo.name,
directory: { directory: {
path: p.directory.path, path: photo.directory.path,
name: p.directory.name, name: photo.directory.name,
}, },
metadata: { metadata: {
size: p.metadata.size, size: photo.metadata.size,
faces: [p.metadata.faces.find(f => f.name === face.name)] faces: [photo.metadata.faces.find(f => f.name === face.name)]
}, },
readyIcon: false, readyIcon: false,
readyThumbnails: [] 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); 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);
});
}); });