summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDylan Dervaux2019-02-01 12:33:27 +0100
committerSheogorath2019-04-10 01:37:12 +0200
commit208070d2e776c437154e6ead552364b3956adf1c (patch)
tree4e24aed2c2be442ede4bf3cbe9e8dc0e6be178df /lib
parent36c083277e6c74bb6eac495971522e6932cfc207 (diff)
Add lutim support
Signed-off-by: Dylan Dervaux <dylanderv05@gmail.com>
Diffstat (limited to '')
-rw-r--r--lib/config/default.js5
-rw-r--r--lib/config/environment.js3
-rw-r--r--lib/config/index.js4
-rw-r--r--lib/web/imageRouter/lutim.js31
4 files changed, 40 insertions, 3 deletions
diff --git a/lib/config/default.js b/lib/config/default.js
index 98ccee91..c87beda3 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
},
diff --git a/lib/config/environment.js b/lib/config/environment.js
index 882df140..508c1ba6 100644
--- a/lib/config/environment.js
+++ b/lib/config/environment.js
@@ -49,6 +49,9 @@ module.exports = {
secure: toBooleanConfig(process.env.CMD_MINIO_SECURE),
port: toIntegerConfig(process.env.CMD_MINIO_PORT)
},
+ lutim: {
+ url: process.env.CMD_LUTIM_URL
+ },
s3bucket: process.env.CMD_S3_BUCKET,
azure: {
connectionString: process.env.CMD_AZURE_CONNECTION_STRING,
diff --git a/lib/config/index.js b/lib/config/index.js
index 4c28196e..e102dce9 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'
}
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)
+ })
+}