Przeglądaj źródła

remove zip file after import and log collectionName for error

mizozobu 6 lat temu
rodzic
commit
5a74fdad1a

+ 2 - 0
src/client/js/components/Admin/Import/GrowiZipImportForm.jsx

@@ -54,6 +54,7 @@ class GrowiImportForm extends React.Component {
     });
     // TODO toastSuccess, toastError
     this.setState(this.initialState);
+    this.props.onPostImport();
   }
 
   validateForm() {
@@ -131,6 +132,7 @@ GrowiImportForm.propTypes = {
   fileName: PropTypes.string,
   fileStats: PropTypes.arrayOf(PropTypes.object).isRequired,
   onDiscard: PropTypes.func.isRequired,
+  onPostImport: PropTypes.func.isRequired,
 };
 
 /**

+ 6 - 0
src/client/js/components/Admin/Import/GrowiZipImportSection.jsx

@@ -22,6 +22,7 @@ class GrowiZipImportSection extends React.Component {
 
     this.handleUpload = this.handleUpload.bind(this);
     this.discardData = this.discardData.bind(this);
+    this.resetState = this.resetState.bind(this);
   }
 
   handleUpload({ meta, fileName, fileStats }) {
@@ -33,6 +34,10 @@ class GrowiZipImportSection extends React.Component {
 
   async discardData() {
     await this.props.appContainer.apiRequest('delete', `/v3/import/${this.state.fileName}`, {});
+    this.resetState();
+  }
+
+  resetState() {
     this.setState(this.initialState);
   }
 
@@ -54,6 +59,7 @@ class GrowiZipImportSection extends React.Component {
               fileName={this.state.fileName}
               fileStats={this.state.fileStats}
               onDiscard={this.discardData}
+              onPostImport={this.resetState}
             />
           </Fragment>
         ) : (

+ 3 - 0
src/server/routes/apiv3/import.js

@@ -105,6 +105,9 @@ module.exports = (crowi) => {
     // eslint-disable-next-line no-unused-vars
     const { meta, fileStats } = await growiBridgeService.parseZipFile(zipFile);
 
+    // delete zip file after unzipping and parsing it
+    fs.unlinkSync(zipFile);
+
     // filter fileStats
     const filteredFileStats = fileStats.filter(({ fileName, collectionName, size }) => { return collections.includes(collectionName) });
 

+ 2 - 1
src/server/service/import.js

@@ -174,8 +174,9 @@ class ImportService {
       nInserted = log.result.nInserted;
     }
     catch (err) {
+      const collectionName = unorderedBulkOp.s.namespace;
       for (const error of err.result.result.writeErrors) {
-        logger.error(error.errmsg);
+        logger.error(`${collectionName}: ${error.errmsg}`);
         failed.push(error.err.op._id);
       }