-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
86 lines (81 loc) · 2.68 KB
/
util.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
85
86
const formidable = require('formidable');
const fs = require('fs')
const rimraf = require('rimraf');
exports.upload = function (req, res) {
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var oldpath = files.bundle.path;
var newpath = __dirname + '/public/' + files.bundle.name;
fs.rename(oldpath, newpath, function (err) {
if (err) throw err;
res.write('File uploaded and moved!');
res.end();
});
});
}
exports.uploadSplitBundle = function (req, res) {
var dirPath = __dirname + '/static/js2';
if (!fs.existsSync(dirPath)){
fs.mkdirSync(dirPath);
}
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var oldpath = files.bundle.path;
var newpath = dirPath + '/' + files.bundle.name;
fs.rename(oldpath, newpath, function (err) {
if (err) throw err;
res.write('File uploaded and moved!');
res.end();
});
});
}
exports.completedBundleUpload = function (req, res) {
var tempPath = __dirname + '/static/js2';
if (!fs.existsSync(tempPath)){
res.write('Invalid Operation. Upload the bundle files first!');
res.end();
return ;
}
var newPath = __dirname + '/static/js';
rimraf(newPath, function () {
console.log('done deleted of js folder');
fs.rename(tempPath, newPath, function (err) {
if (err) throw err;
res.write('Acknowledged! Bundle Update Complete');
res.end();
});
});
}
exports.uploadSplitBundleStaging = function (req, res) {
var dirPath = __dirname + '/staging/static/js2';
if (!fs.existsSync(dirPath)){
fs.mkdirSync(dirPath);
}
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var oldpath = files.bundle.path;
var newpath = dirPath + '/' + files.bundle.name;
fs.rename(oldpath, newpath, function (err) {
if (err) throw err;
res.write('File uploaded and moved!');
res.end();
});
});
}
exports.completedBundleUploadStaging = function (req, res) {
var tempPath = __dirname + '/staging/static/js2';
if (!fs.existsSync(tempPath)){
res.write('Invalid Operation. Upload the bundle files first!');
res.end();
return ;
}
var newPath = __dirname + '/staging/static/js';
rimraf(newPath, function () {
console.log('done deleted of js folder');
fs.rename(tempPath, newPath, function (err) {
if (err) throw err;
res.write('Acknowledged! Bundle Update Complete');
res.end();
});
});
}