From e478959a1b4f225cb202140bb42e49777689b726 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 29 Jul 2023 11:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=AA=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/utils/trie.js | 2 +- frontend/src/views/Room.vue | 4 ++-- services/translate.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/utils/trie.js b/frontend/src/utils/trie.js index 86a54f5..a869cd5 100644 --- a/frontend/src/utils/trie.js +++ b/frontend/src/utils/trie.js @@ -41,7 +41,7 @@ export class Trie { return this.get(key) !== null } - greedyMatch(str) { + lazyMatch(str) { let node = this._root for (let char of str) { let nextNode = node.children[char] diff --git a/frontend/src/views/Room.vue b/frontend/src/views/Room.vue index 62e8c47..d6134df 100644 --- a/frontend/src/views/Room.vue +++ b/frontend/src/views/Room.vue @@ -272,7 +272,7 @@ export default { let blockKeywordsTrie = this.blockKeywordsTrie for (let i = 0; i < content.length; i++) { let remainContent = content.substring(i) - if (blockKeywordsTrie.greedyMatch(remainContent) !== null) { + if (blockKeywordsTrie.lazyMatch(remainContent) !== null) { return false } } @@ -327,7 +327,7 @@ export default { let pos = 0 while (pos < data.content.length) { let remainContent = data.content.substring(pos) - let matchEmoticon = emoticonsTrie.greedyMatch(remainContent) + let matchEmoticon = emoticonsTrie.lazyMatch(remainContent) if (matchEmoticon === null) { pos++ continue diff --git a/services/translate.py b/services/translate.py index d85c06d..bc7fd9b 100644 --- a/services/translate.py +++ b/services/translate.py @@ -446,7 +446,7 @@ class TencentTranslate(FlowControlTranslateProvider): logger.warning('TencentTranslate request failed: status=%d %s', r.status, r.reason) return None data = (await r.json())['Response'] - except (aiohttp.ClientError, asyncio.TimeoutError): + except (aiohttp.ClientConnectionError, asyncio.TimeoutError): return None error = data.get('Error', None) if error is not None: @@ -554,7 +554,7 @@ class BaiduTranslate(FlowControlTranslateProvider): logger.warning('BaiduTranslate request failed: status=%d %s', r.status, r.reason) return None data = await r.json() - except (aiohttp.ClientError, asyncio.TimeoutError): + except (aiohttp.ClientConnectionError, asyncio.TimeoutError): return None error_code = data.get('error_code', None) if error_code is not None: