|
|
@@ -3,17 +3,18 @@
|
|
|
*/
|
|
|
|
|
|
|
|
|
-module.exports = function(crowi, app) {
|
|
|
+module.exports = function(crowi) {
|
|
|
'use strict';
|
|
|
|
|
|
var aws = require('aws-sdk')
|
|
|
, debug = require('debug')('crowi:lib:fileUploader')
|
|
|
, Promise = require('bluebird')
|
|
|
+ , Config = crowi.model('Config')
|
|
|
, config = crowi.getConfig()
|
|
|
, lib = {}
|
|
|
;
|
|
|
|
|
|
- function getAwsConfig ()
|
|
|
+ lib.getAwsConfig = function()
|
|
|
{
|
|
|
return {
|
|
|
accessKeyId: config.crowi['aws:accessKeyId'],
|
|
|
@@ -21,18 +22,7 @@ module.exports = function(crowi, app) {
|
|
|
region: config.crowi['aws:region'],
|
|
|
bucket: config.crowi['aws:bucket']
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- function isUploadable(awsConfig) {
|
|
|
- if (!awsConfig.accessKeyId ||
|
|
|
- !awsConfig.secretAccessKey ||
|
|
|
- !awsConfig.region ||
|
|
|
- !awsConfig.bucket) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
// lib.deleteFile = function(filePath, callback) {
|
|
|
// // TODO 実装する
|
|
|
@@ -40,8 +30,8 @@ module.exports = function(crowi, app) {
|
|
|
//
|
|
|
|
|
|
lib.uploadFile = function(filePath, contentType, fileStream, options) {
|
|
|
- var awsConfig = getAwsConfig();
|
|
|
- if (!isUploadable(awsConfig)) {
|
|
|
+ var awsConfig = lib.getAwsConfig();
|
|
|
+ if (!Config.isUploadable(config)) {
|
|
|
return new Promise.reject(new Error('AWS is not configured.'));
|
|
|
}
|
|
|
|
|
|
@@ -70,7 +60,7 @@ module.exports = function(crowi, app) {
|
|
|
};
|
|
|
|
|
|
lib.generateS3FileUrl = function(filePath) {
|
|
|
- var awsConfig = getAwsConfig();
|
|
|
+ var awsConfig = lib.getAwsConfig();
|
|
|
var url = 'https://' + awsConfig.bucket +'.s3.amazonaws.com/' + filePath;
|
|
|
|
|
|
return url;
|