Quellcode durchsuchen

Merge branch 'master' into feat/select-language-in-installer

Yuto Iwata vor 7 Jahren
Ursprung
Commit
d4b62f11cc

+ 1 - 1
CHANGES.md

@@ -3,7 +3,7 @@ CHANGES
 
 
 ## 3.2.9-RC
 ## 3.2.9-RC
 
 
-* 
+* Feature: Attachment Storing to MongoDB GridFS
 
 
 ## 3.2.8
 ## 3.2.8
 
 

+ 5 - 1
README.md

@@ -163,7 +163,11 @@ Environment Variables
     * PASSWORD_SEED: A password seed used by password hash generator.
     * PASSWORD_SEED: A password seed used by password hash generator.
     * SECRET_TOKEN: A secret key for verifying the integrity of signed cookies.
     * SECRET_TOKEN: A secret key for verifying the integrity of signed cookies.
     * SESSION_NAME: The name of the session ID cookie to set in the response by Express. default: `connect.sid`
     * SESSION_NAME: The name of the session ID cookie to set in the response by Express. default: `connect.sid`
-    * FILE_UPLOAD: `aws` (default), `local`, `none`
+    * FILE_UPLOAD: Attached files storage. default: `aws`
+      * `aws` : AWS S3 (needs AWS settings on Admin page)
+      * `mongodb` : MongoDB GridFS (Setting-less)
+      * `local` : Server's Local file system (Setting-less)
+      * `none` : Disable file uploading
 * **Option to integrate with external systems**
 * **Option to integrate with external systems**
     * HACKMD_URI: URI to connect to [HackMD(CodiMD)](https://hackmd.io/) server.
     * HACKMD_URI: URI to connect to [HackMD(CodiMD)](https://hackmd.io/) server.
         * **This server must load the GROWI agent. [Here's how to prepare it](https://docs.growi.org/management-cookbook/integrate-with-hackmd).**
         * **This server must load the GROWI agent. [Here's how to prepare it](https://docs.growi.org/management-cookbook/integrate-with-hackmd).**

+ 1 - 1
config/env.dev.js

@@ -1,6 +1,6 @@
 module.exports = {
 module.exports = {
   NODE_ENV: 'development',
   NODE_ENV: 'development',
-  FILE_UPLOAD: 'local',
+  FILE_UPLOAD: 'mongodb',
   // MATHJAX: 1,
   // MATHJAX: 1,
   ELASTICSEARCH_URI: 'http://localhost:9200/growi',
   ELASTICSEARCH_URI: 'http://localhost:9200/growi',
   HACKMD_URI: 'http://localhost:3010',
   HACKMD_URI: 'http://localhost:3010',

+ 7 - 0
resource/locales/en-US/translation.json

@@ -101,6 +101,13 @@
   "Deleted Pages": "Deleted Pages",
   "Deleted Pages": "Deleted Pages",
   "Sign out": "Logout",
   "Sign out": "Logout",
 
 
+  "installer": {
+    "setup": "Setup",
+    "create_initial_account": "Create an initial account",
+    "initial_account_will_be_administrator_automatically": "The initial account will be administrator automatically.",
+    "unavaliable_user_id": "This 'User ID' is unavailable."
+  },
+
   "page_register": {
   "page_register": {
     "notice": {
     "notice": {
       "restricted": "Admin approval required.",
       "restricted": "Admin approval required.",

+ 1 - 1
src/server/routes/attachment.js

@@ -55,7 +55,7 @@ module.exports = function(crowi, app) {
    * @apiParam {String} pageId, fileName
    * @apiParam {String} pageId, fileName
    */
    */
   api.get = async function(req, res) {
   api.get = async function(req, res) {
-    if (process.env.FILE_UPLOAD != 'gridfs') {
+    if (process.env.FILE_UPLOAD !== 'mongodb') {
       return res.status(400);
       return res.status(400);
     }
     }
     const pageId = req.params.pageId;
     const pageId = req.params.pageId;

+ 7 - 8
src/server/service/file-uploader/gridfs.js

@@ -3,22 +3,21 @@
 module.exports = function(crowi) {
 module.exports = function(crowi) {
   'use strict';
   'use strict';
 
 
-  var debug = require('debug')('growi:service:fileUploadergridfs')
-  var mongoose = require('mongoose');
-  var path = require('path');
-  var fs = require('fs');
-  var lib = {};
-  var AttachmentFile = {};
+  const debug = require('debug')('growi:service:fileUploaderGridfs');
+  const mongoose = require('mongoose');
+  const path = require('path');
+  const fs = require('fs');
+  const lib = {};
 
 
   // instantiate mongoose-gridfs
   // instantiate mongoose-gridfs
-  var gridfs = require('mongoose-gridfs')({
+  const gridfs = require('mongoose-gridfs')({
     collection: 'attachmentFiles',
     collection: 'attachmentFiles',
     model: 'AttachmentFile',
     model: 'AttachmentFile',
     mongooseConnection: mongoose.connection
     mongooseConnection: mongoose.connection
   });
   });
 
 
   // obtain a model
   // obtain a model
-  AttachmentFile = gridfs.model;
+  const AttachmentFile = gridfs.model;
 
 
   // delete a file
   // delete a file
   lib.deleteFile = async function(fileId, filePath) {
   lib.deleteFile = async function(fileId, filePath) {

+ 8 - 1
src/server/service/file-uploader/index.js

@@ -1,8 +1,15 @@
+const envToModuleMappings = {
+  aws:     'aws',
+  local:   'local',
+  none:    'none',
+  mongodb: 'gridfs',
+};
+
 class FileUploaderFactory {
 class FileUploaderFactory {
 
 
   getUploader(crowi) {
   getUploader(crowi) {
     if (this.uploader == null) {
     if (this.uploader == null) {
-      const method = process.env.FILE_UPLOAD || 'aws';
+      const method = envToModuleMappings[process.env.FILE_UPLOAD] || 'aws';
       const modulePath = `./${method}`;
       const modulePath = `./${method}`;
       this.uploader = require(modulePath)(crowi);
       this.uploader = require(modulePath)(crowi);
     }
     }