From 5dc652199b44e163bb2335ce46bfc89cbaca06f9 Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Mon, 7 Jun 2021 15:11:17 +0800 Subject: [PATCH] fix typo in LEVEL_UP_LOCATION (#139) --- apps/whale-api/src/app.configuration.ts | 1 + .../src/module.database/provider.level/module.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/whale-api/src/app.configuration.ts b/apps/whale-api/src/app.configuration.ts index cb6fca9ba6..06e227fa97 100644 --- a/apps/whale-api/src/app.configuration.ts +++ b/apps/whale-api/src/app.configuration.ts @@ -5,6 +5,7 @@ * replacing the config module. */ export const AppConfiguration = (): any => ({ + isProd: process.env.NODE_ENV === 'production', defid: { url: process.env.WHALE_DEFID_URL }, diff --git a/apps/whale-api/src/module.database/provider.level/module.ts b/apps/whale-api/src/module.database/provider.level/module.ts index 3c5e577606..8730979f4a 100644 --- a/apps/whale-api/src/module.database/provider.level/module.ts +++ b/apps/whale-api/src/module.database/provider.level/module.ts @@ -19,11 +19,16 @@ function mkdir (location: string): void { providers: [ { provide: 'LEVEL_UP_LOCATION', + /** + * if isProd, resolve to .leveldb/{network} + * else, resolve to .leveldb/{network}/time-now + */ useFactory: (configService: ConfigService): string => { - const location = configService.get( - 'database.level.location', - process.env.NODE_ENV === 'production ' ? '.level/index' : `.level/unnamed/${Date.now()}` - ) + const isProd = configService.get('isProd', false) + const network = configService.get('network', 'unknown') + const defaultLocation = isProd ? `.leveldb/${network}` : `.leveldb/${network}/${Date.now()}` + + const location = configService.get('database.level.location', defaultLocation) mkdir(location) return location },