Added schema validation for mapbox secret from server

This commit is contained in:
Alex Tran 2022-03-07 14:54:46 -06:00
parent 251c92ff1e
commit 5093c57cf9
3 changed files with 26 additions and 3 deletions

View file

@ -11,3 +11,8 @@ UPLOAD_LOCATION=absolute_location_on_your_machine_where_you_want_to_store_the_ba
# JWT SECRET # JWT SECRET
JWT_SECRET= JWT_SECRET=
# MAPBOX
## ENABLE_MAPBOX is either true of false -> if true, you have to provide MAPBOX_KEY
ENABLE_MAPBOX=
MAPBOX_KEY=

View file

@ -1,9 +1,12 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard';
import { ServerInfoService } from './server-info.service'; import { ServerInfoService } from './server-info.service';
@Controller('server-info') @Controller('server-info')
export class ServerInfoController { export class ServerInfoController {
constructor(private readonly serverInfoService: ServerInfoService) {} constructor(private readonly serverInfoService: ServerInfoService, private readonly configService: ConfigService) {}
@Get() @Get()
async getServerInfo() { async getServerInfo() {
@ -16,4 +19,13 @@ export class ServerInfoController {
res: 'pong', res: 'pong',
}; };
} }
@UseGuards(JwtAuthGuard)
@Get('/mapbox')
async getMapboxInfo(@GetAuthUser() authUser: AuthUserDto) {
return {
isEnable: this.configService.get('ENABLE_MAPBOX'),
mapboxSecret: this.configService.get('MAPBOX_KEY'),
};
}
} }

View file

@ -11,5 +11,11 @@ export const immichAppConfig: ConfigModuleOptions = {
DB_DATABASE_NAME: Joi.string().required(), DB_DATABASE_NAME: Joi.string().required(),
UPLOAD_LOCATION: Joi.string().required(), UPLOAD_LOCATION: Joi.string().required(),
JWT_SECRET: Joi.string().required(), JWT_SECRET: Joi.string().required(),
ENABLE_MAPBOX: Joi.boolean().required().valid(true, false),
MAPBOX_KEY: Joi.any().when('ENABLE_MAPBOX', {
is: true,
then: Joi.string().required(),
otherwise: Joi.string().optional,
}),
}), }),
}; };