From 558139b752ec39000d20ab4a387aaf12f82f435e Mon Sep 17 00:00:00 2001 From: Brandon Kim Date: Tue, 23 Mar 2021 12:36:15 +0900 Subject: [PATCH 1/4] web_view changed to type jsonb --- .../20210323030530-change-web_view-plugins.js | 19 +++++++++++++++++++ server/db/models/plugin.js | 3 ++- server/plugins.js | 8 ++++---- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 server/db/migrations/20210323030530-change-web_view-plugins.js diff --git a/server/db/migrations/20210323030530-change-web_view-plugins.js b/server/db/migrations/20210323030530-change-web_view-plugins.js new file mode 100644 index 0000000000..73186743d5 --- /dev/null +++ b/server/db/migrations/20210323030530-change-web_view-plugins.js @@ -0,0 +1,19 @@ +'use strict'; + +const TABLE = 'Plugins'; +const COLUMN = 'web_view'; + +module.exports = { + up: (queryInterface, Sequelize) => queryInterface.sequelize.query(` + ALTER TABLE "${TABLE}" + ALTER COLUMN "${COLUMN}" + SET DATA TYPE jsonb + USING '[]'::jsonb; + `), + down: (queryInterface, Sequelize) => queryInterface.sequelize.query(` + ALTER TABLE "${TABLE}" + ALTER COLUMN "${COLUMN}" + SET DATA TYPE jsonb + USING '[]'::jsonb; + `), +}; \ No newline at end of file diff --git a/server/db/models/plugin.js b/server/db/models/plugin.js index 583f5890bc..4f4877e934 100644 --- a/server/db/models/plugin.js +++ b/server/db/models/plugin.js @@ -59,7 +59,8 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.TEXT }, web_view: { - type: DataTypes.TEXT + type: DataTypes.JSONB, + defaultValue: [] } }, { timestamps: true, diff --git a/server/plugins.js b/server/plugins.js index 9bc31e97bf..eea5d19fab 100644 --- a/server/plugins.js +++ b/server/plugins.js @@ -305,8 +305,8 @@ checkStatus() }, web_view: { in: ['body'], - errorMessage: 'must be a string or null', - isString: true, + errorMessage: 'must be an array or null', + isArray: true, optional: { options: { nullable: true } } }, prescript: { @@ -577,8 +577,8 @@ checkStatus() }, web_view: { in: ['body'], - errorMessage: 'must be a string or null', - isString: true, + errorMessage: 'must be an array or null', + isArray: true, optional: { options: { nullable: true } } }, prescript: { From 1180eafa98af9263e6e0dc1806dc8d340d3bbf98 Mon Sep 17 00:00:00 2001 From: Brandon Kim Date: Thu, 25 Mar 2021 15:02:59 +0900 Subject: [PATCH 2/4] ws send message checks readyState of websockets --- server/ws/chat/index.js | 13 ++++++++----- server/ws/hub.js | 19 ++++++++++++++----- server/ws/index.js | 13 ++++++++----- server/ws/sub.js | 13 ++++++++++--- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/server/ws/chat/index.js b/server/ws/chat/index.js index 9af971eaf6..2e62de30c8 100644 --- a/server/ws/chat/index.js +++ b/server/ws/chat/index.js @@ -10,6 +10,7 @@ const { isUserBanned } = require('./ban'); const moment = require('moment'); const { subscriber, publisher } = require('../../db/pubsub'); const { getChannels } = require('../channel'); +const WebSocket = require('ws'); const MESSAGES_KEY = 'WS:MESSAGES'; let MESSAGES = []; @@ -68,11 +69,13 @@ const deleteMessage = (idToDelete) => { const publishChatMessage = (event, data) => { each(getChannels()[WEBSOCKET_CHANNEL('chat')], (ws) => { - ws.send(JSON.stringify({ - topic: 'chat', - action: event, - data - })); + if (ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify({ + topic: 'chat', + action: event, + data + })); + } }); }; diff --git a/server/ws/hub.js b/server/ws/hub.js index cecc824a49..eb19069ac0 100644 --- a/server/ws/hub.js +++ b/server/ws/hub.js @@ -7,6 +7,7 @@ const { WS_HUB_CHANNEL, WEBSOCKET_CHANNEL } = require('../constants'); const { each } = require('lodash'); const { getChannels, resetChannels } = require('./channel'); const { updateOrderbookData, updateTradeData, resetPublicData } = require('./publicData'); +const WebSocket = require('ws'); let networkNodeLib = null; let wsConnected = false; @@ -63,10 +64,10 @@ const connect = () => { if (data !== 'pong') { try { data = JSON.parse(data); + handleHubData(data); } catch (err) { loggerWebsocket.error('ws/hub message err', err.message); } - handleHubData(data); } }); } @@ -84,19 +85,25 @@ const handleHubData = (data) => { case 'orderbook': updateOrderbookData(data); each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.symbol)], (ws) => { - ws.send(JSON.stringify(data)); + if (ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify(data)); + } }); break; case 'trade': updateTradeData(data); each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.symbol)], (ws) => { - ws.send(JSON.stringify(data)); + if (ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify(data)); + } }); break; case 'order': case 'wallet': each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.user_id)], (ws) => { - ws.send(JSON.stringify(data)); + if (ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify(data)); + } }); break; default: @@ -107,7 +114,9 @@ const handleHubData = (data) => { const closeAllClients = () => { each(getChannels(), (channel) => { each(channel, (ws) => { - ws.close(); + if (ws.readyState !== WebSocket.CONNECTING) { + ws.close(); + } }); }); resetChannels(); diff --git a/server/ws/index.js b/server/ws/index.js index 7a65af1543..60dfec21a0 100644 --- a/server/ws/index.js +++ b/server/ws/index.js @@ -13,18 +13,21 @@ const { const { initializeTopic, terminateTopic, authorizeUser, terminateClosedChannels, handleChatData } = require('./sub'); const { connect, hubConnected } = require('./hub'); const { setWsHeartbeat } = require('ws-heartbeat/server'); +const WebSocket = require('ws'); wss.on('connection', (ws, req) => { // attaching unique id and authorization to the socket ws.id = uuid(); ws.auth = req.auth; - // send welcome message - ws.send(JSON.stringify({ message: WS_WELCOME })); + if (ws.readyState === WebSocket.OPEN) { + // send welcome message + ws.send(JSON.stringify({ message: WS_WELCOME })); - // send authenticated message if authenticated - if (ws.auth.sub) { - ws.send(JSON.stringify({ message: WS_USER_AUTHENTICATED(ws.auth.sub.email) })); + // send authenticated message if authenticated + if (ws.auth.sub) { + ws.send(JSON.stringify({ message: WS_USER_AUTHENTICATED(ws.auth.sub.email) })); + } } ws.on('message', (message) => { diff --git a/server/ws/sub.js b/server/ws/sub.js index fbcc254899..e789c5dde8 100644 --- a/server/ws/sub.js +++ b/server/ws/sub.js @@ -19,12 +19,17 @@ const { sendInitialMessages, addMessage, deleteMessage } = require('./chat'); const { getUsername, changeUsername } = require('./chat/username'); const { sendBannedUsers, banUser, unbanUser } = require('./chat/ban'); const { sendNetworkWsMessage } = require('./hub'); +const WebSocket = require('ws'); subscriber.subscribe(WS_PUBSUB_DEPOSIT_CHANNEL); subscriber.on('message', (channel, data) => { if (channel === WS_PUBSUB_DEPOSIT_CHANNEL) { - data = JSON.parse(data); - handleDepositData(data); + try { + data = JSON.parse(data); + handleDepositData(data); + } catch (err) { + loggerWebsocket.error('ws/sub/subscriber deposit message', err.message); + } } }); @@ -264,7 +269,9 @@ const handleDepositData = (data) => { switch (data.topic) { case 'deposit': each(getChannels()[WEBSOCKET_CHANNEL(data.topic, data.user_id)], (ws) => { - ws.send(JSON.stringify(data)); + if (ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify(data)); + } }); break; default: From 0b29c2cef5ea4092576f78d8d6f9be55ed9f66ae Mon Sep 17 00:00:00 2001 From: user Date: Fri, 26 Mar 2021 14:32:27 +0900 Subject: [PATCH 3/4] updated web_view plugin migration --- .../20210323030530-change-web_view-plugins.js | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/server/db/migrations/20210323030530-change-web_view-plugins.js b/server/db/migrations/20210323030530-change-web_view-plugins.js index 73186743d5..8ca909c914 100644 --- a/server/db/migrations/20210323030530-change-web_view-plugins.js +++ b/server/db/migrations/20210323030530-change-web_view-plugins.js @@ -4,16 +4,12 @@ const TABLE = 'Plugins'; const COLUMN = 'web_view'; module.exports = { - up: (queryInterface, Sequelize) => queryInterface.sequelize.query(` - ALTER TABLE "${TABLE}" - ALTER COLUMN "${COLUMN}" - SET DATA TYPE jsonb - USING '[]'::jsonb; - `), - down: (queryInterface, Sequelize) => queryInterface.sequelize.query(` - ALTER TABLE "${TABLE}" - ALTER COLUMN "${COLUMN}" - SET DATA TYPE jsonb - USING '[]'::jsonb; - `), + up: (queryInterface) => + queryInterface + .changeColumn(TABLE, COLUMN, { type: `jsonb USING '[]'::jsonb;` }), + down: () => { + return new Promise(resolve => { + resolve(); + }); + } }; \ No newline at end of file From 154f24587b40dd3184c1171e4c595cb2f1ed82d3 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 26 Mar 2021 14:36:07 +0900 Subject: [PATCH 4/4] remove invite friends from mail template --- server/mail/templates/helpers/common.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/server/mail/templates/helpers/common.js b/server/mail/templates/helpers/common.js index 071626aea3..095362e27c 100644 --- a/server/mail/templates/helpers/common.js +++ b/server/mail/templates/helpers/common.js @@ -3,7 +3,6 @@ const { BITHOLLA_DOMAIN, BITHOLLA_LOGO_BLACK, - EMAIL_ICONS } = require('../../constants'); const { DOMAIN, GET_KIT_CONFIG } = require('../../../constants'); const LOGO_IMAGE = () => GET_KIT_CONFIG().logo_image; @@ -25,7 +24,7 @@ const footerTemplate = (language = DEFAULT_LANGUAGE(), domain = DOMAIN) => { return `
-

${FOOTER.INVITE_YOUR_FRIENDS} ${domain}

+

${domain}

${ @@ -60,18 +59,6 @@ const LOGO_TEMPLATE = ({ domain = DOMAIN, logoPath = LOGO_IMAGE() }) => `
`; -const HEADER_TEMPLATE = ({ title, imagePath = '' }) => ` -
- ${imagePath && - ` -
- -
- `} -
${title}
-
-`; - const rtlLanguage = (lang) => (lang === 'fa' || lang === 'ar' ? RTL : ''); exports.TemplateEmail = (