mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-16 12:16:09 +03:00
485c264c69
no issue - now that we use bluebird globally, we can use the promise support from fs-extra
31 lines
671 B
JavaScript
31 lines
671 B
JavaScript
var Promise = require('bluebird'),
|
|
fs = require('fs-extra'),
|
|
storage = require('../adapters/storage'),
|
|
upload;
|
|
|
|
/**
|
|
* ## Upload API Methods
|
|
*
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
*/
|
|
upload = {
|
|
|
|
/**
|
|
* ### Add Image
|
|
*
|
|
* @public
|
|
* @param {{context}} options
|
|
* @returns {Promise<String>} location of uploaded file
|
|
*/
|
|
add: Promise.method(function (options) {
|
|
var store = storage.getStorage();
|
|
|
|
return store.save(options).finally(function () {
|
|
// Remove uploaded file from tmp location
|
|
return fs.unlink(options.path);
|
|
});
|
|
})
|
|
};
|
|
|
|
module.exports = upload;
|