2020-04-12 14:41:54 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-04-12 14:43:38 -04:00
|
|
|
callback(undefined, (new URL(path.basename(imagePath), config.serverURL + '/uploads/')).href)
|
2020-04-12 14:41:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { FilesystemUploadProvider }
|