mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #2284 from sebgie/issue#1654
Remove res.redirect from db.exportContent
This commit is contained in:
commit
d996ff68e7
5 changed files with 30 additions and 28 deletions
|
@ -16,32 +16,10 @@ api.notifications = require('./notifications');
|
||||||
api.settings = require('./settings');
|
api.settings = require('./settings');
|
||||||
|
|
||||||
db = {
|
db = {
|
||||||
'exportContent': function (req, res) {
|
'exportContent': function () {
|
||||||
/*jslint unparam:true*/
|
// Export data, otherwise send error 500
|
||||||
return dataExport().then(function (exportedData) {
|
return dataExport().otherwise(function (error) {
|
||||||
// Save the exported data to the file system for download
|
return when.reject({errorCode: 500, message: error.message || error});
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'importContent': function (options) {
|
'importContent': function (options) {
|
||||||
|
|
|
@ -111,6 +111,28 @@ adminControllers = {
|
||||||
bodyClass: 'settings',
|
bodyClass: 'settings',
|
||||||
adminNav: setSelected(adminNavbar, '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
|
// Route: upload
|
||||||
|
|
|
@ -43,6 +43,8 @@ module.exports = function (server) {
|
||||||
server.get('/ghost/settings*', admin.settings);
|
server.get('/ghost/settings*', admin.settings);
|
||||||
server.get('/ghost/debug/', admin.debug.index);
|
server.get('/ghost/debug/', admin.debug.index);
|
||||||
|
|
||||||
|
server.get('/ghost/export/', admin.debug.exportContent);
|
||||||
|
|
||||||
server.post('/ghost/upload/', middleware.busboy, admin.upload);
|
server.post('/ghost/upload/', middleware.busboy, admin.upload);
|
||||||
|
|
||||||
// redirect to /ghost and let that do the authentication to prevent redirects to /ghost//admin etc.
|
// 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.del('/ghost/api/v0.1/notifications/:id', api.requestHandler(api.notifications.destroy));
|
||||||
server.post('/ghost/api/v0.1/notifications/', api.requestHandler(api.notifications.add));
|
server.post('/ghost/api/v0.1/notifications/', api.requestHandler(api.notifications.add));
|
||||||
// #### Import/Export
|
// #### 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.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));
|
server.del('/ghost/api/v0.1/db/', api.requestHandler(api.db.deleteAllContent));
|
||||||
};
|
};
|
|
@ -20,7 +20,7 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Export</label>
|
<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>
|
<p>Export the blog settings and data.</p>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
Loading…
Add table
Reference in a new issue