Ghost/core/server/api/v2/upload.js
2018-10-12 22:41:39 +02:00

32 lines
931 B
JavaScript

const fs = require('fs-extra');
const storage = require('../../adapters/storage');
module.exports = {
docName: 'upload',
image: {
statusCode: 201,
permissions: false,
query(frame) {
const store = storage.getStorage();
if (frame.files) {
return Promise.map(frame.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(frame.file).finally(() => {
// Remove uploaded file from tmp location
return fs.unlink(frame.file.path);
});
}
}
};