hedgedoc/lib/web/imageRouter/filesystem.ts
Philip Molares 41726949e8
not specified errors should be undefined and not null in UploadProvider
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: David Mehren <dmehren1@gmail.com>
2020-04-25 16:04:10 +02:00

24 lines
643 B
TypeScript

import path from 'path'
import { URL } from 'url'
import { config } from '../../config'
import { logger } from '../../logger'
import { UploadProvider } from './index'
const FilesystemUploadProvider: 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
}
callback(undefined, (new URL(path.basename(imagePath), config.serverURL + '/uploads/')).href)
}
}
export { FilesystemUploadProvider }