import { inject , injectable } from 'inversify' ; import * as path from 'path' ; import * as apid from '../../../../api' ; import FileUtil from '../../../util/FileUtil' ; import IDropLogFileDB from '../../db/IDropLogFileDB' ; import IConfigFile from '../../IConfigFile' ; import IConfiguration from '../../IConfiguration' ; import IDropLogApiModel , { DropLogApiErrors } from './IDropLogApiModel' ; @ injectable ( ) export default class DropLogApiModel implements IDropLogApiModel { private config : IConfigFile ; private dropLogFileDB : IDropLogFileDB ; constructor ( @ inject ( 'IConfiguration' ) configuration , @ inject ( 'IDropLogFileDB' ) dropLogFileDB ) { this . dropLogFileDB = dropLogFileDB ; this . config = configuration . getConfig ( ) ; } param dropLogFileId param maxSize return public async getIdFilePath ( dropLogFileId , maxSize ) { const dropLogFile = await this . dropLogFileDB . findId ( dropLogFileId ) ; if ( dropLogFile === null ) { return null ; } const filePath = path . join ( this . config . dropLog , dropLogFile . filePath ) ; const fileSize = await FileUtil . getFileSize ( filePath ) ; if ( fileSize > maxSize * 1024 ) { throw new Error ( DropLogApiErrors . FILE_IS_TOO_LARGE ) ; } return filePath ; } }