|
|
@@ -1,11 +1,11 @@
|
|
|
module.exports = function(crowi, app) {
|
|
|
'use strict';
|
|
|
|
|
|
- var debug = require('debug')('growi:routs:attachment')
|
|
|
+ var debug = require('debug')('growi:routss:attachment')
|
|
|
+ , logger = require('@alias/logger')('growi:routes:attachment')
|
|
|
, Attachment = crowi.model('Attachment')
|
|
|
, User = crowi.model('User')
|
|
|
, Page = crowi.model('Page')
|
|
|
- , config = crowi.getConfig()
|
|
|
, path = require('path')
|
|
|
, fs = require('fs')
|
|
|
, fileUploader = require('../util/fileUploader')(crowi, app)
|
|
|
@@ -42,7 +42,7 @@ module.exports = function(crowi, app) {
|
|
|
})
|
|
|
// not found
|
|
|
.catch((err) => {
|
|
|
- debug('download err', err);
|
|
|
+ logger.error('download err', err);
|
|
|
return res.status(404).sendFile(crowi.publicDir + '/images/file-not-found.png');
|
|
|
});
|
|
|
};
|
|
|
@@ -140,7 +140,6 @@ module.exports = function(crowi, app) {
|
|
|
return Attachment.create(id, req.user, filePath, originalName, fileName, fileType, fileSize);
|
|
|
}).then(function(data) {
|
|
|
var fileUrl = data.fileUrl;
|
|
|
- var config = crowi.getConfig();
|
|
|
|
|
|
var result = {
|
|
|
page: page.toObject(),
|
|
|
@@ -157,18 +156,18 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
}).catch(function(err) {
|
|
|
- debug('Error on saving attachment data', err);
|
|
|
+ logger.error('Error on saving attachment data', err);
|
|
|
// @TODO
|
|
|
// Remove from S3
|
|
|
|
|
|
// delete anyway
|
|
|
- fs.unlink(tmpPath, function(err) { if (err) { debug('Error while deleting tmp file.') } });
|
|
|
+ fs.unlink(tmpPath, function(err) { if (err) { logger.error('Error while deleting tmp file.') } });
|
|
|
|
|
|
return res.json(ApiResponse.error('Error while uploading.'));
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
}).catch(function(err) {
|
|
|
- debug('Attachement upload error', err);
|
|
|
+ logger.error('Attachement upload error', err);
|
|
|
return res.json(ApiResponse.error('Error.'));
|
|
|
});
|
|
|
};
|
|
|
@@ -192,10 +191,11 @@ module.exports = function(crowi, app) {
|
|
|
debug('removeAttachment', data);
|
|
|
return res.json(ApiResponse.success({}));
|
|
|
}).catch(err => {
|
|
|
+ logger.error('Error', err);
|
|
|
return res.status(500).json(ApiResponse.error('Error while deleting file'));
|
|
|
});
|
|
|
}).catch(err => {
|
|
|
- debug('Error', err);
|
|
|
+ logger.error('Error', err);
|
|
|
return res.status(404);
|
|
|
});
|
|
|
};
|