mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 13:22:39 +03:00
Merge pull request #2284 from sebgie/issue#1654
Remove res.redirect from db.exportContent
This commit is contained in:
commit
d996ff68e7
@ -16,32 +16,10 @@ api.notifications = require('./notifications');
|
||||
api.settings = require('./settings');
|
||||
|
||||
db = {
|
||||
'exportContent': function (req, res) {
|
||||
/*jslint unparam:true*/
|
||||
return dataExport().then(function (exportedData) {
|
||||
// Save the exported data to the file system for download
|
||||
var fileName = path.join(config().paths.exportPath, 'exported-' + (new Date().getTime()) + '.json');
|
||||
|
||||
return nodefn.call(fs.writeFile, fileName, JSON.stringify(exportedData)).then(function () {
|
||||
return when(fileName);
|
||||
});
|
||||
}).then(function (exportedFilePath) {
|
||||
// Send the exported data file
|
||||
res.download(exportedFilePath, 'GhostData.json');
|
||||
}).otherwise(function (error) {
|
||||
// Notify of an error if it occurs
|
||||
return api.notifications.browse().then(function (notifications) {
|
||||
var notification = {
|
||||
type: 'error',
|
||||
message: error.message || error,
|
||||
status: 'persistent',
|
||||
id: 'per-' + (notifications.length + 1)
|
||||
};
|
||||
|
||||
return api.notifications.add(notification).then(function () {
|
||||
res.redirect(config().paths.debugPath);
|
||||
});
|
||||
});
|
||||
'exportContent': function () {
|
||||
// Export data, otherwise send error 500
|
||||
return dataExport().otherwise(function (error) {
|
||||
return when.reject({errorCode: 500, message: error.message || error});
|
||||
});
|
||||
},
|
||||
'importContent': function (options) {
|
||||
|
@ -111,6 +111,28 @@ adminControllers = {
|
||||
bodyClass: 'settings',
|
||||
adminNav: setSelected(adminNavbar, 'settings')
|
||||
});
|
||||
},
|
||||
// frontend route for downloading a file
|
||||
exportContent: function (req, res) {
|
||||
/*jslint unparam:true*/
|
||||
api.db.exportContent().then(function (exportData) {
|
||||
// send a file to the client
|
||||
res.set('Content-Disposition', 'attachment; filename="GhostData.json"');
|
||||
res.json(exportData);
|
||||
}).otherwise(function (err) {
|
||||
var notification = {
|
||||
type: 'error',
|
||||
message: 'Your export file could not be generated.',
|
||||
status: 'persistent',
|
||||
id: 'errorexport'
|
||||
};
|
||||
|
||||
errors.logError(err, 'admin.js', "Your export file could not be generated.");
|
||||
|
||||
return api.notifications.add(notification).then(function () {
|
||||
res.redirect(config().paths.subdir + '/ghost/debug');
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
// Route: upload
|
||||
|
@ -43,6 +43,8 @@ module.exports = function (server) {
|
||||
server.get('/ghost/settings*', admin.settings);
|
||||
server.get('/ghost/debug/', admin.debug.index);
|
||||
|
||||
server.get('/ghost/export/', admin.debug.exportContent);
|
||||
|
||||
server.post('/ghost/upload/', middleware.busboy, admin.upload);
|
||||
|
||||
// redirect to /ghost and let that do the authentication to prevent redirects to /ghost//admin etc.
|
||||
|
@ -24,7 +24,7 @@ module.exports = function (server) {
|
||||
server.del('/ghost/api/v0.1/notifications/:id', api.requestHandler(api.notifications.destroy));
|
||||
server.post('/ghost/api/v0.1/notifications/', api.requestHandler(api.notifications.add));
|
||||
// #### Import/Export
|
||||
server.get('/ghost/api/v0.1/db/', api.db.exportContent);
|
||||
server.get('/ghost/api/v0.1/db/', api.requestHandler(api.db.exportContent));
|
||||
server.post('/ghost/api/v0.1/db/', middleware.busboy, api.requestHandler(api.db.importContent));
|
||||
server.del('/ghost/api/v0.1/db/', api.requestHandler(api.db.deleteAllContent));
|
||||
};
|
@ -20,7 +20,7 @@
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label>Export</label>
|
||||
<a href="{{admin_url}}/api/v0.1/db/" class="button-save">Export</a>
|
||||
<a href="{{admin_url}}/export/" class="button-save">Export</a>
|
||||
<p>Export the blog settings and data.</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
Loading…
Reference in New Issue
Block a user