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) { getUniqueFileName(target_dir, basename, ext, null, function (filename) {
fs.mkdirs(target_dir, function (err) { nodefn.call(fs.mkdirs, target_dir).then(function () {
if (err) { return nodefn.call(fs.copy, image.path, target_path);
errors.logError(err); }).then(function () {
return saved.reject(); // 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);
fs.copy(image.path, target_path, function (err) { }).otherwise(function (e) {
if (err) { errors.logError(e);
errors.logError(err); return saved.reject(e);
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);
});
}); });
}); });
@ -83,4 +74,4 @@ localfilesystem = {
} }
}; };
module.exports = localfilesystem; module.exports = localfilesystem;