Add possibility to pull file value

This commit is contained in:
Aurélien Georget 2015-11-20 11:40:33 +01:00
parent fd6e907fc7
commit 91bf22cbbd

View File

@ -342,6 +342,35 @@ module.exports = function (strapi) {
cb(null, obj);
},
/**
* Pull file from local server
*
* @param {Object} data
*
* @return {Function} cb
*/
pullFile: function (data, cb) {
const rootPath = path.resolve(data.path);
fs.exists(rootPath, function (exists) {
if (exists) {
fs.readFile(rootPath, 'utf8', function (err, data) {
if (err) {
cb('Impossible to read `' + rootPath + '`', null);
} else {
cb(null, {
path: rootPath,
value: JSON.parse(data)
});
}
});
} else {
cb('Unknow path `' + rootPath + '`', null);
}
});
},
/**
* Rebuild dictionary
*