0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Convert local file system image storage to use promises

Part of #635
This commit is contained in:
jamesbloomer 2013-10-02 08:36:41 +01:00 committed by Hannah Wolfe
parent 2983e657a6
commit ec79069a1c

View file

@ -58,24 +58,15 @@ localfilesystem = {
getUniqueFileName(target_dir, basename, ext, null, function (filename) {
fs.mkdirs(target_dir, function (err) {
if (err) {
errors.logError(err);
return saved.reject();
}
fs.copy(image.path, target_path, function (err) {
if (err) {
errors.logError(err);
return saved.reject();
}
// NOTE as every upload will need to delete the tmp file make this the admin controllers job
// The src for the image must be in URI format, not a file system path, which in Windows uses \
var fullUrl = path.join(ghostUrl, filename).replace(new RegExp('\\' + path.sep, 'g'), '/');
return saved.resolve(fullUrl);
});
nodefn.call(fs.mkdirs, target_dir).then(function () {
return nodefn.call(fs.copy, image.path, target_path);
}).then(function () {
// The src for the image must be in URI format, not a file system path, which in Windows uses \
var fullUrl = path.join(ghostUrl, filename).replace(new RegExp('\\' + path.sep, 'g'), '/');
return saved.resolve(fullUrl);
}).otherwise(function (e) {
errors.logError(e);
return saved.reject(e);
});
});
@ -83,4 +74,4 @@ localfilesystem = {
}
};
module.exports = localfilesystem;
module.exports = localfilesystem;