Sotaro KARASAWA 10 лет назад
Родитель
Сommit
3f9afc3b3b
6 измененных файлов с 33 добавлено и 27 удалено
  1. 2 0
      lib/crowi/index.js
  2. 15 0
      lib/models/config.js
  3. 7 17
      lib/util/fileUploader.js
  4. 1 1
      lib/views/_form.html
  5. 0 1
      lib/views/page.html
  6. 8 8
      resource/js/crowi-form.js

+ 2 - 0
lib/crowi/index.js

@@ -63,7 +63,9 @@ Crowi.prototype.init = function() {
         if (err) {
           return reject();
         }
+
         self.setConfig(doc);
+
         return resolve();
       });
     });

+ 15 - 0
lib/models/config.js

@@ -21,6 +21,7 @@ module.exports = function(crowi) {
     return {
       'app:title'         : 'Crowi',
       'app:confidential'  : '',
+      'app:uploadable'  : false,
 
       'security:registrationMode'      : 'Open',
       'security:registrationWhiteList' : [],
@@ -158,11 +159,25 @@ module.exports = function(crowi) {
           config[el.ns][el.key] = JSON.parse(el.value);
         });
 
+        // temporary ...
+        config.crowi['app:uploadable'] = Config.isUploadable(config);
+
         debug('Config loaded', config);
         return callback(null, config);
       });
   };
 
+  configSchema.statics.isUploadable = function(config)
+  {
+    if (!config.crowi['aws:accessKeyId'] ||
+        !config.crowi['aws:secretAccessKey'] ||
+        !config.crowi['aws:region'] ||
+        !config.crowi['aws:bucket']) {
+      return false;
+    }
+
+    return true;
+  };
 
   Config = mongoose.model('Config', configSchema);
   Config.SECURITY_REGISTRATION_MODE_OPEN       = SECURITY_REGISTRATION_MODE_OPEN;

+ 7 - 17
lib/util/fileUploader.js

@@ -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;

+ 1 - 1
lib/views/_form.html

@@ -9,7 +9,7 @@
 </div>
 {% endif %}
 <div id="form-box" class="row">
-  <form action="{{ path }}/edit" id="page-form" method="post" class="col-md-6">
+  <form action="{{ path }}/edit" id="page-form" method="post" class="col-md-6 {% if config.crowi['app:uploadable'] %}uploadable{% endif %}">
     <textarea name="pageForm[body]" class="form-control form-body-height" id="form-body">{% if pageForm.body %}{{ pageForm.body }}{% elseif not revision.body %}# {{ path|path2name }}{% else %}{{ revision.body }}{% endif %}</textarea>
 
     <input type="hidden" name="pageForm[format]" value="markdown" id="form-format">

+ 0 - 1
lib/views/page.html

@@ -159,7 +159,6 @@
         var urlBase = res.data.fileBaseUrl;
         if (attachments.length > 0) {
           $.each(attachments, function(i, file) {
-            console.log(file);
             $pageAttachmentList.append(
             '<li><a href="' + urlBase + file.filePath + '">' + (file.originalName || file.fileName) + '</a> <span class="label label-default">' + file.fileFormat + '</span></li>'
             );

+ 8 - 8
resource/js/crowi-form.js

@@ -250,7 +250,7 @@ $(function() {
     };
   };
 
-  var $inputForm = $('textarea#form-body');
+  var $inputForm = $('form.uploadable textarea#form-body');
   if ($inputForm.length > 0) {
     var pageId = $('#content-main').data('page-id') || 0;
     var attachmentOption = {
@@ -281,12 +281,12 @@ $(function() {
     };
 
     bindInlineAttachment($inputForm, attachmentOption);
-  }
 
-  $('textarea#form-body').on('dragenter dragover', function() {
-    $(this).addClass('dragover');
-  });
-  $('textarea#form-body').on('drop dragleave dragend', function() {
-    $(this).removeClass('dragover');
-  });
+    $('textarea#form-body').on('dragenter dragover', function() {
+      $(this).addClass('dragover');
+    });
+    $('textarea#form-body').on('drop dragleave dragend', function() {
+      $(this).removeClass('dragover');
+    });
+  }
 });