import { inject , injectable } from 'inversify' ; import * as apid from '../../../../../api' ; import IEncodeApiModel from '../../api/encode/IEncodeApiModel' ; import IServerConfigModel from '../../serverConfig/IServerConfigModel' ; import { IAddEncodeSettingStorageModel } from '../../storage/encode/IAddEncodeSettingStorageModel' ; import IAddEncodeState from './IAddEncodeState' ; @ injectable ( ) export default class AddEncodeState implements IAddEncodeState { public videoFileId : apid . VideoFileId | null = null ; public encodeMode : string | null = null ; public parentDirectory : string | null = null ; public directory : string | null = null ; private serverConfig : IServerConfigModel ; private encodeApiModel : IEncodeApiModel ; private setting : IAddEncodeSettingStorageModel ; private videoFiles : apid . VideoFile [ ] = [ ] ; private recordedId : apid . RecordedId | null = null ; constructor ( @ inject ( 'IServerConfigModel' ) serverConfig , @ inject ( 'IEncodeApiModel' ) encodeApiModel , @ inject ( 'IAddEncodeSettingStorageModel' ) setting ) { this . serverConfig = serverConfig ; this . encodeApiModel = encodeApiModel ; this . setting = setting ; } param recordedId param videoFiles param encodeMode param parentDirectory public init ( recordedId , videoFiles , encodeMode , parentDirectory ) { this . recordedId = recordedId ; this . videoFileId = null ; this . directory = null ; this . videoFiles = videoFiles ; if ( this . videoFiles . length > 0 ) { this . videoFileId = this . videoFiles [ 0 ] . id ; } const encodeList = this . getEncodeList ( ) ; if ( encodeList . length > 0 ) { this . encodeMode = null ; for ( const e of encodeList ) { if ( e === encodeMode ) { this . encodeMode = e ; break ; } } if ( this . encodeMode === null ) { this . encodeMode = encodeList [ 0 ] ; } } const parendDirList = this . getParentDirectoryList ( ) ; if ( parendDirList . length > 0 ) { this . parentDirectory = null ; for ( const d of parendDirList ) { if ( d === parentDirectory ) { this . parentDirectory = d ; break ; } } if ( this . parentDirectory === null ) { this . parentDirectory = parendDirList [ 0 ] ; } } } return { * public getVideoFiles ( ) { return this . videoFiles . map ( v => { return { text : v . name , value : v . id , } ; } ) ; } return public getEncodeList ( ) { const config = this . serverConfig . getConfig ( ) ; return config === null ? [ ] : config . encode ; } return public getParentDirectoryList ( ) { const config = this . serverConfig . getConfig ( ) ; return config === null ? [ ] : config . recorded ; } /**
     * エンコード追加
     */ public async addEncode ( ) { if ( this . recordedId === null || this . videoFileId === null || this . encodeMode === null ) { throw new Error ( 'OptionError' ) ; } const option = { recordedId : this . recordedId , sourceVideoFileId : this . videoFileId , mode : this . encodeMode , removeOriginal : this . setting . tmp . removeOriginal , } ; if ( this . setting . tmp . isSaveSameDirectory === true ) { option . isSaveSameDirectory = true ; } else { if ( this . parentDirectory === null ) { throw new Error ( 'ParentDirectoryIsNull' ) ; } option . parentDir = this . parentDirectory ; if ( this . directory !== null ) { option . directory = this . directory ; } } await this . encodeApiModel . addEncode ( option ) ; } }