Skip to content

Commit e2b9ea8

Browse files
authored
Merge pull request #1136 from Dylanderv/feature/lutim
Add support for file hosting with lutim
2 parents 9f16f32 + 6291813 commit e2b9ea8

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

lib/config/default.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ module.exports = {
6060
responseMaxLag: 70,
6161
// document
6262
documentMaxLength: 100000,
63-
// image upload setting, available options are imgur/s3/filesystem/azure
63+
// image upload setting, available options are imgur/s3/filesystem/azure/lutim
6464
imageUploadType: 'filesystem',
65+
lutim: {
66+
url: 'https://framapic.org/'
67+
},
6568
imgur: {
6669
clientID: undefined
6770
},

lib/config/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ if (config.sessionSecret === 'secret') {
164164
}
165165

166166
// Validate upload upload providers
167-
if (['filesystem', 's3', 'minio', 'imgur', 'azure'].indexOf(config.imageUploadType) === -1) {
168-
logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio", "azure" or "imgur". Defaulting to "filesystem"')
167+
if (['filesystem', 's3', 'minio', 'imgur', 'azure', 'lutim'].indexOf(config.imageUploadType) === -1) {
168+
logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio", "azure", "lutim" or "imgur". Defaulting to "filesystem"')
169169
config.imageUploadType = 'filesystem'
170170
}
171171

lib/web/imageRouter/lutim.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict'
2+
const config = require('../../config')
3+
const logger = require('../../logger')
4+
5+
const lutim = require('lutim')
6+
7+
exports.uploadImage = function (imagePath, callback) {
8+
if (!imagePath || typeof imagePath !== 'string') {
9+
callback(new Error('Image path is missing or wrong'), null)
10+
return
11+
}
12+
13+
if (!callback || typeof callback !== 'function') {
14+
logger.error('Callback has to be a function')
15+
return
16+
}
17+
18+
if (config.lutim && config.lutim.url) {
19+
lutim.setAPIUrl(config.lutim.url)
20+
}
21+
22+
lutim.uploadImage(imagePath)
23+
.then(function (json) {
24+
if (config.debug) {
25+
logger.info('SERVER uploadimage success: ' + JSON.stringify(json))
26+
}
27+
callback(null, lutim.getAPIUrl() + json.msg.short)
28+
}).catch(function (err) {
29+
callback(new Error(err), null)
30+
})
31+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"keymaster": "~1.6.2",
8080
"list.js": "~1.5.0",
8181
"lodash": "~4.17.11",
82+
"lutim": "~1.0.2",
8283
"markdown-it": "~8.2.2",
8384
"markdown-it-abbr": "~1.0.4",
8485
"markdown-it-container": "~2.0.0",

0 commit comments

Comments
 (0)