-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (61 loc) · 2.19 KB
/
app.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
var express = require('express');
var app = express();
var path = require('path');
var formidable = require('formidable');
var fs = require('fs');
var File = require(path.join(__dirname, 'bin/workFile'));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, 'views/index.html'));
});
app.post('/upload', function(req, res){
// create an incoming form object
var form = new formidable.IncomingForm();
// specify that we want to allow the user to upload multiple files in a single request
form.multiples = true;
// store all uploads in the /uploads directory
form.uploadDir = path.join(__dirname, '/uploads');
// every time a file has been uploaded successfully,
// rename it to it's orignal name
form.on('file', function(field, file) {
fs.rename(file.path, path.join(form.uploadDir, file.name));
});
// log any errors that occur
form.on('error', function(err) {
console.log('An error has occured: \n' + err);
});
// once all the files have been uploaded, send a response to the client
form.on('end', function(field, file) {
res.end('success');
});
form.parse(req, function(err, fields, files) {
console.log(fields);
console.log(files);
if(fields.database == 'PostgreSQL') {
if (files.uploads.length == undefined) {
var file = new File(files.uploads);
file.pgParse();
file.deleteFile();
} else {
files.uploads.forEach(function (item) {
var file = new File(item);
file.pgParse();
file.deleteFile();
});
}
} else {
if (files.uploads.length == undefined) {
var file = new File(files.uploads);
file.mdParse();
file.deleteFile();
} else {
files.uploads.forEach(function (item) {
var file = new File(item);
file.mdParse();
file.deleteFile();
});
}
}
});
});
module.exports = app;