Skip to content

Commit 45e6fd3

Browse files
committed
check pipeline size on change and before save / deploy
1 parent 1123ad4 commit 45e6fd3

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

app/hydrator/controllers/create/toppanel-ctrl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ class HydratorPlusPlusTopPanelCtrl {
588588
this.checkNameError();
589589
}
590590
onPublishV2(isEdit = false) {
591+
if (!this.HydratorPlusPlusConfigStore.checkPipelineJsonSize()) return;
591592
this.HydratorPlusPlusConfigActions.publishPipeline(isEdit);
592593
this.checkNameError();
593594
}
@@ -1456,6 +1457,16 @@ class HydratorPlusPlusTopPanelCtrl {
14561457
}
14571458

14581459
let uploadedFile = files[0];
1460+
1461+
const MB = 1024 * 1024; // Bytes
1462+
if (files[0].size > 2 * MB) {
1463+
const fileSizeInMB = ((files[0].size || 1) / MB).toFixed(2);
1464+
this.myAlertOnValium.show({
1465+
type: "danger",
1466+
content: `File size is ${fileSizeInMB}MB. Pipelines larger than 2MB are not supported.`,
1467+
});
1468+
return;
1469+
}
14591470
this.HydratorUpgradeService.validateAndUpgradeConfigFile(uploadedFile, this.getParentVersion());
14601471
}
14611472

app/hydrator/services/create/stores/config-store.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
class HydratorPlusPlusConfigStore {
18-
constructor(HydratorPlusPlusConfigDispatcher, HydratorPlusPlusCanvasFactory, GLOBALS, mySettings, HydratorPlusPlusConsoleActions, $stateParams, NonStorePipelineErrorFactory, HydratorPlusPlusHydratorService, $q, HydratorPlusPlusPluginConfigFactory, uuid, $state, HYDRATOR_DEFAULT_VALUES, myHelpers, MY_CONFIG, EventPipe, myPipelineApi, myAppsApi, HydratorPlusPlusNodeService) {
18+
constructor(HydratorPlusPlusConfigDispatcher, HydratorPlusPlusCanvasFactory, GLOBALS, mySettings, HydratorPlusPlusConsoleActions, $stateParams, NonStorePipelineErrorFactory, HydratorPlusPlusHydratorService, $q, HydratorPlusPlusPluginConfigFactory, uuid, $state, HYDRATOR_DEFAULT_VALUES, myHelpers, MY_CONFIG, EventPipe, myPipelineApi, myAppsApi, HydratorPlusPlusNodeService, myAlertOnValium) {
1919
'ngInject';
2020
this.state = {};
2121
this.mySettings = mySettings;
@@ -36,6 +36,7 @@ class HydratorPlusPlusConfigStore {
3636
this.myPipelineApi = myPipelineApi;
3737
this.myAppsApi = myAppsApi;
3838
this.isDistributed = MY_CONFIG.isEnterprise ? true : false;
39+
this.myAlertOnValium = myAlertOnValium;
3940

4041
this.changeListeners = [];
4142
this.setDefaults();
@@ -70,7 +71,28 @@ class HydratorPlusPlusConfigStore {
7071
this.changeListeners.splice(index, 1);
7172
};
7273
}
74+
checkPipelineJsonSize() {
75+
const MB = 1024 * 1024; // Bytes
76+
try {
77+
const pipelineJson = this.getConfigForExport();
78+
delete pipelineJson.__ui__;
79+
const jsonBlob = new Blob([JSON.stringify(pipelineJson, null, 4)], { type: 'application/json' });
80+
const blobSize = jsonBlob.size || 1;
81+
const blobSizeInMBRounded = (blobSize / MB).toFixed(2);
82+
if (jsonBlob.size > 2 * MB) {
83+
this.myAlertOnValium.show({
84+
type: "danger",
85+
content: `Pipeline size is ${blobSizeInMBRounded}MB. Pipelines larger than 2MB are not supported.`,
86+
});
87+
return false;
88+
}
89+
} catch (e) {
90+
// pass
91+
}
92+
return true;
93+
}
7394
emitChange() {
95+
this.checkPipelineJsonSize();
7496
this.changeListeners.forEach( callback => callback() );
7597
}
7698
setDefaults(config) {
@@ -1208,6 +1230,8 @@ class HydratorPlusPlusConfigStore {
12081230
return;
12091231
}
12101232

1233+
if (!this.HydratorPlusPlusConfigStore.checkPipelineJsonSize()) return;
1234+
12111235
let config = this.getConfigForExport({ shouldPruneProperties: false });
12121236
const draftId = this.getDraftId() || this.uuid.v4();
12131237
const params = {

0 commit comments

Comments
 (0)