|
Lines 22-30
var mkdirp = require('mkdirp');
Link Here
|
| 22 |
var fs = Promise.promisifyAll(require('fs')); |
22 |
var fs = Promise.promisifyAll(require('fs')); |
| 23 |
var fileUtil = require('./fileUtil'); |
23 |
var fileUtil = require('./fileUtil'); |
| 24 |
|
24 |
|
| 25 |
/** |
25 |
/** |
| 26 |
* @callback |
26 |
* @callback |
| 27 |
*/ |
27 |
*/ |
| 28 |
module.exports = function(options) { |
28 |
module.exports = function(options) { |
| 29 |
var UPLOADS_FOLDER = path.join(options.configParams['orion.single.user'] ? |
29 |
var UPLOADS_FOLDER = path.join(options.configParams['orion.single.user'] ? |
| 30 |
path.join(os.homedir(), ".orion") : options.workspaceDir, ".uploads"); |
30 |
path.join(os.homedir(), ".orion") : options.workspaceDir, ".uploads"); |
|
Lines 41-46
module.exports = function(options) {
Link Here
|
| 41 |
function getOptions(req) { |
41 |
function getOptions(req) { |
| 42 |
return req.get("X-Xfer-Options").split(","); |
42 |
return req.get("X-Xfer-Options").split(","); |
| 43 |
} |
43 |
} |
|
|
44 |
|
| 45 |
function reportTransferFailure(res, err) { |
| 46 |
var message = "File transfer failed"; |
| 47 |
if (err.message) { |
| 48 |
message += ": " + err.message; |
| 49 |
} |
| 50 |
return res.status(400).json({ |
| 51 |
Severity: "Error", |
| 52 |
HttpCode: 400, |
| 53 |
Code: 0, |
| 54 |
Message: message, |
| 55 |
DetailedMessage: message |
| 56 |
}); |
| 57 |
} |
| 44 |
|
58 |
|
| 45 |
function postImportXfer(req, res) { |
59 |
function postImportXfer(req, res) { |
| 46 |
var filePath = req.params["0"]; |
60 |
var filePath = req.params["0"]; |
|
Lines 63-68
function postImportXfer(req, res) {
Link Here
|
| 63 |
function upload(request) { |
77 |
function upload(request) { |
| 64 |
var tempFile = path.join(UPLOADS_FOLDER, Date.now() + fileName); |
78 |
var tempFile = path.join(UPLOADS_FOLDER, Date.now() + fileName); |
| 65 |
var ws = fs.createWriteStream(tempFile); |
79 |
var ws = fs.createWriteStream(tempFile); |
|
|
80 |
ws.on('error', function(err) { |
| 81 |
reportTransferFailure(res, err); |
| 82 |
}); |
| 66 |
ws.on('finish', function() { |
83 |
ws.on('finish', function() { |
| 67 |
completeTransfer(req, res, tempFile, filePath, fileName, xferOptions, shouldUnzip); |
84 |
completeTransfer(req, res, tempFile, filePath, fileName, xferOptions, shouldUnzip); |
| 68 |
}); |
85 |
}); |
|
Lines 142-150
function completeTransfer(req, res, tempFile, filePath, fileName, xferOptions, s
Link Here
|
| 142 |
entry.autodrain(); |
159 |
entry.autodrain(); |
| 143 |
return; |
160 |
return; |
| 144 |
} |
161 |
} |
| 145 |
entry.pipe(fs.createWriteStream(outputName)); |
162 |
// make sure all sub folders exist |
|
|
163 |
var subfolderPath = path.join(filePath, path.dirname(entryName)); |
| 164 |
if (!fs.existsSync(subfolderPath)) { |
| 165 |
mkdirp.sync(subfolderPath); |
| 166 |
} |
| 167 |
var writeStream = fs.createWriteStream(outputName); |
| 168 |
writeStream.on('error', function(err) { |
| 169 |
reportTransferFailure(res, err); |
| 170 |
}); |
| 171 |
entry.pipe(writeStream); |
| 146 |
} else if (type === "Directory") { |
172 |
} else if (type === "Directory") { |
| 147 |
mkdirp.sync(outputName); |
173 |
if (!fs.existsSync(outputName)) { |
|
|
174 |
mkdirp.sync(outputName); |
| 175 |
} |
| 148 |
} |
176 |
} |
| 149 |
} else { |
177 |
} else { |
| 150 |
entry.autodrain(); |
178 |
entry.autodrain(); |
|
Lines 210-213
function write (zip, base, filePath) {
Link Here
|
| 210 |
zip.file(filePath, { name: filePath.substring(base.length).replace(/\\/g, "/") }); |
238 |
zip.file(filePath, { name: filePath.substring(base.length).replace(/\\/g, "/") }); |
| 211 |
}); |
239 |
}); |
| 212 |
} |
240 |
} |
| 213 |
}; |
241 |
}; |