import diskusage from 'diskusage-ng' ; import { inject , injectable } from 'inversify' ; import * as apid from '../../../../api' ; import IConfigFile from '../../IConfigFile' ; import IConfiguration from '../../IConfiguration' ; import IStorageApiModel from './IStorageApiModel' ; @ injectable ( ) export default class StorageApiModel implements IStorageApiModel { private config : IConfigFile ; constructor ( @ inject ( 'IConfiguration' ) configuration ) { this . config = configuration . getConfig ( ) ; } return public async getInfo ( ) { const items = [ ] ; for ( const r of this . config . recorded ) { const info = await this . getDiskInfo ( r . path ) ; ( info as apid . StorageItem ) . name = r . name ; items . push ( info as apid . StorageItem ) ; } return { items : items , } ; } param dirPath private getDiskInfo ( dirPath ) { return new Promise < apid . DiskUsage > ( ( resolve , reject ) => { diskusage ( dirPath , ( err , usage ) => { if ( err ) { reject ( err ) ; } else { resolve ( { available : usage . available , used : usage . used , total : usage . total , } ) ; } } ) ; } ) ; } }