import { Injectable , Inject } from '@nestjs/common' ; import { StorageOptions } from './interfaces' ; import { StorageDriver } from './interfaces' ; import { DriverManager } from './driverManager' ; import { STORAGE_OPTIONS } from './constants' ; @ Injectable ( ) export class StorageService { private static diskDrivers : { [ key ] : any ; } ; private static options : StorageOptions ; private static driverManager : DriverManager ; constructor ( @ Inject ( STORAGE_OPTIONS ) options ) { StorageService . options = options ; StorageService . diskDrivers = { } ; StorageService . driverManager = new DriverManager ( ) ; } static getDriver ( disk ) { if ( StorageService . diskDrivers [ disk ] ) { return StorageService . diskDrivers [ disk ] ; } const driver = StorageService . newDriver ( disk ) ; StorageService . diskDrivers [ disk ] = driver ; return driver ; } static newDriver ( disk ) { return StorageService . driverManager . getDriver ( disk , StorageService . options . disks [ disk ] ) ; } }