Verified Commit a356943b authored by Frauke's avatar Frauke

Fix image path

parent 5987eeaa
const fileUtils = require('../helpers/fileUtils')
const os = require('os')
const path = require('path')
const dataDirectoryPath = path.join(os.homedir(), '.hallo.gent')
module.exports = (image, original) => {
if (image === '' && original && original !== '') {
// Original image was removed and no new image was uploaded, so remove original image.
fileUtils.removeFile(`${dataDirectoryPath}${original}`).catch(err => {
fileUtils.removeFile(original).catch(err => {
throw err
})
image = null
} else if (image && image !== '' && (!original || original === '' || image !== original)) {
// An image was uploaded, save only the path to the image
image = `${image[0].destination.replace(${dataDirectoryPath}, '')}/${image[0].filename}`
image = image[0].path
// And remove originalImage if present
if (!original && original !== '') {
fileUtils.removeFile(`${dataDirectoryPath}${original}`).catch(err => {
fileUtils.removeFile(original).catch(err => {
throw err
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment