mirror of
https://github.com/immich-app/immich.git
synced 2024-12-25 10:43:13 +02:00
fix(server): reverse geocoding delete dump logic (#2551)
This commit is contained in:
parent
2dc8a93685
commit
a1f1e5bc37
@ -50,14 +50,14 @@ export class MetadataExtractionProcessor {
|
|||||||
this.reverseGeocodingEnabled = !configService.get('DISABLE_REVERSE_GEOCODING');
|
this.reverseGeocodingEnabled = !configService.get('DISABLE_REVERSE_GEOCODING');
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(skipCache = false) {
|
async init(deleteCache = false) {
|
||||||
this.logger.warn(`Reverse geocoding is ${this.reverseGeocodingEnabled ? 'enabled' : 'disabled'}`);
|
this.logger.warn(`Reverse geocoding is ${this.reverseGeocodingEnabled ? 'enabled' : 'disabled'}`);
|
||||||
if (!this.reverseGeocodingEnabled) {
|
if (!this.reverseGeocodingEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipCache) {
|
if (deleteCache) {
|
||||||
await this.geocodingRepository.deleteCache();
|
await this.geocodingRepository.deleteCache();
|
||||||
}
|
}
|
||||||
this.logger.log('Initializing Reverse Geocoding');
|
this.logger.log('Initializing Reverse Geocoding');
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { GeoPoint, IGeocodingRepository, ReverseGeocodeResult } from '@app/domain';
|
import { GeoPoint, IGeocodingRepository, ReverseGeocodeResult } from '@app/domain';
|
||||||
import { localGeocodingConfig } from '@app/infra';
|
import { localGeocodingConfig } from '@app/infra';
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { rm } from 'fs/promises';
|
import { readdir, rm } from 'fs/promises';
|
||||||
import { getName } from 'i18n-iso-countries';
|
import { getName } from 'i18n-iso-countries';
|
||||||
import geocoder, { AddressObject } from 'local-reverse-geocoder';
|
import geocoder, { AddressObject } from 'local-reverse-geocoder';
|
||||||
|
import path from 'path';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
export interface AdminCode {
|
export interface AdminCode {
|
||||||
@ -31,7 +32,12 @@ export class GeocodingRepository implements IGeocodingRepository {
|
|||||||
async deleteCache() {
|
async deleteCache() {
|
||||||
const dumpDirectory = localGeocodingConfig.dumpDirectory;
|
const dumpDirectory = localGeocodingConfig.dumpDirectory;
|
||||||
if (dumpDirectory) {
|
if (dumpDirectory) {
|
||||||
await rm(dumpDirectory, { recursive: true, force: true });
|
// delete contents
|
||||||
|
const items = await readdir(dumpDirectory, { withFileTypes: true });
|
||||||
|
const folders = items.filter((item) => item.isDirectory());
|
||||||
|
for (const { name } of folders) {
|
||||||
|
await rm(path.join(dumpDirectory, name), { recursive: true, force: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user