Ghost/core/server/api/v2/upload.js

32 lines
931 B
JavaScript
Raw Normal View History

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);
});
}
}
};