mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
feat(server, web)!: Move reverse geocoding settings to the UI (#4222)
* feat: reverse geocoding settings * chore: open api * re-init geocoder if precision has been updated * update docs * chore: update verbiage * fix: re-init logic * fix: reset to default --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
@@ -64,6 +64,9 @@ export enum SystemConfigKey {
|
||||
MAP_ENABLED = 'map.enabled',
|
||||
MAP_TILE_URL = 'map.tileUrl',
|
||||
|
||||
REVERSE_GEOCODING_ENABLED = 'reverseGeocoding.enabled',
|
||||
REVERSE_GEOCODING_CITIES_FILE_OVERRIDE = 'reverseGeocoding.citiesFileOverride',
|
||||
|
||||
OAUTH_ENABLED = 'oauth.enabled',
|
||||
OAUTH_ISSUER_URL = 'oauth.issuerUrl',
|
||||
OAUTH_CLIENT_ID = 'oauth.clientId',
|
||||
@@ -130,6 +133,13 @@ export enum Colorspace {
|
||||
P3 = 'p3',
|
||||
}
|
||||
|
||||
export enum CitiesFile {
|
||||
CITIES_15000 = 'cities15000',
|
||||
CITIES_5000 = 'cities5000',
|
||||
CITIES_1000 = 'cities1000',
|
||||
CITIES_500 = 'cities500',
|
||||
}
|
||||
|
||||
export interface SystemConfig {
|
||||
ffmpeg: {
|
||||
crf: number;
|
||||
@@ -175,6 +185,10 @@ export interface SystemConfig {
|
||||
enabled: boolean;
|
||||
tileUrl: string;
|
||||
};
|
||||
reverseGeocoding: {
|
||||
enabled: boolean;
|
||||
citiesFileOverride: CitiesFile;
|
||||
};
|
||||
oauth: {
|
||||
enabled: boolean;
|
||||
issuerUrl: string;
|
||||
|
||||
@@ -2,7 +2,6 @@ import { QueueName } from '@app/domain';
|
||||
import { RegisterQueueOptions } from '@nestjs/bullmq';
|
||||
import { QueueOptions } from 'bullmq';
|
||||
import { RedisOptions } from 'ioredis';
|
||||
import { InitOptions } from 'local-reverse-geocoder';
|
||||
import { ConfigurationOptions } from 'typesense/lib/Typesense/Configuration';
|
||||
|
||||
function parseRedisConfig(): RedisOptions {
|
||||
@@ -72,20 +71,5 @@ function parseTypeSenseConfig(): ConfigurationOptions {
|
||||
|
||||
export const typesenseConfig: ConfigurationOptions = parseTypeSenseConfig();
|
||||
|
||||
function parseLocalGeocodingConfig(): InitOptions {
|
||||
const precision = Number(process.env.REVERSE_GEOCODING_PRECISION);
|
||||
|
||||
return {
|
||||
citiesFileOverride: precision ? ['cities15000', 'cities5000', 'cities1000', 'cities500'][precision] : undefined,
|
||||
load: {
|
||||
admin1: true,
|
||||
admin2: true,
|
||||
admin3And4: false,
|
||||
alternateNames: false,
|
||||
},
|
||||
countries: [],
|
||||
dumpDirectory: process.env.REVERSE_GEOCODING_DUMP_DIRECTORY || process.cwd() + '/.reverse-geocoding-dump/',
|
||||
};
|
||||
}
|
||||
|
||||
export const localGeocodingConfig: InitOptions = parseLocalGeocodingConfig();
|
||||
export const REVERSE_GEOCODING_DUMP_DIRECTORY =
|
||||
process.env.REVERSE_GEOCODING_DUMP_DIRECTORY || process.cwd() + '/.reverse-geocoding-dump/';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { GeoPoint, IGeocodingRepository, ReverseGeocodeResult } from '@app/domain';
|
||||
import { localGeocodingConfig } from '@app/infra';
|
||||
import { REVERSE_GEOCODING_DUMP_DIRECTORY } from '@app/infra';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { readdir, rm } from 'fs/promises';
|
||||
import { getName } from 'i18n-iso-countries';
|
||||
import geocoder, { AddressObject } from 'local-reverse-geocoder';
|
||||
import geocoder, { AddressObject, InitOptions } from 'local-reverse-geocoder';
|
||||
import path from 'path';
|
||||
import { promisify } from 'util';
|
||||
|
||||
@@ -18,19 +18,33 @@ export type GeoData = AddressObject & {
|
||||
admin2Code?: AdminCode | string;
|
||||
};
|
||||
|
||||
const init = (): Promise<void> => new Promise<void>((resolve) => geocoder.init(localGeocodingConfig, resolve));
|
||||
const lookup = promisify<GeoPoint[], number, AddressObject[][]>(geocoder.lookUp).bind(geocoder);
|
||||
|
||||
@Injectable()
|
||||
export class GeocodingRepository implements IGeocodingRepository {
|
||||
private logger = new Logger(GeocodingRepository.name);
|
||||
|
||||
async init(): Promise<void> {
|
||||
await init();
|
||||
async init(options: Partial<InitOptions>): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
geocoder.init(
|
||||
{
|
||||
load: {
|
||||
admin1: true,
|
||||
admin2: true,
|
||||
admin3And4: false,
|
||||
alternateNames: false,
|
||||
},
|
||||
countries: [],
|
||||
dumpDirectory: REVERSE_GEOCODING_DUMP_DIRECTORY,
|
||||
...options,
|
||||
},
|
||||
resolve,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async deleteCache() {
|
||||
const dumpDirectory = localGeocodingConfig.dumpDirectory;
|
||||
const dumpDirectory = REVERSE_GEOCODING_DUMP_DIRECTORY;
|
||||
if (dumpDirectory) {
|
||||
// delete contents
|
||||
const items = await readdir(dumpDirectory, { withFileTypes: true });
|
||||
|
||||
Reference in New Issue
Block a user