Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 0bc032d

Browse files
authored
Merge branch 'dev' into misc-blocks
2 parents 12acfc0 + 300c6d6 commit 0bc032d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/botPage/view/blockly/customBlockly.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import GTM from '../../../common/gtm';
22
import { translate, translateLangToLang } from '../../../common/i18n';
33
import { getLanguage } from '../../../common/lang';
4+
import { save } from './utils';
45

56
/* eslint-disable */
67
Blockly.WorkspaceAudio.prototype.preload = function() {};
@@ -376,3 +377,29 @@ Blockly.WorkspaceAudio.prototype.preload = function() {
376377
}
377378
}
378379
};
380+
381+
// https://groups.google.com/forum/#!msg/blockly/eS1V49pI9c8/VEh5UuUcBAAJ
382+
const addDownloadOption = (callback, options, block) => {
383+
options.push({
384+
text: translate('Download'),
385+
enabled: true,
386+
callback: () => {
387+
const xml = Blockly.Xml.textToDom('<xml xmlns="http://www.w3.org/1999/xhtml" collection="false"></xml>');
388+
xml.appendChild(Blockly.Xml.blockToDom(block));
389+
save('binary-bot-block', true, xml);
390+
},
391+
});
392+
callback(options);
393+
};
394+
395+
const originalCustomContextVarFn =
396+
Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN.customContextMenu;
397+
Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN.customContextMenu = function(options) {
398+
addDownloadOption(originalCustomContextVarFn.bind(this), options, this);
399+
};
400+
401+
const originalCustomContextLoopFn =
402+
Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN.customContextMenu;
403+
Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN.customContextMenu = function(options) {
404+
addDownloadOption(originalCustomContextLoopFn.bind(this), options, this);
405+
};

src/indexPage/endpoint.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { get as getStorage, set as setStorage } from '../common/utils/storageManager';
22
import { generateWebSocketURL, getDefaultEndpoint, generateTestLiveApiInstance } from '../common/appId';
3+
import { translate } from '../common/utils/tools';
34

45
if (document.location.href.endsWith('/endpoint')) {
56
window.location.replace(`${document.location.href}.html`);
@@ -64,6 +65,15 @@ function addEndpoint(e) {
6465
setStorage('config.server_url', serverUrl);
6566
setStorage('config.app_id', appId);
6667

68+
const urlReg = /^(?:http(s)?:\/\/)?[\w.-]+(?:.[\w.-]+)+[\w-._~:\/?#[\]@!$&'()*+,;=.]+$/;
69+
70+
if (!urlReg.test(serverUrl)) {
71+
$('#error')
72+
.html(translate('Please enter a valid server URL'))
73+
.show();
74+
return;
75+
}
76+
6777
checkConnection(appId, serverUrl);
6878
}
6979

0 commit comments

Comments
 (0)