-
Notifications
You must be signed in to change notification settings - Fork 4
/
files.js
84 lines (77 loc) · 1.88 KB
/
files.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
75
76
77
78
79
80
81
82
83
84
/**
* Files
* Used for reading GPX track files lists and contents
*/
var Settings = require('./settings.js');
var fs = require('fs');
var path = require('path');
var parseString = require('xml2js').parseString;
var States = require("./serviceState.js");
var FileList = null;
exports.GetFileList = function()
{
return FileList;
}
exports.GetFiles = function(callback)
{
var me = this;
fs.readdir(Settings.Data.GPXDir, function(err, files)
{
if (err)
{
console.log(err);
}
// do not load files created by PostCycla itself
FileList = files.filter(function(file)
{
return file.indexOf("PostCycla") == -1;
});
callback(FileList, err);
});
}
exports.LoadFileList = function()
{
States.SetCurrentState(States.States.LoadingFileList);
var me = this;
fs.readdir(Settings.Data.GPXDir, function(err, files)
{
if (err)
{
console.log(err);
}
// do not load files created by PostCycla itself
FileList = files.filter(function(file)
{
return file.indexOf("PostCycla") == -1;
});
States.SetCurrentState(States.States.FileListLoaded);
});
return "OK";
}
exports.ReadFileContent = function(requestData, parserCallBack)
{
if (requestData)
{
States.SetCurrentState(States.States.LoadingTrack);
var file = Settings.Data.GPXDir+'/'+requestData.file;
fs.readFile(file, 'utf8', function (err,data)
{
if (err)
{
return console.log(err);
}
parserCallBack(data);
});
}
return "OK";
}
exports.AppendFile = function(file, content)
{
fs.appendFile(file, content, function (err)
{
if (err)
{
return console.log(err);
}
});
}