-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashAirUtil.js
74 lines (69 loc) · 1.86 KB
/
flashAirUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var http = require("http");
var fs = require("fs");
var request = require("request-promise");
var basePathList = "/command.cgi?op=100&DIR=/DCIM/";
var optionsList = {
url: '',
method: 'GET',
resolveWithFullResponse: true
};
var optionsData = {
host: '',
path: '/DCIM/'
};
exports.getlist = (dirname, ipaddr) =>{
return new Promise(function(result, errRes){
var fileList = [];
console.log("getlist");
console.log(ipaddr);
optionsList.url = "http://" + ipaddr + basePathList + dirname;
console.log(ipaddr);
optionsData.host = ipaddr;
console.log(optionsList.url);
console.log(optionsData.host);
request(optionsList)
.then((res) => {
txtLine = res.body.split((/\r\n|\r|\n/));
txtLine.pop(); //最後の改行のみの行を削除
txtLine.shift();
txtLine.forEach(function(txt){
txtElement = txt.split(",");
fileList.push(txtElement[1]);
});
//console.log("FileList : " + fileList);
result(fileList);
})
.catch(function(err){
errRes(err);
});
});
};
exports.getdata = (dirname, path, fname) =>{
return new Promise(function(result, errRes){
optionsData.path = "/DCIM/" + dirname + "/" + fname;
console.log(optionsData);
var filename = "./" + path + "/" + dirname + "/" + fname;
var req = http.get(optionsData, function(res) {
if(res.statusCode != 200){
console.log("Error on get (Status)");
result(res.statusCode);
return;
}
var body = "";
res.setEncoding('binary')
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
fs.writeFile(filename, body, 'binary', function(err){
console.log("successfull");
result(0);
});
});
}).on('error', (e) => {
console.log("Error on get (Error)");
errRes();
return;
});
});
};