b43ab65d8a
refs #9866 - preparation for v2 - moved api/ to api/v0.1 - do export v0.1 straight from the api folder, we don't want to touch this right now - that means currently if you require the api folder, we return v0.1 by default - there were some direct requires of api files in the test env - some of them use rewire - for now, we just correct the require path to require api/v0.1/ - we touch the test env next week **Docs about V2 design are coming soon!**
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const Promise = require('bluebird'),
|
|
fs = require('fs-extra'),
|
|
storage = require('../../adapters/storage');
|
|
|
|
let upload;
|
|
|
|
/**
|
|
* ## Upload API Methods
|
|
*
|
|
* **See:** [API Methods](constants.js.html#api%20methods)
|
|
*/
|
|
upload = {
|
|
|
|
/**
|
|
* ### Add Image
|
|
*
|
|
* We only allow multiple uploads internally - see images middlewares.
|
|
*
|
|
* @public
|
|
* @param {{context}} options
|
|
* @returns {Promise<String>} location of uploaded file
|
|
*/
|
|
add: Promise.method((options) => {
|
|
const store = storage.getStorage();
|
|
|
|
if (options.files) {
|
|
return Promise.map(options.files, (file) => {
|
|
return store
|
|
.save(file)
|
|
.finally(() => {
|
|
// Remove uploaded file from tmp location
|
|
return fs.unlink(file.path);
|
|
});
|
|
}).then((paths) => {
|
|
return paths[0];
|
|
});
|
|
}
|
|
|
|
return store.save(options).finally(() => {
|
|
// Remove uploaded file from tmp location
|
|
return fs.unlink(options.path);
|
|
});
|
|
})
|
|
};
|
|
|
|
module.exports = upload;
|