Browse Source

submit code

zhouxianguang 6 years ago
parent
commit
3e43f69744

+ 6 - 0
.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="JavaScriptSettings">
+    <option name="languageLevel" value="ES6" />
+  </component>
+</project>

+ 0 - 40
CourseDown.js

@@ -1,40 +0,0 @@
-var fs = require('fs');
-var logHelper = require("./helper/LjLogHelper.js");
-var fileHelper = require("./helper/LjFileHelper");
-
-/**
- * The course down
- */
-class CourseDown
-{
-    static downCourse(lessonJsonObj,callBack)
-    {
-        /*课件-Begin*/
-        //课程集合
-        var courseList = lessonJsonObj.data.list;
-        //课程数
-        var courseListSize = courseList.length;
-        //遍历课件
-        for (var i = 0; i < courseListSize; i++)
-        {
-            logHelper.debug(courseList[i].title);
-            //资源集合
-            var resourceList = courseList[i].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)
-            }
-        }
-        /*课件-End*/
-        logHelper.info("Succeed to down lesson【"+lessonJsonObj.data.title+"】");
-        callBack();
-    }
-}
-
-module.exports = CourseDown;

+ 6 - 90
app.js

@@ -1,98 +1,14 @@
-var http = require('http');
-var request = require('request');
-var fs = require('fs');
-var url = require('url');
-var ljConst = require("./const/LjConst.js");
-var CourseDown = require("./CourseDown");
-var async = require("async");
-
-var express = require('express');
+var express = require('express');
 var app = express();
-
+var router = express.Router();
 //引入工具类
 var logHelper = require("./helper/LjLogHelper.js");
-var httpHelper = require("./helper/LjHttpHelper");
-var fileHelper = require("./helper/LjFileHelper");
-var apiHelper = require("./helper/LjApiHelper");
-var ljStringHelper = require("./helper/LjStringHelper");
-
-var videoUrl1 = 'https://efunvideo.ai160.com/vs2m/001/00101002/00101002002/00101002002.m3u8';
-var videoUrl2 = 'https://efunvideo.ai160.com/vs2m/801/C-01-01-0004/J-03-02-000365/J-03-02-000365.m3u8';
-var imgUrl = 'https://efunimgs.ai160.com/resources/J/02/01/500001.jpg';
-
-//downloadFile(videoUrl1);
-//downloadFile(videoUrl2);
-//fileHelper.downloadFile(imgUrl);
-
-var result = JSON.parse(fs.readFileSync("./lessonInfo.json"));
-CourseDown.downCourse(result,function()
-{
-    console.info("周现广");
-});
 
-
-/**
- * 下载
- */
-app.get('/down.do', function (req, res)
-{
-    var arg = url.parse(req.url, true).query;
-    var courseId = arg.courseId;
-    var eid = arg.eid;
-    var uid = arg.uid;
-    var token = arg.token;
-    var lessonId = arg.lessonId;
-    //获取参数
-    logHelper.info(arg);
-
-    //校验参数
-    if (ljStringHelper.isNull(courseId))
-    {
-        logHelper.info("null object of courseId");
-        return "null object of courseId";
-    }
-    if (ljStringHelper.isNull(lessonId))
-    {
-        logHelper.info("null object of lessonId");
-        return "null object of courseId";
-    }
-    if (ljStringHelper.isNull(eid))
-    {
-        logHelper.info("null object of eid");
-        return "null object of eid";
-    }
-    if (ljStringHelper.isNull(uid))
-    {
-        logHelper.info("null object of uid");
-        return "null object of uid";
-    }
-    if (ljStringHelper.isNull(token))
-    {
-        logHelper.info("null object of token");
-        return "null object of token";
-    }
-
-    var opt = {};
-    opt.eid = "100166681101003";
-    opt.uid = "100166681101001";
-    opt.token = token;
-    opt.lessonId = "02279ace371a11e8af2000163e08bde8";
-    courseId = "02549160371e11e88c3600163e08bde8";
-    opt.url = apiHelper.getApiForCourse(lessonId, courseId, eid);
-
-    httpHelper.request(opt, function (error, res, body)
-    {
-        logHelper.info(body);
-        let obj = JSON.parse(body);
-        logHelper.info(obj.code);
-
-        var result = JSON.parse(body);
-        CourseDown.downCourse(result);
-    });
-});
+//根据不同的功能划分模块
+app.use('/lesson', require('./router/lesson'))
 
 //启动监听
