Skip to content

Commit

Permalink
Update directory paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cwhite911 committed Nov 24, 2015
1 parent b6bc2eb commit b35ae6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions server/api/document/document.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.exists = function(req, res){
exists: false
};
//Checks if the file exisits
fs.readdir(path.join('public/documents', data.folder), function (err, files){
fs.readdir(path.join(__dirname, '../../', 'public/documents', data.folder), function (err, files){
if (err){
res.status(200).json(data).end();
}
Expand Down Expand Up @@ -50,12 +50,13 @@ exports.updateName = function(req, res){
docType = req.body.params.docType,
split = originalId.split('-'),
dir = path.join('public/documents', split[0]),
oldPath = path.join(dir, originalId + '.pdf'),

oldPath = path.join(__dirname, '../../', dir, originalId + '.pdf'),
newPath;

if (Array.isArray(split) && split.length === 3){
newId = [split[0], docType, split[2]].join('-');
newPath = path.join(dir, newId + '.pdf');
newPath = path.join(__dirname, '../../', dir, newId + '.pdf');
fs.rename(oldPath, newPath, function(err){
if (err) {
res.status(200).json({ message: 'Document not renamed', error: err}).end();
Expand Down Expand Up @@ -113,10 +114,9 @@ exports.send = function(req, res, next){
fileInfo,
options;

fs.stat(path.join(dir, file), function(err, stats){
fs.stat(path.join(__dirname, '../../', dir, file), function(err, stats){
if (err){
res.status(200);
res.json({'message':'Sorry, we cannot find that!'}).end();
res.send(404, err).end();
}
else{
options = {
Expand All @@ -130,8 +130,7 @@ exports.send = function(req, res, next){

res.sendfile(file, options, function (err) {
if (err) {
res.json({'message':'Sorry, we cannot find that!'}).end();
res.status(err.status).end();
res.send(404, err).end();
}
else {
console.log('IP:', req.ip, 'Sent:', file);
Expand Down
2 changes: 1 addition & 1 deletion server/api/document/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var currentFile;
//Handles file uploads
router.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
router.use(multer({
dest: './public/documents',
dest: path.join(__dirname, '../../', 'public/documents'),
limits: {
fileSize: 100000000
},
Expand Down

0 comments on commit b35ae6c

Please sign in to comment.