mirror of
https://github.com/immich-app/immich.git
synced 2025-01-26 17:21:29 +02:00
fix(server): Improve reverse geocoded location metadata (#9051)
* fix: improve reverse geocoding * fix: update tests referencing states * fix: expect state suggestion in any order --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
a2cf8c7fc7
commit
4bb7d2df49
@ -1006,7 +1006,7 @@ describe('/asset', () => {
|
|||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
lat: expect.closeTo(39.115),
|
lat: expect.closeTo(39.115),
|
||||||
lon: expect.closeTo(-108.400_968),
|
lon: expect.closeTo(-108.400_968),
|
||||||
state: 'Mesa County, Colorado',
|
state: 'Colorado',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
city: 'Ralston',
|
city: 'Ralston',
|
||||||
@ -1014,7 +1014,7 @@ describe('/asset', () => {
|
|||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
lat: expect.closeTo(41.2203),
|
lat: expect.closeTo(41.2203),
|
||||||
lon: expect.closeTo(-96.071_625),
|
lon: expect.closeTo(-96.071_625),
|
||||||
state: 'Douglas County, Nebraska',
|
state: 'Nebraska',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
@ -1033,7 +1033,7 @@ describe('/asset', () => {
|
|||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
lat: expect.closeTo(39.115),
|
lat: expect.closeTo(39.115),
|
||||||
lon: expect.closeTo(-108.400_968),
|
lon: expect.closeTo(-108.400_968),
|
||||||
state: 'Mesa County, Colorado',
|
state: 'Colorado',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
city: 'Ralston',
|
city: 'Ralston',
|
||||||
@ -1041,7 +1041,7 @@ describe('/asset', () => {
|
|||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
lat: expect.closeTo(41.2203),
|
lat: expect.closeTo(41.2203),
|
||||||
lon: expect.closeTo(-96.071_625),
|
lon: expect.closeTo(-96.071_625),
|
||||||
state: 'Douglas County, Nebraska',
|
state: 'Nebraska',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -469,7 +469,8 @@ describe('/search', () => {
|
|||||||
const { status, body } = await request(app)
|
const { status, body } = await request(app)
|
||||||
.get('/search/suggestions?type=state')
|
.get('/search/suggestions?type=state')
|
||||||
.set('Authorization', `Bearer ${admin.accessToken}`);
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
||||||
expect(body).toEqual(states);
|
expect(body).toHaveLength(states.length);
|
||||||
|
expect(body).toEqual(expect.arrayContaining(states));
|
||||||
expect(status).toBe(200);
|
expect(status).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -79,7 +79,9 @@ export class MetadataRepository implements IMetadataRepository {
|
|||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
lineToEntityMapper: (lineSplit: string[]) => GeodataPlacesEntity,
|
lineToEntityMapper: (lineSplit: string[]) => GeodataPlacesEntity,
|
||||||
filePath: string,
|
filePath: string,
|
||||||
|
options?: { entityFilter?: (linesplit: string[]) => boolean },
|
||||||
) {
|
) {
|
||||||
|
const _entityFilter = options?.entityFilter ?? (() => true);
|
||||||
if (!existsSync(filePath)) {
|
if (!existsSync(filePath)) {
|
||||||
this.logger.error(`Geodata file ${filePath} not found`);
|
this.logger.error(`Geodata file ${filePath} not found`);
|
||||||
throw new Error(`Geodata file ${filePath} not found`);
|
throw new Error(`Geodata file ${filePath} not found`);
|
||||||
@ -91,6 +93,9 @@ export class MetadataRepository implements IMetadataRepository {
|
|||||||
|
|
||||||
for await (const line of lineReader) {
|
for await (const line of lineReader) {
|
||||||
const lineSplit = line.split('\t');
|
const lineSplit = line.split('\t');
|
||||||
|
if (!_entityFilter(lineSplit)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const geoData = lineToEntityMapper(lineSplit);
|
const geoData = lineToEntityMapper(lineSplit);
|
||||||
bufferGeodata.push(geoData);
|
bufferGeodata.push(geoData);
|
||||||
if (bufferGeodata.length > 1000) {
|
if (bufferGeodata.length > 1000) {
|
||||||
@ -123,6 +128,7 @@ export class MetadataRepository implements IMetadataRepository {
|
|||||||
admin2Name: admin2Map.get(`${lineSplit[8]}.${lineSplit[10]}.${lineSplit[11]}`),
|
admin2Name: admin2Map.get(`${lineSplit[8]}.${lineSplit[10]}.${lineSplit[11]}`),
|
||||||
}),
|
}),
|
||||||
geodataCities500Path,
|
geodataCities500Path,
|
||||||
|
{ entityFilter: (lineSplit) => lineSplit[7] != 'PPLX' },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,10 +173,9 @@ export class MetadataRepository implements IMetadataRepository {
|
|||||||
|
|
||||||
this.logger.verbose(`Raw: ${JSON.stringify(response, null, 2)}`);
|
this.logger.verbose(`Raw: ${JSON.stringify(response, null, 2)}`);
|
||||||
|
|
||||||
const { countryCode, name: city, admin1Name, admin2Name } = response;
|
const { countryCode, name: city, admin1Name } = response;
|
||||||
const country = getName(countryCode, 'en') ?? null;
|
const country = getName(countryCode, 'en') ?? null;
|
||||||
const stateParts = [admin2Name, admin1Name].filter((name) => !!name);
|
const state = admin1Name;
|
||||||
const state = stateParts.length > 0 ? stateParts.join(', ') : null;
|
|
||||||
|
|
||||||
return { country, state, city };
|
return { country, state, city };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user