Ver código fonte

支持有声读物下载

guozhaoshun 6 anos atrás
pai
commit
9a62132aab
3 arquivos alterados com 74 adições e 10 exclusões
  1. 1 0
      common/LjConst.js
  2. 33 0
      helper/LjFileHelper.js
  3. 40 10
      router/lesson.js

+ 1 - 0
common/LjConst.js

@@ -2,6 +2,7 @@ const constBase = {
     BASE_DIR:'c:\\efunbox\\',
     VIDEO_TYPE_M3U8 : 'm3u8',
     VIDEO_TYPE_MP4 : 'mp4',
+    VIDEO_TYPE_MP3 : 'mp3',
     RES_TYPE_AUDIO : 4,
     RES_TYPE_IMAGE : 3,
     RES_TYPE_VIDEO : 0

+ 33 - 0
helper/LjFileHelper.js

@@ -66,6 +66,39 @@ class LjFileHelper
                     })
                 })
                 .save(localFileDir);
+        }//有声读物处理
+        else if (filePropObj.fileType == ljConst.VIDEO_TYPE_MP3)
+        {
+            //未加密图片本地存储地址
+            var localFileDir = filePropObj.folderDir + filePropObj.fileName + "." + filePropObj.fileType;
+
+            //读取图片
+            request(fileUrl).pipe(fs.createWriteStream(localFileDir)).on('close', function ()
+            {
+                //加密图片存储地址
+                var localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new." + filePropObj.fileType;
+                logHelper.info("Succeeded to down audio:" + localFileDirNew);
+
+                //加密图片
+                LjFileHelper.writeEncryptedStream(localFileDir, localFileDirNew);
+
+                logHelper.info("Succeeded to image audio:" + localFileDirNew);
+
+                //删除文件(加密存储完成后删除未加密文件)
+                fs.unlink(localFileDir, function (err)
+                {
+                    if (err)
+                    {
+                        //删除失败
+                        logHelper.erro("Failed to delete audio[" + err.message + "]:" + localFileDir);
+                        throw err;
+                    }
+                    else
+                    {
+                        logHelper.info('Succeeded to delete audio:' + localFileDir)
+                    }
+                })
+            });
         }//图片处理
         else
         {

+ 40 - 10
router/lesson.js

@@ -102,18 +102,48 @@ router.get("/downloadFile",function(req,res,next)
             //遍历课件
             for (var i = 0; i < courseListSize; i++)
             {
-                //资源集合
-                var resourceList = courseList[i].list;
+                var lessonware = courseList[i];
+                if(lessonware.type == ljConst.RES_TYPE_IMAGE || lessonware.type == ljConst.RES_TYPE_VIDEO){
+                    //资源集合
+                    var resourceList = lessonware.list;
+
+                    //资源数
+                    var resourceSize = resourceList.length;
+
+                    for (var j = 0; j < resourceSize; j++)
+                    {
+                        logHelper.debug(resourceList[j].url);
+                        var url = resourceList[j].url;
+                        fileHelper.downloadFile(url)
+                    }
+                }else if(lessonware.type == ljConst.RES_TYPE_AUDIO){
+                    //有声资源集合
+                    var audioResourceList = lessonware.list;
+                    //资源数
+                    var resourceSize = audioResourceList.length;
+
+                    for (var j = 0; j < resourceSize; j++)
+                    {
+                        var img = audioResourceList[j].img;
+                        var audio = audioResourceList[j].audio;
+
+                        logHelper.debug(img);
+                        logHelper.debug(audio);
+                        var imgUrl = img.url;
+                        var audioUrl = audio.url;
+
+                        if(ljStringHelper.isNonNull(imgUrl)){
+                            fileHelper.downloadFile(imgUrl);
+                        }
+                        if(ljStringHelper.isNonNull(audioUrl)){
+                            fileHelper.downloadFile(audioUrl);
+                        }
+                    }
 
-                //资源数
-                var resourceSize = resourceList.length;
-
-                for (var j = 0; j < resourceSize; j++)
-                {
-                    logHelper.debug(resourceList[j].url);
-                    var url = resourceList[j].url;
-                    fileHelper.downloadFile(url)
                 }
+
+
+
             }
             /*课件-End*/