From d38931185c65709a832ede166945f1e6a4793337 Mon Sep 17 00:00:00 2001 From: Dylan Dervaux Date: Fri, 1 Feb 2019 12:33:27 +0100 Subject: [PATCH 1/5] Add lutim dependency Signed-off-by: Dylan Dervaux --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f7b1363..0a9e8bda 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "doctoc": "doctoc --title='# Table of Contents' README.md" }, "dependencies": { + "@mlink/scrypt": "^6.1.2", "@passport-next/passport-openid": "^1.0.0", "Idle.Js": "git+https://github.com/shawnmclean/Idle.js", "archiver": "^2.1.1", @@ -63,6 +64,7 @@ "keymaster": "^1.6.2", "list.js": "^1.5.0", "lodash": "^4.17.11", + "lutim": "^1.0.2", "lz-string": "git+https://github.com/hackmdio/lz-string.git", "markdown-it": "^8.2.2", "markdown-it-abbr": "^1.0.4", @@ -109,7 +111,6 @@ "readline-sync": "^1.4.7", "request": "^2.88.0", "reveal.js": "~3.7.0", - "@mlink/scrypt": "^6.1.2", "select2": "^3.5.2-browserify", "sequelize": "^3.28.0", "sequelize-cli": "^2.5.1", From 8557133fbe3a880743b800f3b6aa217175cf27e2 Mon Sep 17 00:00:00 2001 From: Dylan Dervaux Date: Fri, 1 Feb 2019 12:35:44 +0100 Subject: [PATCH 2/5] Add imageRouter handler for lutim Signed-off-by: Dylan Dervaux --- lib/web/imageRouter/lutim.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/web/imageRouter/lutim.js diff --git a/lib/web/imageRouter/lutim.js b/lib/web/imageRouter/lutim.js new file mode 100644 index 00000000..78b856c9 --- /dev/null +++ b/lib/web/imageRouter/lutim.js @@ -0,0 +1,31 @@ +'use strict' +const config = require('../../config') +const logger = require('../../logger') + +const lutim = require('lutim') + +exports.uploadImage = function (imagePath, callback) { + if (!imagePath || typeof imagePath !== 'string') { + callback(new Error('Image path is missing or wrong'), null) + return + } + + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') + return + } + + if (config.lutim && config.lutim.url) { + lutim.setAPIUrl(config.lutim.url) + } + + lutim.uploadImage(imagePath) + .then(function (json) { + if (config.debug) { + logger.info('SERVER uploadimage success: ' + JSON.stringify(json)) + } + callback(null, lutim.getAPIUrl() + json.msg.short) + }).catch(function (err) { + callback(new Error(err), null) + }) +} From 492d38b5ed6f4980df6c1992917aa68fdbd28a7b Mon Sep 17 00:00:00 2001 From: Dylan Dervaux Date: Fri, 1 Feb 2019 12:36:58 +0100 Subject: [PATCH 3/5] Add lutim in image upload providers validator Signed-off-by: Dylan Dervaux --- lib/config/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config/index.js b/lib/config/index.js index cbe6c39c..9753e33d 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -164,8 +164,8 @@ if (config.sessionSecret === 'secret') { } // Validate upload upload providers -if (['filesystem', 's3', 'minio', 'imgur', 'azure'].indexOf(config.imageUploadType) === -1) { - logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio", "azure" or "imgur". Defaulting to "filesystem"') +if (['filesystem', 's3', 'minio', 'imgur', 'azure', 'lutim'].indexOf(config.imageUploadType) === -1) { + logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio", "azure", "lutim" or "imgur". Defaulting to "filesystem"') config.imageUploadType = 'filesystem' } From 590b2f9c7dde12cd2851e3aad1cb5e312cf30780 Mon Sep 17 00:00:00 2001 From: Dylan Dervaux Date: Fri, 1 Feb 2019 13:42:12 +0100 Subject: [PATCH 4/5] Add default config for lutim Signed-off-by: Dylan Dervaux --- lib/config/default.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/config/default.js b/lib/config/default.js index 9e401f38..e789aa43 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -58,8 +58,11 @@ module.exports = { heartbeatTimeout: 10000, // document documentMaxLength: 100000, - // image upload setting, available options are imgur/s3/filesystem/azure + // image upload setting, available options are imgur/s3/filesystem/azure/lutim imageUploadType: 'filesystem', + lutim: { + url: 'https://framapic.org/' + }, imgur: { clientID: undefined }, From 82ac870c26c9c43fe733aa21469ce4b040556bcb Mon Sep 17 00:00:00 2001 From: Dylan Dervaux Date: Fri, 1 Feb 2019 13:44:34 +0100 Subject: [PATCH 5/5] Update readme close #1109 Signed-off-by: Dylan Dervaux --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6abe9308..e419e2f0 100644 --- a/README.md +++ b/README.md @@ -312,7 +312,8 @@ There are some config settings you need to change in the files below. | `oauth2` | `{baseURL: ..., userProfileURL: ..., userProfileUsernameAttr: ..., userProfileDisplayNameAttr: ..., userProfileEmailAttr: ..., tokenURL: ..., authorizationURL: ..., clientID: ..., clientSecret: ...}` | An object detailing your OAuth2 provider. Refer to the [Mattermost](docs/guides/auth/mattermost-self-hosted.md) or [Nextcloud](docs/guides/auth/nextcloud.md) examples for more details!| | `allowEmailRegister` | `true` or `false` | set to allow email register (only applied when email is set, default is `true`. Note `bin/manage_users` might help you if registration is `false`.) | | `allowGravatar` | `true` or `false` | set to `false` to disable gravatar as profile picture source on your instance | -| `imageUploadType` | `imgur`, `s3`, `minio`, `azure` or `filesystem`(default) | Where to upload images. For S3, see our Image Upload Guides for [S3](docs/guides/s3-image-upload.md) or [Minio](docs/guides/minio-image-upload.md)| +| `imageUploadType` | `imgur`, `s3`, `minio`, `azure`, `lutim` or `filesystem`(default) | Where to upload images. For S3, see our Image Upload Guides for [S3](docs/guides/s3-image-upload.md) or [Minio](docs/guides/minio-image-upload.md)| +|`lutim`| `{"url": "YOUR_LUTIM_URL"}`| When `imageUploadType` is set to `lutim`, you can setup the lutim url| | `minio` | `{ "accessKey": "YOUR_MINIO_ACCESS_KEY", "secretKey": "YOUR_MINIO_SECRET_KEY", "endpoint": "YOUR_MINIO_HOST", port: 9000, secure: true }` | When `imageUploadType` is set to `minio`, you need to set this key. Also checkout our [Minio Image Upload Guide](docs/guides/minio-image-upload.md) | | `s3` | `{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION" }` | When `imageuploadtype` be set to `s3`, you would also need to setup this key, check our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) | | `s3bucket` | `YOUR_S3_BUCKET_NAME` | bucket name when `imageUploadType` is set to `s3` or `minio` |