mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
rewrote ImageRouter
- introduced UploadProvider interface - rewrote all current UploadProviders Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
ab5a654068
commit
982bbe9728
14 changed files with 312 additions and 256 deletions
34
lib/web/imageRouter/lutim.ts
Normal file
34
lib/web/imageRouter/lutim.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import lutim from 'lutim'
|
||||
|
||||
import { config } from '../../config'
|
||||
import { logger } from '../../logger'
|
||||
import { UploadProvider } from './index'
|
||||
|
||||
const LutimUploadProvider: UploadProvider = {
|
||||
uploadImage: (imagePath, callback) => {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
logger.error('Callback has to be a function')
|
||||
return
|
||||
}
|
||||
|
||||
if (!imagePath) {
|
||||
callback(new Error('Image path is missing or wrong'), undefined)
|
||||
return
|
||||
}
|
||||
|
||||
if (config.lutim && config.lutim.url) {
|
||||
lutim.setAPIUrl(config.lutim.url)
|
||||
logger.debug(`Set lutim URL to ${lutim.getAPIUrl()}`)
|
||||
}
|
||||
|
||||
lutim.uploadImage(imagePath)
|
||||
.then(function (json) {
|
||||
logger.debug(`SERVER uploadimage success: ${JSON.stringify(json)}`)
|
||||
callback(undefined, lutim.getAPIUrl() + json.msg.short)
|
||||
}).catch(function (err) {
|
||||
callback(new Error(err), undefined)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export { LutimUploadProvider }
|
Loading…
Add table
Add a link
Reference in a new issue