|
@@ -21,7 +21,7 @@ class LjFileHelper
|
|
|
*/
|
|
|
static downloadFile(fileUrl, opt)
|
|
|
{
|
|
|
- if(fileUrl == null || fileUrl=="")
|
|
|
+ if (fileUrl == null || fileUrl == "")
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
@@ -43,17 +43,17 @@ class LjFileHelper
|
|
|
ffmpeg(fileUrl).format(ljConst.VIDEO_TYPE_MP4)
|
|
|
.on('start', function (err)
|
|
|
{
|
|
|
- logHelper.info("【"+opt.lessonId+"】","Starting down video:" + fileUrl);
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", "Starting down video:" + fileUrl);
|
|
|
})
|
|
|
.on('error', function (err)
|
|
|
{
|
|
|
- logHelper.error("【"+opt.lessonId+"】","Failed to down video[" + fileUrl + "]: " + err.message);
|
|
|
+ logHelper.error("【" + opt.lessonId + "】", "Failed to down video[" + fileUrl + "]: " + err.message);
|
|
|
})
|
|
|
.on('end', function ()
|
|
|
{
|
|
|
//加密视频存储路径
|
|
|
let localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new" + ".mp4"
|
|
|
- logHelper.info("【"+opt.lessonId+"】","Succeeded to down video:" + localFileDirNew);
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", "Succeeded to down video:" + localFileDirNew);
|
|
|
|
|
|
//加密存储
|
|
|
LjFileHelper.writeEncryptedStream(localFileDir, localFileDirNew, function ()
|
|
@@ -61,20 +61,23 @@ class LjFileHelper
|
|
|
LjFileHelper.updateDownloadResSize(opt);
|
|
|
});
|
|
|
|
|
|
- //删除文件(加密存储完成后删除未加密文件)
|
|
|
- fs.unlink(localFileDir, function (err)
|
|
|
+ if (fs.existsSync(localFileDir))
|
|
|
{
|
|
|
- if (err)
|
|
|
- {
|
|
|
- //删除失败
|
|
|
- logHelper.error("【"+opt.lessonId+"】","Failed to delete video[" + err.message + "]:" + localFileDir);
|
|
|
- throw err;
|
|
|
- }
|
|
|
- else
|
|
|
+ //删除文件(加密存储完成后删除未加密文件)
|
|
|
+ fs.unlink(localFileDir, function (err)
|
|
|
{
|
|
|
- logHelper.info("【"+opt.lessonId+"】",'Succeeded to delete video:' + localFileDir)
|
|
|
- }
|
|
|
- })
|
|
|
+ if (err)
|
|
|
+ {
|
|
|
+ //删除失败
|
|
|
+ logHelper.error("【" + opt.lessonId + "】", "Failed to delete video[" + err.message + "]:" + localFileDir);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", 'Succeeded to delete video:' + localFileDir)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
})
|
|
|
.save(localFileDir);
|
|
|
}//有声读物处理
|
|
@@ -88,7 +91,7 @@ class LjFileHelper
|
|
|
{
|
|
|
//加密有声读物存储地址
|
|
|
var localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new." + filePropObj.fileType;
|
|
|
- logHelper.info("【"+opt.lessonId+"】","Succeeded to down audio:" + localFileDirNew);
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", "Succeeded to down audio:" + localFileDirNew);
|
|
|
|
|
|
//加密有声读物
|
|
|
LjFileHelper.writeEncryptedStream(localFileDir, localFileDirNew, function ()
|
|
@@ -107,20 +110,23 @@ class LjFileHelper
|
|
|
LjFileHelper.updateDownloadResSize(opt);
|
|
|
});
|
|
|
|
|
|
- //删除文件(加密存储完成后删除未加密文件)
|
|
|
- fs.unlink(localFileDir, function (err)
|
|
|
+ if (fs.existsSync(localFileDir))
|
|
|
{
|
|
|
- if (err)
|
|
|
- {
|
|
|
- //删除失败
|
|
|
- logHelper.erro("【"+opt.lessonId+"】","Failed to delete audio[" + err.message + "]:" + localFileDir);
|
|
|
- throw err;
|
|
|
- }
|
|
|
- else
|
|
|
+ //删除文件(加密存储完成后删除未加密文件)
|
|
|
+ fs.unlink(localFileDir, function (err)
|
|
|
{
|
|
|
- logHelper.info("【"+opt.lessonId+"】",'Succeeded to delete audio:' + localFileDir)
|
|
|
- }
|
|
|
- })
|
|
|
+ if (err)
|
|
|
+ {
|
|
|
+ //删除失败
|
|
|
+ logHelper.erro("【" + opt.lessonId + "】", "Failed to delete audio[" + err.message + "]:" + localFileDir);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", 'Succeeded to delete audio:' + localFileDir)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}//图片处理
|
|
|
else
|
|
@@ -133,41 +139,44 @@ class LjFileHelper
|
|
|
{
|
|
|
//加密图片存储地址
|
|
|
var localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new." + filePropObj.fileType;
|
|
|
- logHelper.info("【"+opt.lessonId+"】","Succeeded to down image:" + localFileDirNew);
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", "Succeeded to down image:" + localFileDirNew);
|
|
|
|
|
|
//加密图片
|
|
|
LjFileHelper.writeEncryptedStream(localFileDir, localFileDirNew, function ()
|
|
|
{
|
|
|
- /* //获取文件基本信息
|
|
|
- fs.stat(localFileDirNew, function (err, stats)
|
|
|
- {
|
|
|
- if (err == null)
|
|
|
- {
|
|
|
- //文件大小
|
|
|
- var fileSize = stats.size;
|
|
|
- LjFileHelper.updateDownloadResSize(opt);
|
|
|
-
|
|
|
- logHelper.info("Succeeded to encrypt image:" + localFileDirNew + " with file size[" + fileSize + "]");
|
|
|
- }
|
|
|
- });*/
|
|
|
+ /* //获取文件基本信息
|
|
|
+ fs.stat(localFileDirNew, function (err, stats)
|
|
|
+ {
|
|
|
+ if (err == null)
|
|
|
+ {
|
|
|
+ //文件大小
|
|
|
+ var fileSize = stats.size;
|
|
|
+ LjFileHelper.updateDownloadResSize(opt);
|
|
|
+
|
|
|
+ logHelper.info("Succeeded to encrypt image:" + localFileDirNew + " with file size[" + fileSize + "]");
|
|
|
+ }
|
|
|
+ });*/
|
|
|
LjFileHelper.updateDownloadResSize(opt);
|
|
|
});
|
|
|
|
|
|
|
|
|
- //删除文件(加密存储完成后删除未加密文件)
|
|
|
- fs.unlink(localFileDir, function (err)
|
|
|
+ if (fs.existsSync(localFileDir))
|
|
|
{
|
|
|
- if (err)
|
|
|
- {
|
|
|
- //删除失败
|
|
|
- logHelper.error("【"+opt.lessonId+"】","Failed to delete image[" + err.message + "]:" + localFileDir);
|
|
|
- throw err;
|
|
|
- }
|
|
|
- else
|
|
|
+ //删除文件(加密存储完成后删除未加密文件)
|
|
|
+ fs.unlink(localFileDir, function (err)
|
|
|
{
|
|
|
- logHelper.info("【"+opt.lessonId+"】",'Succeeded to delete image:' + localFileDir)
|
|
|
- }
|
|
|
- })
|
|
|
+ if (err)
|
|
|
+ {
|
|
|
+ //删除失败
|
|
|
+ logHelper.error("【" + opt.lessonId + "】", "Failed to delete image[" + err.message + "]:" + localFileDir);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", 'Succeeded to delete image:' + localFileDir)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -191,20 +200,23 @@ class LjFileHelper
|
|
|
//加密视频存储路径
|
|
|
let localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new" + ".mp4"
|
|
|
|
|
|
- //删除加密文件
|
|
|
- fs.unlink(localFileDirNew, function (err)
|
|
|
+ if (fs.existsSync(localFileDirNew))
|
|
|
{
|
|
|
- if (err)
|
|
|
- {
|
|
|
- //删除失败
|
|
|
- logHelper.info("Failed to delete video[" + err.message + "]:" + localFileDir);
|
|
|
- throw err;
|
|
|
- }
|
|
|
- else
|
|
|
+ //删除加密文件
|
|
|
+ fs.unlink(localFileDirNew, function (err)
|
|
|
{
|
|
|
- logHelper.info('Succeeded to delete video:' + localFileDir)
|
|
|
- }
|
|
|
- })
|
|
|
+ if (err)
|
|
|
+ {
|
|
|
+ //删除失败
|
|
|
+ logHelper.info("Failed to delete video[" + err.message + "]:" + localFileDir);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logHelper.info('Succeeded to delete video:' + localFileDir)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}//有声读物处理
|
|
|
else if (filePropObj.fileType == ljConst.VIDEO_TYPE_MP3)
|
|
|
{
|
|
@@ -217,20 +229,23 @@ class LjFileHelper
|
|
|
//加密有声读物存储地址
|
|
|
var localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new." + filePropObj.fileType;
|
|
|
|
|
|
- //删除文件(加密存储完成后删除未加密文件)
|
|
|
- fs.unlink(localFileDirNew, function (err)
|
|
|
+ if (fs.existsSync(localFileDirNew))
|
|
|
{
|
|
|
- if (err)
|
|
|
- {
|
|
|
- //删除失败
|
|
|
- logHelper.erro("【"+opt.lessonId+"】","Failed to delete audio[" + err.message + "]:" + localFileDir);
|
|
|
- throw err;
|
|
|
- }
|
|
|
- else
|
|
|
+ //删除文件(加密存储完成后删除未加密文件)
|
|
|
+ fs.unlink(localFileDirNew, function (err)
|
|
|
{
|
|
|
- logHelper.info("【"+opt.lessonId+"】",'Succeeded to delete audio:' + localFileDir)
|
|
|
- }
|
|
|
- })
|
|
|
+ if (err)
|
|
|
+ {
|
|
|
+ //删除失败
|
|
|
+ logHelper.erro("【" + opt.lessonId + "】", "Failed to delete audio[" + err.message + "]:" + localFileDir);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logHelper.info("【" + opt.lessonId + "】", 'Succeeded to delete audio:' + localFileDir)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}//图片处理
|
|
|
else
|
|
@@ -238,20 +253,23 @@ class LjFileHelper
|
|
|
//加密图片存储地址
|
|
|
var localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new." + filePropObj.fileType;
|
|
|
|
|
|
- //删除加密文件
|
|
|
- fs.unlink(localFileDirNew, function (err)
|
|
|
+ if (fs.existsSync(localFileDirNew))
|
|
|
{
|
|
|
- if (err)
|
|
|
- {
|
|
|
- //删除失败
|
|
|
- logHelper.erro("Failed to delete image[" + err.message + "]:" + localFileDir);
|
|
|
- throw err;
|
|
|
- }
|
|
|
- else
|
|
|
+ //删除加密文件
|
|
|
+ fs.unlink(localFileDirNew, function (err)
|
|
|
{
|
|
|
- logHelper.info('Succeeded to delete image:' + localFileDir)
|
|
|
- }
|
|
|
- })
|
|
|
+ if (err)
|
|
|
+ {
|
|
|
+ //删除失败
|
|
|
+ logHelper.erro("Failed to delete image[" + err.message + "]:" + localFileDir);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logHelper.info('Succeeded to delete image:' + localFileDir)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -340,7 +358,7 @@ class LjFileHelper
|
|
|
folderDir += splitArr[i] + "\\";
|
|
|
}
|
|
|
}
|
|
|
- else if(platform == "darwin")
|
|
|
+ else if (platform == "darwin")
|
|
|
{
|
|
|
for (var i = 3; i < arrLen - 1; i++)
|
|
|
{
|
|
@@ -368,7 +386,7 @@ class LjFileHelper
|
|
|
*/
|
|
|
static getFilePropertyNoMkdir(fileUrl)
|
|
|
{
|
|
|
- if(fileUrl == null)
|
|
|
+ if (fileUrl == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
@@ -385,7 +403,7 @@ class LjFileHelper
|
|
|
folderDir += splitArr[i] + "\\";
|
|
|
}
|
|
|
}
|
|
|
- else if(platform == "darwin")
|
|
|
+ else if (platform == "darwin")
|
|
|
{
|
|
|
for (var i = 3; i < arrLen - 1; i++)
|
|
|
{
|