@@ -1252,98 +1252,76 @@ protected String getStreamsDirectory(String appScopeName) {
12521252 return String .format ("%s/webapps/%s/%s" , System .getProperty ("red5.root" ), appScopeName , "streams" );
12531253 }
12541254
1255- protected Result uploadVoDFile (String fileName , InputStream inputStream ) {
1256- boolean success = false ;
1257- String message = "" ;
1258- String id = null ;
1255+ public Result uploadVoDFile (String fileName , InputStream inputStream ) {
1256+ return uploadVoDFile (fileName , inputStream , null );
1257+ }
1258+
1259+ public Result uploadVoDFile (String fileName , InputStream inputStream , String metadata ) {
1260+ String id = null ;
12591261 String appScopeName = getScope ().getName ();
12601262 String fileExtension = FilenameUtils .getExtension (fileName );
1261- try {
1262-
1263- String [] supportedFormats = new String [] {"mp4" , "webm" , "mov" , "avi" , "mp3" , "wmv" };
1264-
1265- if (ArrayUtils .contains (supportedFormats , fileExtension )) {
1266-
1267-
1268- IStatsCollector statsCollector = (IStatsCollector ) getAppContext ().getBean (IStatsCollector .BEAN_NAME );
1269- String vodUploadFinishScript = getAppSettings ().getVodUploadFinishScript ();
1270- if (StringUtils .isNotBlank (vodUploadFinishScript ) && !statsCollector .enoughResource ())
1271- {
1272- logger .info ("Not enough resource to upload VoD file" );
1273- message = "Not enough system resources available to upload and process VoD File" ;
1274- }
1275- else
1276- {
1277-
1278- File streamsDirectory = new File (
1279- getStreamsDirectory (appScopeName ));
1280-
1281- // if the directory does not exist, create it
1282- if (!streamsDirectory .exists ()) {
1283- streamsDirectory .mkdirs ();
1284- }
1285- String vodId = RandomStringUtils .secure ().nextNumeric (24 );
1286-
1287-
1288- File savedFile = new File (streamsDirectory , vodId + "." + fileExtension );
1289-
1290- if (!savedFile .toPath ().normalize ().startsWith (streamsDirectory .toPath ().normalize ())) {
1291- throw new IOException ("Entry is outside of the target directory" );
1292- }
1293-
1294- int read = 0 ;
1295- byte [] bytes = new byte [2048 ];
1296- try (OutputStream outpuStream = new FileOutputStream (savedFile ))
1297- {
1298-
1299- while ((read = inputStream .read (bytes )) != -1 ) {
1300- outpuStream .write (bytes , 0 , read );
1301- }
1302- outpuStream .flush ();
1263+
1264+ String [] supportedFormats = new String [] {"mp4" , "webm" , "mov" , "avi" , "mp3" , "wmv" };
1265+ if (!ArrayUtils .contains (supportedFormats , fileExtension )) {
1266+ //this message has been used in the frontend(webpanel) pay attention
1267+ return new Result (false , null , "notSupportedFileType" );
1268+ }
13031269
1304- long fileSize = savedFile .length ();
1305- long unixTime = System .currentTimeMillis ();
1270+ IStatsCollector statsCollector = (IStatsCollector ) getAppContext ().getBean (IStatsCollector .BEAN_NAME );
1271+ String vodUploadFinishScript = getAppSettings ().getVodUploadFinishScript ();
1272+ if (StringUtils .isNotBlank (vodUploadFinishScript ) && !statsCollector .enoughResource ()) {
1273+ logger .info ("Not enough resource to upload VoD file" );
1274+ return new Result (false , null , "Not enough system resources available to upload and process VoD File" );
1275+ }
13061276
1307- String path = savedFile .getPath ();
1277+ try {
1278+ File streamsDirectory = new File (getStreamsDirectory (appScopeName ));
1279+ if (!streamsDirectory .exists ()) {
1280+ streamsDirectory .mkdirs ();
1281+ }
13081282
1283+ String vodId = RandomStringUtils .secure ().nextNumeric (24 );
1284+ File savedFile = new File (streamsDirectory , vodId + "." + fileExtension );
13091285
1310- String relativePath = AntMediaApplicationAdapter .getRelativePath (path );
1286+ if (!savedFile .toPath ().normalize ().startsWith (streamsDirectory .toPath ().normalize ())) {
1287+ throw new IOException ("Entry is outside of the target directory" );
1288+ }
13111289
1312- VoD newVod = new VoD (fileName , "file" , relativePath , fileName , unixTime , 0 , Muxer .getDurationInMs (savedFile ,fileName ), fileSize ,
1313- VoD .UPLOADED_VOD , vodId , null );
1290+ int read = 0 ;
1291+ byte [] bytes = new byte [2048 ];
1292+ try (OutputStream outpuStream = new FileOutputStream (savedFile )) {
1293+ while ((read = inputStream .read (bytes )) != -1 ) {
1294+ outpuStream .write (bytes , 0 , read );
1295+ }
1296+ outpuStream .flush ();
13141297
1315- if ( StringUtils . isNotBlank ( vodUploadFinishScript )) {
1316- newVod . setProcessStatus ( VoD . PROCESS_STATUS_INQUEUE );
1317- }
1298+ long fileSize = savedFile . length ();
1299+ long unixTime = System . currentTimeMillis ( );
1300+ String relativePath = AntMediaApplicationAdapter . getRelativePath ( savedFile . getPath ());
13181301
1319- id = getDataStore ().addVod (newVod );
1302+ VoD newVod = new VoD (fileName , "file" , relativePath , fileName , unixTime , 0 ,
1303+ Muxer .getDurationInMs (savedFile , fileName ), fileSize , VoD .UPLOADED_VOD , vodId , null );
13201304
1321- if ( id != null ) {
1322- success = true ;
1323- message = id ;
1305+ if ( StringUtils . isNotBlank ( metadata ) ) {
1306+ newVod . setMetadata ( metadata ) ;
1307+ }
13241308
1325- if (StringUtils .isNotBlank (vodUploadFinishScript ))
1326- {
1327- startVoDScriptProcess ( vodUploadFinishScript , savedFile , newVod , id );
1309+ if (StringUtils .isNotBlank (vodUploadFinishScript )) {
1310+ newVod . setProcessStatus ( VoD . PROCESS_STATUS_INQUEUE );
1311+ }
13281312
1329- }
1313+ id = getDataStore (). addVod ( newVod );
13301314
1331- }
1332- }
1315+ if ( id != null && StringUtils . isNotBlank ( vodUploadFinishScript )) {
1316+ startVoDScriptProcess ( vodUploadFinishScript , savedFile , newVod , id );
13331317 }
13341318 }
1335- else {
1336- //this message has been used in the frontend(webpanel) pay attention
1337- message = "notSupportedFileType" ;
1338- }
1339-
1340- }
1341- catch (IOException iox ) {
1319+ } catch (IOException iox ) {
13421320 logger .error (iox .getMessage ());
1321+ return new Result (false , null , "" );
13431322 }
13441323
1345-
1346- return new Result (success , id , message );
1324+ return new Result (id != null , id , id != null ? id : "" );
13471325 }
13481326
13491327 public void startVoDScriptProcess (String vodUploadFinishScript , File savedFile , VoD newVod , String vodId ) {
0 commit comments