Browse Source

commit for draft PR

kaoritokashiki 5 years ago
parent
commit
d06a4a9395

+ 1 - 1
src/client/js/components/Admin/ImportData/GrowiArchive/UploadForm.jsx

@@ -31,7 +31,7 @@ class UploadForm extends React.Component {
     formData.append('_csrf', this.props.appContainer.csrfToken);
     formData.append('file', this.inputRef.current.files[0]);
 
-    const { data } = await this.props.appContainer.apiv3Post('/import/upload', formData);
+    const { data } = await this.props.appContainer.apiv3Post('/import/upload', formData); // ここにアップロードしたデータが渡ってきている
     this.props.onUpload(data);
     // TODO: toastSuccess, toastError
   }

+ 21 - 1
src/client/js/components/Admin/ImportData/GrowiArchiveSection.jsx

@@ -18,6 +18,7 @@ class GrowiArchiveSection extends React.Component {
     this.initialState = {
       fileName: null,
       innerFileStats: null,
+      isTheSameVersion: true,
     };
 
     this.state = this.initialState;
@@ -25,6 +26,7 @@ class GrowiArchiveSection extends React.Component {
     this.handleUpload = this.handleUpload.bind(this);
     this.discardData = this.discardData.bind(this);
     this.resetState = this.resetState.bind(this);
+    this.renderDefferentVersionAlert = this.renderDefferentVersionAlert.bind(this);
   }
 
   async componentWillMount() {
@@ -37,11 +39,15 @@ class GrowiArchiveSection extends React.Component {
     }
   }
 
-  handleUpload({ meta, fileName, innerFileStats }) {
+  handleUpload({
+    meta, fileName, innerFileStats, isTheSameVersion,
+  }) {
     this.setState({
       fileName,
       innerFileStats,
+      isTheSameVersion: false, // 仮
     });
+    console.log(`isTheSameVersion from handleUpload = ${isTheSameVersion}`);
   }
 
   async discardData() {
@@ -74,12 +80,25 @@ class GrowiArchiveSection extends React.Component {
     }
   }
 
+  renderDefferentVersionAlert() {
+    const { t } = this.props;
+    const { isTheSameVersion } = this.state;
+    console.log(`versionsNotMetinRenderDefferentVersionAlert=${isTheSameVersion}`);
+    return (
+      <div className="alert alert-warning mt-3">
+        {t('admin:importer_management.growi_settings.errors.versions_not_met')}
+      </div>
+    );
+  }
+
   resetState() {
     this.setState(this.initialState);
   }
 
   render() {
     const { t } = this.props;
+    const { isTheSameVersion } = this.state;
+    console.log(`isTheSameVersion=${isTheSameVersion}`);
 
     return (
       <Fragment>
@@ -87,6 +106,7 @@ class GrowiArchiveSection extends React.Component {
 
         {this.state.fileName != null ? (
           <div className="px-4">
+            {isTheSameVersion === false && this.renderDefferentVersionAlert()}
             <ImportForm
               fileName={this.state.fileName}
               innerFileStats={this.state.innerFileStats}

+ 5 - 2
src/server/routes/apiv3/import.js

@@ -311,8 +311,11 @@ module.exports = (crowi) => {
       const data = await growiBridgeService.parseZipFile(zipFile);
 
       // validate with meta.json
-      importService.validate(data.meta);
-
+      // importService.validate(data.meta);  元々これのみ
+      const versionErr = importService.validateVersionforUploading(data.meta);
+      if (versionErr !== null) {
+        return res.apiv3({ data, versionErr }); // versionErrはobjではないので恐らくこの書き方は間違い
+      }
       return res.apiv3(data);
     }
     catch (err) {

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

@@ -479,7 +479,7 @@ class ImportService {
   // 追加
   validateVersionforUploading(meta) {
     if (meta.version !== this.crowi.version) {
-      const versionErr = new Error('the version of this growi and the growi that exported the data are not met');
+      const versionErr = new Error('the version of this growi and the growi that updated data are not met');
       return versionErr;
     }
   }