installation of library and settings
This commit is contained in:
parent
96f1a271ef
commit
557b824f8b
12 changed files with 1399 additions and 32 deletions
12
cli/src/api/open-api/api.ts
generated
12
cli/src/api/open-api/api.ts
generated
|
@ -3926,6 +3926,18 @@ export interface SystemConfigReverseGeocodingDto {
|
|||
* @memberof SystemConfigReverseGeocodingDto
|
||||
*/
|
||||
'enabled': boolean;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof SystemConfigReverseGeocodingDto
|
||||
*/
|
||||
'mapboxAccessToken': string;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof SystemConfigReverseGeocodingDto
|
||||
*/
|
||||
'useMapbox': boolean;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ Name | Type | Description | Notes
|
|||
------------ | ------------- | ------------- | -------------
|
||||
**citiesFileOverride** | [**CitiesFile**](CitiesFile.md) | |
|
||||
**enabled** | **bool** | |
|
||||
**mapboxAccessToken** | **String** | |
|
||||
**useMapbox** | **bool** | |
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
|
@ -15,30 +15,42 @@ class SystemConfigReverseGeocodingDto {
|
|||
SystemConfigReverseGeocodingDto({
|
||||
required this.citiesFileOverride,
|
||||
required this.enabled,
|
||||
required this.mapboxAccessToken,
|
||||
required this.useMapbox,
|
||||
});
|
||||
|
||||
CitiesFile citiesFileOverride;
|
||||
|
||||
bool enabled;
|
||||
|
||||
String mapboxAccessToken;
|
||||
|
||||
bool useMapbox;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is SystemConfigReverseGeocodingDto &&
|
||||
other.citiesFileOverride == citiesFileOverride &&
|
||||
other.enabled == enabled;
|
||||
other.enabled == enabled &&
|
||||
other.mapboxAccessToken == mapboxAccessToken &&
|
||||
other.useMapbox == useMapbox;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(citiesFileOverride.hashCode) +
|
||||
(enabled.hashCode);
|
||||
(enabled.hashCode) +
|
||||
(mapboxAccessToken.hashCode) +
|
||||
(useMapbox.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'SystemConfigReverseGeocodingDto[citiesFileOverride=$citiesFileOverride, enabled=$enabled]';
|
||||
String toString() => 'SystemConfigReverseGeocodingDto[citiesFileOverride=$citiesFileOverride, enabled=$enabled, mapboxAccessToken=$mapboxAccessToken, useMapbox=$useMapbox]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
json[r'citiesFileOverride'] = this.citiesFileOverride;
|
||||
json[r'enabled'] = this.enabled;
|
||||
json[r'mapboxAccessToken'] = this.mapboxAccessToken;
|
||||
json[r'useMapbox'] = this.useMapbox;
|
||||
return json;
|
||||
}
|
||||
|
||||
|
@ -52,6 +64,8 @@ class SystemConfigReverseGeocodingDto {
|
|||
return SystemConfigReverseGeocodingDto(
|
||||
citiesFileOverride: CitiesFile.fromJson(json[r'citiesFileOverride'])!,
|
||||
enabled: mapValueOfType<bool>(json, r'enabled')!,
|
||||
mapboxAccessToken: mapValueOfType<String>(json, r'mapboxAccessToken')!,
|
||||
useMapbox: mapValueOfType<bool>(json, r'useMapbox')!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
@ -101,6 +115,8 @@ class SystemConfigReverseGeocodingDto {
|
|||
static const requiredKeys = <String>{
|
||||
'citiesFileOverride',
|
||||
'enabled',
|
||||
'mapboxAccessToken',
|
||||
'useMapbox',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,16 @@ void main() {
|
|||
// TODO
|
||||
});
|
||||
|
||||
// String mapboxAccessToken
|
||||
test('to test the property `mapboxAccessToken`', () async {
|
||||
// TODO
|
||||
});
|
||||
|
||||
// bool useMapbox
|
||||
test('to test the property `useMapbox`', () async {
|
||||
// TODO
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -8828,11 +8828,19 @@
|
|||
},
|
||||
"enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"mapboxAccessToken": {
|
||||
"type": "string"
|
||||
},
|
||||
"useMapbox": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"citiesFileOverride",
|
||||
"enabled"
|
||||
"enabled",
|
||||
"useMapbox",
|
||||
"mapboxAccessToken"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
|
|
1307
server/package-lock.json
generated
1307
server/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -40,6 +40,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.22.11",
|
||||
"@mapbox/mapbox-sdk": "^0.15.3",
|
||||
"@nestjs/bullmq": "^10.0.1",
|
||||
"@nestjs/common": "^10.2.2",
|
||||
"@nestjs/config": "^3.0.0",
|
||||
|
@ -100,6 +101,7 @@
|
|||
"@types/jest": "29.5.4",
|
||||
"@types/jest-when": "^3.5.2",
|
||||
"@types/lodash": "^4.14.197",
|
||||
"@types/mapbox__mapbox-sdk": "^0.13.9",
|
||||
"@types/mock-fs": "^4.13.1",
|
||||
"@types/multer": "^1.4.7",
|
||||
"@types/mv": "^2.1.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CitiesFile } from '@app/infra/entities';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsBoolean, IsEnum } from 'class-validator';
|
||||
import { IsBoolean, IsEnum, IsNotEmpty, IsString, ValidateIf } from 'class-validator';
|
||||
|
||||
export class SystemConfigReverseGeocodingDto {
|
||||
@IsBoolean()
|
||||
|
@ -9,4 +9,12 @@ export class SystemConfigReverseGeocodingDto {
|
|||
@IsEnum(CitiesFile)
|
||||
@ApiProperty({ enum: CitiesFile, enumName: 'CitiesFile' })
|
||||
citiesFileOverride!: CitiesFile;
|
||||
|
||||
@IsBoolean()
|
||||
useMapbox!: boolean;
|
||||
|
||||
@ValidateIf((o) => o.useMapbox === true)
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
mapboxAccessToken!: string;
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ export const defaults = Object.freeze<SystemConfig>({
|
|||
reverseGeocoding: {
|
||||
enabled: true,
|
||||
citiesFileOverride: CitiesFile.CITIES_500,
|
||||
useMapbox: false,
|
||||
mapboxAccessToken: '',
|
||||
},
|
||||
oauth: {
|
||||
enabled: false,
|
||||
|
|
|
@ -67,6 +67,8 @@ export enum SystemConfigKey {
|
|||
|
||||
REVERSE_GEOCODING_ENABLED = 'reverseGeocoding.enabled',
|
||||
REVERSE_GEOCODING_CITIES_FILE_OVERRIDE = 'reverseGeocoding.citiesFileOverride',
|
||||
REVERSE_GEOCODING_USE_MAPBOX = 'reverseGeocoding.useMapbox',
|
||||
REVERSE_GEOCODING_MAPBOX_ACCESS_TOKEN = 'reverseGeocoding.mapboxAccessToken',
|
||||
|
||||
NEW_VERSION_CHECK_ENABLED = 'newVersionCheck.enabled',
|
||||
|
||||
|
@ -201,6 +203,8 @@ export interface SystemConfig {
|
|||
reverseGeocoding: {
|
||||
enabled: boolean;
|
||||
citiesFileOverride: CitiesFile;
|
||||
useMapbox: boolean;
|
||||
mapboxAccessToken: string;
|
||||
};
|
||||
oauth: {
|
||||
enabled: boolean;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { GeoPoint, IMetadataRepository, ImmichTags, ReverseGeocodeResult } from '@app/domain';
|
||||
import { REVERSE_GEOCODING_DUMP_DIRECTORY } from '@app/infra';
|
||||
import { MapiResponse } from '@mapbox/mapbox-sdk/lib/classes/mapi-response';
|
||||
import mapboxGeocoding, { GeocodeService } from '@mapbox/mapbox-sdk/services/geocoding';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { DefaultReadTaskOptions, exiftool } from 'exiftool-vendored';
|
||||
import { readdir, rm } from 'fs/promises';
|
||||
|
@ -25,6 +27,7 @@ const lookup = promisify<GeoPoint[], number, AddressObject[][]>(geocoder.lookUp)
|
|||
@Injectable()
|
||||
export class MetadataRepository implements IMetadataRepository {
|
||||
private logger = new Logger(MetadataRepository.name);
|
||||
private mapboxClient?: GeocodeService;
|
||||
|
||||
async init(options: Partial<InitOptions>): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
|
@ -61,7 +64,8 @@ export class MetadataRepository implements IMetadataRepository {
|
|||
}
|
||||
}
|
||||
|
||||
async reverseGeocode(point: GeoPoint): Promise<ReverseGeocodeResult> {
|
||||
async reverseGeocode(point: GeoPoint, useMapbox: boolean = false): Promise<ReverseGeocodeResult> {
|
||||
console.log(point);
|
||||
this.logger.debug(`Request: ${point.latitude},${point.longitude}`);
|
||||
|
||||
const [address] = await lookup([point], 1);
|
||||
|
@ -73,6 +77,38 @@ export class MetadataRepository implements IMetadataRepository {
|
|||
const state = stateParts.length > 0 ? stateParts.join(', ') : null;
|
||||
this.logger.debug(`Normalized: ${JSON.stringify({ country, state, city })}`);
|
||||
|
||||
// Mapbox
|
||||
this.mapboxClient = mapboxGeocoding({
|
||||
accessToken: 'pk.eyJ1IjoiYWx0cmFuMTUwMiIsImEiOiJjbDBoaXQyZGkwOTEyM2tvMzd2dzJqcXZwIn0.-Lrg7SfQVnhAwWSNV5HoSQ',
|
||||
});
|
||||
|
||||
const geoCodeInfo: MapiResponse = await this.mapboxClient
|
||||
.reverseGeocode({
|
||||
query: [point.longitude, point.latitude],
|
||||
types: ['country', 'region', 'place'],
|
||||
})
|
||||
.send();
|
||||
console.log(geoCodeInfo.body);
|
||||
const res: [] = geoCodeInfo.body['features'];
|
||||
|
||||
let mbCity = '';
|
||||
let mbState = '';
|
||||
let mbCountry = '';
|
||||
|
||||
if (res.filter((geoInfo) => geoInfo['place_type'][0] == 'place')[0]) {
|
||||
mbCity = res.filter((geoInfo) => geoInfo['place_type'][0] == 'place')[0]['text'];
|
||||
}
|
||||
|
||||
if (res.filter((geoInfo) => geoInfo['place_type'][0] == 'region')[0]) {
|
||||
mbState = res.filter((geoInfo) => geoInfo['place_type'][0] == 'region')[0]['text'];
|
||||
}
|
||||
|
||||
if (res.filter((geoInfo) => geoInfo['place_type'][0] == 'country')[0]) {
|
||||
mbCountry = res.filter((geoInfo) => geoInfo['place_type'][0] == 'country')[0]['text'];
|
||||
}
|
||||
|
||||
console.log('Mapbox: ', mbCity, mbState, mbCountry);
|
||||
|
||||
return { country, state, city };
|
||||
}
|
||||
|
||||
|
|
12
web/src/api/open-api/api.ts
generated
12
web/src/api/open-api/api.ts
generated
|
@ -3926,6 +3926,18 @@ export interface SystemConfigReverseGeocodingDto {
|
|||
* @memberof SystemConfigReverseGeocodingDto
|
||||
*/
|
||||
'enabled': boolean;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof SystemConfigReverseGeocodingDto
|
||||
*/
|
||||
'mapboxAccessToken': string;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof SystemConfigReverseGeocodingDto
|
||||
*/
|
||||
'useMapbox': boolean;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue