@@ -16,7 +16,7 @@ api.notifications = require('./notifications');
1616api . settings = require ( './settings' ) ;
1717
1818db = {
19- 'export ' : function ( req , res ) {
19+ 'exportContent ' : function ( req , res ) {
2020 /*jslint unparam:true*/
2121 return dataExport ( ) . then ( function ( exportedData ) {
2222 // Save the exported data to the file system for download
@@ -44,11 +44,10 @@ db = {
4444 } ) ;
4545 } ) ;
4646 } ,
47- 'import' : function ( req , res ) {
48- var notification ,
49- databaseVersion ;
47+ 'importContent' : function ( options ) {
48+ var databaseVersion ;
5049
51- if ( ! req . files . importfile || ! req . files . importfile . path || req . files . importfile . name . indexOf ( 'json' ) === - 1 ) {
50+ if ( ! options . importfile || ! options . importfile . path || options . importfile . name . indexOf ( 'json' ) === - 1 ) {
5251 /**
5352 * Notify of an error if it occurs
5453 *
@@ -57,30 +56,17 @@ db = {
5756 * - If there is no path
5857 * - If the name doesn't have json in it
5958 */
60- return api . notifications . browse ( ) . then ( function ( notifications ) {
61- notification = {
62- type : 'error' ,
63- message : "Must select a .json file to import" ,
64- status : 'persistent' ,
65- id : 'per-' + ( notifications . length + 1 )
66- } ;
67-
68-
69-
70- return api . notifications . add ( notification ) . then ( function ( ) {
71- res . redirect ( configPaths ( ) . debugPath ) ;
72- } ) ;
73- } ) ;
59+ return when . reject ( { errorCode : 500 , message : 'Please select a .json file to import.' } ) ;
7460 }
7561
76- api . settings . read ( { key : 'databaseVersion' } ) . then ( function ( setting ) {
62+ return api . settings . read ( { key : 'databaseVersion' } ) . then ( function ( setting ) {
7763 return when ( setting . value ) ;
7864 } , function ( ) {
7965 return when ( '001' ) ;
8066 } ) . then ( function ( version ) {
8167 databaseVersion = version ;
8268 // Read the file contents
83- return nodefn . call ( fs . readFile , req . files . importfile . path ) ;
69+ return nodefn . call ( fs . readFile , options . importfile . path ) ;
8470 } ) . then ( function ( fileContents ) {
8571 var importData ,
8672 error = '' ,
@@ -132,32 +118,9 @@ db = {
132118 } ) . then ( function importSuccess ( ) {
133119 return api . settings . updateSettingsCache ( ) ;
134120 } ) . then ( function ( ) {
135- return api . notifications . browse ( ) ;
136- } ) . then ( function ( notifications ) {
137- notification = {
138- type : 'success' ,
139- message : "Posts, tags and other data successfully imported" ,
140- status : 'persistent' ,
141- id : 'per-' + ( notifications . length + 1 )
142- } ;
143-
144- return api . notifications . add ( notification ) . then ( function ( ) {
145- res . redirect ( configPaths ( ) . debugPath ) ;
146- } ) ;
121+ return when . resolve ( { message : 'Posts, tags and other data successfully imported' } ) ;
147122 } ) . otherwise ( function importFailure ( error ) {
148- return api . notifications . browse ( ) . then ( function ( notifications ) {
149- // Notify of an error if it occurs
150- notification = {
151- type : 'error' ,
152- message : error . message || error ,
153- status : 'persistent' ,
154- id : 'per-' + ( notifications . length + 1 )
155- } ;
156-
157- return api . notifications . add ( notification ) . then ( function ( ) {
158- res . redirect ( configPaths ( ) . debugPath ) ;
159- } ) ;
160- } ) ;
123+ return when . reject ( { errorCode : 500 , message : error . message || error } ) ;
161124 } ) ;
162125 } ,
163126 'deleteAllContent' : function ( ) {
0 commit comments