mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
0faf89b5ab
refs #4453 * On by default * Added config to disable resizing * Added basic image optimization processing * Added dep: sharp (optional dep) * Added resize middleware * Take care of rotation based on EXIF information * Removed all meta data from optimised image * Added handling if sharp could not get installed * Do not read ext twice - optimisation * Do not call sharp if config is disabled * Do not remove the original image which was uploaded (store 2 images) * Support of `req.files` for internal logic * Disabled cache to enable file removal on Windows
46 lines
1.2 KiB
JavaScript
46 lines
1.2 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(function (options) {
|
|
const store = storage.getStorage();
|
|
|
|
if (options.files) {
|
|
return Promise.map(options.files, (file) => {
|
|
return store
|
|
.save(file)
|
|
.finally(function () {
|
|
// Remove uploaded file from tmp location
|
|
return fs.unlink(file.path);
|
|
});
|
|
}).then((paths) => {
|
|
return paths[0];
|
|
});
|
|
}
|
|
|
|
return store.save(options).finally(function () {
|
|
// Remove uploaded file from tmp location
|
|
return fs.unlink(options.path);
|
|
});
|
|
})
|
|
};
|
|
|
|
module.exports = upload;
|