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