-app.listen(9095, function ()
+app.listen(8089, function ()
 {
-    logHelper.info("winBoxNode starting success");
+    logHelper.info("WinBoxNode starting success");
 });

BIN
audio.json


+ 10 - 0
common/LjConst.js

@@ -0,0 +1,10 @@
+const constBase = {
+    BASE_DIR:'c:\\efunbox\\',
+    VIDEO_TYPE_M3U8 : 'm3u8',
+    VIDEO_TYPE_MP4 : 'mp4',
+    RES_TYPE_AUDIO : 4,
+    RES_TYPE_IMAGE : 3,
+    RES_TYPE_VIDEO : 0
+}
+
+module.exports = constBase;

+ 8 - 0
common/LjRetState.js

@@ -0,0 +1,8 @@
+var ljRetState =
+    {
+        code: 200,
+        msg: "",
+        data: {}
+    }
+
+module.exports = ljRetState;

+ 0 - 12
const/LjConst.js

@@ -1,12 +0,0 @@
-const constBase = {
-    BASE_DIR:'c:\\efunbox\\',
-    VIDEO_TYPE_M3U8 : '',
-    VIDEO_TYPE_MP4 : ''
-}
-
-const constApi = {
-    GET_COURSE_WARE_LIST_BY_LESSON_ID:'http://tt-web.api.ai160.com/lesson/02279ace371a11e8af2000163e08bde8?courseId=02549160371e11e88c3600163e08bde8&eid=100166681101002&cache=true'
-}
-
-module.exports.constBase = constBase;
-module.exports.constApi = constApi;

+ 27 - 4
helper/LjApiHelper.js

@@ -6,8 +6,14 @@ var cryptoJS = require("crypto-js");
  */
 class LjApiHelper
 {
-    //获取课程信息
-    static getApiForCourse(lessonId, courseId, eid)
+    /**
+     * Gets the API for query course
+     * @param lessonId the lesson id
+     * @param courseId the course id
+     * @param eid the eid
+     * @returns {string} the API url
+     */
+    static getApiForQueryCourse(lessonId, courseId, eid)
     {
         var http = "http://tt-web.api.ai160.com/lesson/" + lessonId;
         http += "?courseId=" + courseId
@@ -17,9 +23,26 @@ class LjApiHelper
         return http;
     }
 
-    static getApiForDown(lessonId)
+    /**
+     * Gets the API for add download
+     * @param lessonId the lesson id
+     * @param data the data
+     * @returns {string}
+     */
+    static getApiForAddDownload(lessonId,courseId,data)
     {
-        return "http://tt-web.api.ai160.com/callback/download/add?lessonId=" + lessonId;
+        return "http://tt-web.api.ai160.com/callback/download/add?lessonId=" + lessonId+"&courseId="+courseId+"&data="+data;
+    }
+
+    /**
+     * Gets the API for delete download
+     * @param lessonId the lesson id
+     * @param data the data
+     * @returns {string}
+     */
+    static getApiForDelDownload(lessonId,data)
+    {
+        return "http://tt-web.api.ai160.com/callback/download/delete?lessonId=" + lessonId+"&data="+data;
     }
 }
 

+ 87 - 33
helper/LjFileHelper.js

@@ -1,7 +1,7 @@
 var request = require('request');
 var fs = require('fs');
 var ffmpeg = require('fluent-ffmpeg');
-var ljConst = require("../const/LjConst.js");
+var ljConst = require("../common/LjConst.js");
 var path = require('path');
 var logHelper = require("./LjLogHelper");
 
@@ -23,15 +23,15 @@ class LjFileHelper
         {
             return false;
         }
-
+        console.info(filePropObj);
         //视频处理
-        if (filePropObj.fileType == ljConst.constBase.VIDEO_TYPE_M3U8)
+        if (filePropObj.fileType == ljConst.VIDEO_TYPE_M3U8)
         {
             //未加密视频本地存储路径
             var localFileDir = filePropObj.folderDir + filePropObj.fileName + ".mp4"
 
             //M3U8视频转换MP4
-            ffmpeg(fileUrl).format(ljConst.constBase.VIDEO_TYPE_MP4)
+            ffmpeg(fileUrl).format(ljConst.VIDEO_TYPE_MP4)
                 .on('start', function (err)
                 {
                     logHelper.info("Starting down video:" + fileUrl);
@@ -47,8 +47,8 @@ class LjFileHelper
                     logHelper.info("Succeeded to down video:" + localFileDirNew);
 
                     //加密存储
-                    this.writeEncryptedStream(localFileDir, localFileDirNew);
-                    console.info("Succeeded to encrypt video:" + localFileDirNew);
+                    LjFileHelper.writeEncryptedStream(localFileDir, localFileDirNew);
+                    logHelper.info("Succeeded to encrypt video:" + localFileDirNew);
 
                     //删除文件(加密存储完成后删除未加密文件)
                     fs.unlink(localFileDir, function (err)
@@ -82,7 +82,7 @@ class LjFileHelper
                 //加密图片
                 LjFileHelper.writeEncryptedStream(localFileDir, localFileDirNew);
 
-                logHelper.info("Succeeded to image video:" + localFileDirNew);
+                logHelper.info("Succeeded to image image:" + localFileDirNew);
 
                 //删除文件(加密存储完成后删除未加密文件)
                 fs.unlink(localFileDir, function (err)
@@ -103,6 +103,64 @@ class LjFileHelper
     }
 
     /**
+     * Delete file
+     * @param fileUrl the file url
+     * @returns {boolean}
+     */
+    static delFile(fileUrl)
+    {
+        //获取文件属性对象
+        var filePropObj = this.getFileProperty(fileUrl);
+        if (filePropObj == null)
+        {
+            return false;
+        }
+        //视频处理
+        if (filePropObj.fileType == ljConst.VIDEO_TYPE_M3U8)
+        {
+            //加密视频存储路径
+            let localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new" + ".mp4"
+            logHelper.info("Succeeded to down video:" + localFileDirNew);
+
+            //删除加密文件
+            fs.unlink(localFileDirNew, function (err)
+            {
+                if (err)
+                {
+                    //删除失败
+                    logHelper.info("Failed to delete video[" + err.message + "]:" + localFileDir);
+                    throw err;
+                }
+                else
+                {
+                    logHelper.info('Succeeded to delete video:' + localFileDir)
+                }
+            })
+        }//图片处理
+        else
+        {
+            //加密图片存储地址
+            var localFileDirNew = filePropObj.folderDir + filePropObj.fileName + "_new." + filePropObj.fileType;
+            logHelper.info("Succeeded to down image:" + localFileDirNew);
+
+            //删除加密文件
+            fs.unlink(localFileDirNew, function (err)
+            {
+                if (err)
+                {
+                    //删除失败
+                    logHelper.erro("Failed to delete image[" + err.message + "]:" + localFileDir);
+                    throw err;
+                }
+                else
+                {
+                    logHelper.info('Succeeded to delete image:' + localFileDir)
+                }
+            })
+        }
+    }
+
+    /**
      * Gets file directory
      * @param fileName the file name
      * @returns {*|string} the file directory
@@ -115,12 +173,12 @@ class LjFileHelper
         if (fileType == "m3u8")
         {
             fileName = fileName.replace(".m3u8", "_new.mp4")
-            newFileDir = constObj.baseDir + fileName.replace(/\*/g, '\\');
+            newFileDir = ljConst.BASE_DIR + fileName.replace(/\*/g, '\\');
         }
         else
         {
             fileName = fileName.replace(".", "_new.")
-            newFileDir = constObj.baseDir + fileName.replace(/\*/g, '\\');
+            newFileDir = ljConst.BASE_DIR + fileName.replace(/\*/g, '\\');
         }
 
         return newFileDir;
@@ -154,32 +212,28 @@ class LjFileHelper
      */
     static getFileProperty(fileUrl)
     {
-        if (fileUrl.startsWith("https://efunimgs.ai160.com") || fileUrl.startsWith("https://efunvideo.ai160.com"))
-        {
-            /*--文件夹目录-Begin--*/
-            var folderDir = ljConst.constBase.BASE_DIR;
+        /*--文件夹目录-Begin--*/
+        var folderDir = ljConst.BASE_DIR;
 
-            var splitArr = fileUrl.split('/')
-            var arrLen = splitArr.length;
-            for (var i = 3; i < arrLen - 1; i++)
-            {
-                folderDir += splitArr[i] + "\\";
-            }
-            //创建文件夹目录
-            this.mkdirsSync(folderDir);
-
-            var filePropObj = {};
-            filePropObj.folderDir = folderDir;
-            //获取文件名称
-            filePropObj.fileName = splitArr[arrLen - 1].split(".")[0];
-            //获取文件类型
-            filePropObj.fileType = splitArr[arrLen - 1].split(".")[1];
-            /*--文件夹目录-Begin--*/
-
-            return filePropObj;
+        var splitArr = fileUrl.split('/')
+        var arrLen = splitArr.length;
+        for (var i = 3; i < arrLen - 1; i++)
+        {
+            folderDir += splitArr[i] + "\\";
         }
+        //创建文件夹目录
+        this.mkdirsSync(folderDir);
+
+        var filePropObj = {};
+        filePropObj.folderDir = folderDir;
+        //获取文件名称
+        filePropObj.fileName = splitArr[arrLen - 1].split(".")[0];
+        //获取文件类型
+        filePropObj.fileType = splitArr[arrLen - 1].split(".")[1];
+        /*--文件夹目录-Begin--*/
+
+        return filePropObj;
 
-        return null;
     }
 
     static Encrypted(c)
@@ -369,7 +423,7 @@ class LjFileHelper
             let b = new Buffer(chunk, 'hex');
 
             let c = b.toString('hex');
-            c = decryptedContent(c);
+            c = LjFileHelper.decryptedContent(c);
 
             let d = Buffer.from(c, 'hex');
 

+ 15 - 14
helper/LjHttpHelper.js

@@ -1,33 +1,34 @@
 var request = require('request');
 var cryptoJS = require("crypto-js");
 var logHelper = require("./LjLogHelper");
+var uuid = require('node-uuid');
 
 /**
  * The helper of http
  */
 class LjHttpHelper
 {
-    static request(optinons,callback)
+    static request(optinons, callback)
     {
         //签名
-        const signStr = 'path='+optinons.url+'&uid='+optinons.uid+'&eid='+optinons.eid+'&'+optinons.token;
-        const sign = cryptoJS.MD5(signStr).toString();
+        var signStr = 'path=' + optinons.path + '&uid=' + optinons.uid + '&eid=' + optinons.eid + '&' + optinons.token;
+        var sign = cryptoJS.MD5(signStr).toString();
 
-        logHelper.info(optinons);
-        let headers = {
-            'Content-Type':'application/json',
-            'eid':optinons.eid,
-            'uid':optinons.uid,
-            'sign':sign,
-            'terminal':"web",
-            'merchant':"angelbell",
-            'requestId':"11111111111111",
+        var headers = {
+            'Content-Type': 'application/json',
+            'eid': optinons.eid,
+            'uid': optinons.uid,
+            'sign': sign,
+            'terminal': "web",
+            'merchant': "angelbell",
+            'requestId': uuid.v1(),
         };
 
-        let optionsObj = {};
+        var optionsObj = {};
         optionsObj.url = optinons.url;
         optionsObj.headers = headers;
-        logHelper.info(optionsObj);
+        optionsObj.method = optinons.method;
+
         request(optionsObj, callback);
     }
 }

+ 1 - 0
helper/LjStringHelper.js

@@ -29,6 +29,7 @@ class LjStringHelper
 
         return false;
     }
+
 }
 
 module.exports = LjStringHelper;

File diff suppressed because it is too large
+ 5529 - 0
logs/info.log


+ 2 - 2
node_modules/.bin/uuid

@@ -6,10 +6,10 @@ case `uname` in
 esac
 
 if [ -x "$basedir/node" ]; then
-  "$basedir/node"  "$basedir/../uuid/bin/uuid" "$@"
+  "$basedir/node"  "$basedir/../node-uuid/bin/uuid" "$@"
   ret=$?
 else 
-  node  "$basedir/../uuid/bin/uuid" "$@"
+  node  "$basedir/../node-uuid/bin/uuid" "$@"
   ret=$?
 fi
 exit $ret

+ 2 - 2
node_modules/.bin/uuid.cmd

@@ -1,7 +1,7 @@
 @IF EXIST "%~dp0\node.exe" (
-  "%~dp0\node.exe"  "%~dp0\..\uuid\bin\uuid" %*
+  "%~dp0\node.exe"  "%~dp0\..\node-uuid\bin\uuid" %*
 ) ELSE (
   @SETLOCAL
   @SET PATHEXT=%PATHEXT:;.JS;=;%
-  node  "%~dp0\..\uuid\bin\uuid" %*
+  node  "%~dp0\..\node-uuid\bin\uuid" %*
 )

+ 1 - 0
node_start.bat

@@ -0,0 +1 @@
+node C:\John\WorkSpace\WebStorm\WinBoxNode\app.js

+ 5 - 0
package-lock.json

@@ -509,6 +509,11 @@
       "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
       "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk="
     },
+    "node-uuid": {
+      "version": "1.4.8",
+      "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.8.tgz",
+      "integrity": "sha1-sEDrCSOWivq/jTL7HxfxFn/auQc="
+    },
     "oauth-sign": {
       "version": "0.8.2",
       "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz",

+ 1 - 0
package.json

@@ -17,6 +17,7 @@
     "express": "^4.16.3",
     "fluent-ffmpeg": "^2.1.2",
     "log4js": "^3.0.3",
+    "node-uuid": "^1.4.8",
     "request": "^2.87.0"
   }
 }

+ 305 - 0
router/lesson.js

@@ -0,0 +1,305 @@
+var express = require('express');
+var url = require('url');
+var router = express.Router();
+
+var ljConst =  require("../common/LjConst");
+var ljRetState =  require("../common/LjRetState");
+
+var logHelper = require("../helper/LjLogHelper.js");
+var httpHelper = require("../helper/LjHttpHelper");
+var fileHelper = require("../helper/LjFileHelper");
+var apiHelper = require("../helper/LjApiHelper");
+var ljStringHelper = require("../helper/LjStringHelper");
+
+/**
+ * 下载文件
+ */
+router.get("/downloadFile",function(req,res,next)
+{
+    var arg = url.parse(req.url, true).query;
+    var courseId = arg.courseId;
+    var eid = arg.eid;
+    var uid = arg.uid;
+    var token = arg.token;
+    var lessonId = arg.lessonId;
+    //获取参数
+    logHelper.debug(arg);
+
+    //校验参数
+    if (ljStringHelper.isNull(courseId))
+    {
+        logHelper.info("null object of courseId");
+
+        ljRetState.code = 2;
+        ljRetState.msg ="null object of courseId"
+        res.json(ljRetState);
+
+        return;
+    }
+    if (ljStringHelper.isNull(lessonId))
+    {
+        logHelper.info("null object of lessonId");
+
+        ljRetState.code = 2;
+        ljRetState.msg ="null object of lessonId"
+        res.json(ljRetState);
+
+        return;
+    }
+    if (ljStringHelper.isNull(eid))
+    {
+        logHelper.info("null object of eid");
+
+        ljRetState.code = 2;
+        ljRetState.msg ="null object of eid"
+        res.json(ljRetState);
+
+        return;
+    }
+    if (ljStringHelper.isNull(uid))
+    {
+        logHelper.info("null object of uid");
+
+        ljRetState.code = 2;
+        ljRetState.msg ="null object of uid"
+        res.json(ljRetState);
+
+        return;
+    }
+    if (ljStringHelper.isNull(token))
+    {
+        logHelper.info("null object of token");
+
+        ljRetState.code = 2;
+        ljRetState.msg ="null object of token"
+        res.json(ljRetState);
+
+        return;
+    }
+
+    var opt = {};
+    opt.eid = eid;
+    opt.uid = uid;
+    opt.token = token;
+    opt.lessonId = lessonId;
+    opt.courseId = courseId;
+    opt.path = "/lesson/" + opt.lessonId;
+    opt.url = apiHelper.getApiForQueryCourse(opt.lessonId, opt.courseId, opt.eid);
+    opt.method = "get";
+
+    httpHelper.request(opt, function (error, res, body)
+    {
+        let obj = JSON.parse(body);
+
+        var lessonJsonObj = JSON.parse(body);
+        if (lessonJsonObj.code == 200)
+        {
+            /*课件-Begin*/
+            //课程集合
+            var courseList = lessonJsonObj.data.list;
+            //课程数
+            var courseListSize = courseList.length;
+            //遍历课件
+            for (var i = 0; i < courseListSize; i++)
+            {
+                //资源集合
+                var resourceList = courseList[i].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)
+                }
+            }
+            /*课件-End*/
+
+            //保存记录
+            //addDownload(opt)
+
+            return "ok";
+        }
+        else
+        {
+            logHelper.error("failed to query lesson with lessonId[" + opt.lessonId + "],caused by error:" + lessonJsonObj);
+            return "error";
+        }
+    }).on("end",function()
+    {
+        test();
+    });
+
+
+});
+
+/**
+ * 读取文件
+ */
+router.get("/readFile",function(req,res)
+{
+    var arg = url.parse(req.url, true).query;
+    var fileDirStr = arg.n;
+    var fileDirNew =  fileDirStr.replace(/\*/g,'\\');
+    
+    var fileDir =  fileHelper.getFileDir(fileDirNew)
+    var fileProp =  fileHelper.getFileProperty(fileDir);
+
+    if(fileProp.fileType == ljConst.VIDEO_TYPE_M3U8)
+    {
+        fileHelper.readDecryptedStream(res,fileDir,"video/mp4")
+    }
+    else
+    {
+        fileHelper.readDecryptedStream(res,fileDir,"image/jpeg")
+    }
+});
+function test()
+{
+    console.log(11);
+}
+/**
+ * 删除下载文件
+ */
+router.get("/delFile",function(req,res)
+{
+    var arg = url.parse(req.url, true).query;
+    var courseId = arg.courseId;
+    var eid = arg.eid;
+    var uid = arg.uid;
+    var token = arg.token;
+    var lessonId = arg.lessonId;
+    //获取参数
+    logHelper.debug(arg);
+
+    //校验参数
+    if (ljStringHelper.isNull(courseId))
+    {
+        logHelper.info("null object of courseId");
+        return "null object of courseId";
+    }
+    if (ljStringHelper.isNull(lessonId))
+    {
+        logHelper.info("null object of lessonId");
+        return "null object of courseId";
+    }
+    if (ljStringHelper.isNull(eid))
+    {
+        logHelper.info("null object of eid");
+        return "null object of eid";
+    }
+    if (ljStringHelper.isNull(uid))
+    {
+        logHelper.info("null object of uid");
+        return "null object of uid";
+    }
+    if (ljStringHelper.isNull(token))
+    {
+        logHelper.info("null object of token");
+        return "null object of token";
+    }
+
+    var opt = {};
+    opt.eid = eid;
+    opt.uid = uid;
+    opt.token = token;
+    opt.lessonId = lessonId;
+    opt.courseId = courseId;
+    opt.path = "/lesson/" + opt.lessonId;
+    opt.url = apiHelper.getApiForCourse(opt.lessonId, opt.courseId, opt.eid);
+    opt.method = "get";
+
+    httpHelper.request(opt, function (error, res, body)
+    {
+        let obj = JSON.parse(body);
+
+        var lessonJsonObj = JSON.parse(body);
+        if (lessonJsonObj.code == 200)
+        {
+            /*课件-Begin*/
+            //课程集合
+            var courseList = lessonJsonObj.data.list;
+            //课程数
+            var courseListSize = courseList.length;
+            //遍历课件
+            for (var i = 0; i < courseListSize; i++)
+            {
+                //资源集合
+                var resourceList = courseList[i].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)
+                }
+            }
+            /*课件-End*/
+
+            //保存记录
+            process.nextTick(addDownload);
+            return "ok";
+        }
+        else
+        {
+            logHelper.error("failed to query lesson with lessonId[" + opt.lessonId + "],caused by error:" + lessonJsonObj);
+            return "error";
+        }
+    });
+
+});
+
+var addDownload = function(opt)
+{
+    opt.url = apiHelper.getApiForAddDownload(opt.lessonId,opt.courseId, null);
+    opt.method = "post";
+    opt.path = "/callback/download/add";
+
+    httpHelper.request(opt, function (error, res, body)
+    {
+        var retObj = JSON.parse(body);
+        logHelper.debug(retObj);
+
+        if (retObj.code == 200)
+        {
+            logHelper.info("Succeed to call api[" + opt.path + "]");
+            return true;
+        }
+        else
+        {
+            logHelper.error("Failed to call api[" + opt.path + "],caused by error[" + retObj + "]");
+            return false;
+        }
+    });
+}
+
+var delDownload = function(opt)
+{
+    opt.url = apiHelper.getApiForDelDownload(opt.lessonId, null);
+    opt.method = "post";
+    opt.path = "/callback/download/delete";
+
+    httpHelper.request(opt, function (error, res, body)
+    {
+        var retObj = JSON.parse(body);
+        logHelper.debug(retObj);
+
+        if (retObj.code == 200)
+        {
+            logHelper.info("Succeed to call api[" + opt.path + "]");
+            return true;
+        }
+        else
+        {
+            logHelper.error("Failed to call api[" + opt.path + "],caused by error[" + retObj + "]");
+            return false;
+        }
+    });
+}
+
+module.exports = router;

node_register_service.bat → start.bat


+ 1 - 1
test/json.js

@@ -1,7 +1,7 @@
 var fs = require('fs');
 var logHelper = require("../helper/LjLogHelper.js");
 
-var lessonJsonObj = JSON.parse(fs.readFileSync("./lessonInfo.json"));
+var lessonJsonObj = JSON.parse(fs.readFileSync("./audio.json"));
 /*课件-Begin*/
 //课程集合
 var courseList = lessonJsonObj.data.list;

lessonInfo.json → video.json