...
 
Commits (3)
......@@ -81,15 +81,15 @@ app.service('authentication').hooks({
app.get('/uploads/:domain/:id',
// authenticate request with JSONWebToken
// optional
function (req, res, next) {
jsonWebToken.verify(req.headers.authorization, secretFile.secret, (err) => {
if (err) {
res.status(401).end()
} else {
next()
}
})
},
// function (req, res, next) {
// jsonWebToken.verify(req.headers.authorization, secretFile.secret, err => {
// if (err) {
// res.status(401).end()
// } else {
// next()
// }
// })
// },
// fetch file and return
function (req, res) {
res.sendFile(`${req.params.domain}/${req.params.id}`, {root: `${dataDirectoryPath}/uploads/`}, err => {
......@@ -99,6 +99,13 @@ app.get('/uploads/:domain/:id',
})
})
// expose dataDirectoryPath to requests and feathers services
app.use((req, res, next) => {
req.dataDirectoryPath = dataDirectoryPath
req.feathers.dataDirectoryPath = dataDirectoryPath
next()
})
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware)
// Set up our services (see `services/index.js`)
......
......@@ -58,8 +58,7 @@ function removeFile (fileName) {
}
// remove a dir
function removeDir(path) {
console.log(path)
function removeDir (path) {
return fs.remove(path)
}
......
......@@ -9,11 +9,11 @@ module.exports = (image, original) => {
image = null
} else if (image && image !== '' && (!original || original === '' || image !== original)) {
// An image was uploaded, save only the path to the image
image = image[0].path
// An image was uploaded, save only the PUBLIC path to the image
image = image[0].public
// And remove originalImage if present
if (!original && original !== '') {
if (original && original !== '') {
fileUtils.removeFile(original).catch(err => {
throw err
})
......
const multer = require('multer')
const mime = require('mime-types')
const fileUtils = require('../helpers/fileUtils')
const os = require('os')
const path = require('path')
const dataDirectoryPath = path.join(os.homedir(), '.hallo.gent')
// storage for header and profile images
const infoStorage = multer.diskStorage({
destination: function (req, file, next) {
fileUtils.makeDir(`${dataDirectoryPath}/uploads/${req.params.__feathersId}`).then(() => {
next(null, `${dataDirectoryPath}/uploads/${req.params.__feathersId}`)
fileUtils.makeDir(`${req.dataDirectoryPath}/uploads/${req.params.__feathersId}`).then(() => {
next(null, `${req.dataDirectoryPath}/uploads/${req.params.__feathersId}`)
}).catch(err => {
throw err
})
......
......@@ -2,6 +2,26 @@
// Note: files will only be added to the request when multer is previous middleware
module.exports = (req, res, next) => {
if (req.files) {
// provide a publicly accessible file path
Object.keys(req.files).forEach(
key => {
let file = req.files[key][0]
file.public = `/uploads/${req.params.__feathersId}/${file.filename}`
}
)
Object.keys(req.body).forEach(key => {
// convert string 'null' to real null
if (req.body[key] === 'null') {
req.body[key] = null
}
// convert public upload path to server path
if (typeof req.body[key] === 'string' && req.body[key].indexOf('/uploads') === 0 ) {
req.body[key] = req.dataDirectoryPath + req.body[key]
}
})
const data = Object.assign({}, req.body, req.files)
req.body = data
}
......
......@@ -13,7 +13,6 @@ class Service {
try {
const site = new PendingSite(id)
const code = new AccountCode(params.payload.accountCode)
await site.saveInfo(data)
await code.setLocale(data.locale)
} catch (err) {
......
......@@ -15,17 +15,9 @@ module.exports = {
// check if peningSite exists
const site = new PendingSite(context.id)
site.getMetaData().then(() => {
// convert string 'null' to real null
Object.keys(context.data).forEach(key => {
if (context.data[key] === 'null') {
context.data[key] = null
}
})
// set the correct path for the images
context.data.headerImage = fileCheck(context.data.headerImage, context.data.headerOriginalImage)
context.data.profileImage = fileCheck(context.data.profileImage, context.data.profileOriginalImage)
// String to JSON convertion
context.data.headerImageMetadata = JSON.parse(context.data.headerImageMetadata)
context.data.profileImageMetadata = JSON.parse(context.data.profileImageMetadata)
......
const PendingSite = require('../../db/models/pendingSite')
const messagesDb = require('../../db/services/messagesDb')
const fileUtils = require('../../helpers/fileUtils')
const os = require('os')
const path = require('path')
const dataDirectoryPath = path.join(os.homedir(), '.hallo.gent')
class Service {
constructor (options) {
......@@ -28,7 +25,7 @@ class Service {
await site.remove()
// Delete images from site
await fileUtils.removeDir(`${dataDirectoryPath}/uploads/${id}`)
await fileUtils.removeDir(`${params.dataDirectoryPath}/uploads/${id}`)
// delete the conversation on the server.
await messagesDb.deleteConversation(metaData.accountCode)
......