Ghost/core/server/api/upload.js
Aileen Nowak 1b965fab95 🎨 Move scheduling and storage in adapters/ (#8435)
no issue

Move `core/server/scheduling` to `core/server/adapters/scheduling` and
`core/server/storage` to `core/server/adapters/storage`
2017-05-15 12:52:01 +02:00

32 lines
718 B
JavaScript

var Promise = require('bluebird'),
fs = require('fs-extra'),
pUnlink = Promise.promisify(fs.unlink),
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 pUnlink(options.path);
});
})
};
module.exports = upload;