From 4b98c5696563bbec912a26f91760698fcb64f2c9 Mon Sep 17 00:00:00 2001 From: simon3000 Date: Sat, 30 Nov 2019 07:08:17 +0100 Subject: [PATCH 1/3] auto http/https avatarUrl --- frontend/src/components/ChatRenderer/index.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/ChatRenderer/index.vue b/frontend/src/components/ChatRenderer/index.vue index 35bc655..a17bae4 100644 --- a/frontend/src/components/ChatRenderer/index.vue +++ b/frontend/src/components/ChatRenderer/index.vue @@ -112,7 +112,10 @@ export default { } }, methods: { - addMessage(message) { + addMessage({ avatarUrl, ...message }) { + if (avatarUrl) { + message.avatarUrl = avatarUrl.replace('http:', '').replace('https:', '') + } this.addMessages([message]) }, addMessages(messages) { From 1991e33b9deb7e966996c937518e5fa8540cb046 Mon Sep 17 00:00:00 2001 From: simon3000 Date: Sat, 30 Nov 2019 07:16:38 +0100 Subject: [PATCH 2/3] Revert "auto http/https avatarUrl" This reverts commit 4b98c5696563bbec912a26f91760698fcb64f2c9. --- frontend/src/components/ChatRenderer/index.vue | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frontend/src/components/ChatRenderer/index.vue b/frontend/src/components/ChatRenderer/index.vue index a17bae4..35bc655 100644 --- a/frontend/src/components/ChatRenderer/index.vue +++ b/frontend/src/components/ChatRenderer/index.vue @@ -112,10 +112,7 @@ export default { } }, methods: { - addMessage({ avatarUrl, ...message }) { - if (avatarUrl) { - message.avatarUrl = avatarUrl.replace('http:', '').replace('https:', '') - } + addMessage(message) { this.addMessages([message]) }, addMessages(messages) { From 7453d7e890f7c764ea858b9fa187303e2ddc5815 Mon Sep 17 00:00:00 2001 From: simon3000 Date: Sat, 30 Nov 2019 07:20:35 +0100 Subject: [PATCH 3/3] (python) http/https avatarUrl --- views/chat.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/views/chat.py b/views/chat.py index 4ab8722..746ed9c 100644 --- a/views/chat.py +++ b/views/chat.py @@ -26,7 +26,7 @@ class Command(enum.IntEnum): DEL_SUPER_CHAT = 6 -DEFAULT_AVATAR_URL = 'https://static.hdslb.com/images/member/noface.gif' +DEFAULT_AVATAR_URL = '//static.hdslb.com/images/member/noface.gif' _http_session = aiohttp.ClientSession() _avatar_url_cache: Dict[int, str] = {} @@ -68,7 +68,7 @@ async def get_avatar_url(user_id): data = await r.json() except aiohttp.ClientConnectionError: return DEFAULT_AVATAR_URL - url = data['data']['face'] + url = data['data']['face'].replace('http:', '').replace('https:', '') if not url.endswith('noface.gif'): url += '@48w_48h' _avatar_url_cache[user_id] = url @@ -143,7 +143,7 @@ class Room(blivedm.BLiveClient): if gift.coin_type != 'gold': # 丢人 return self.send_message(Command.ADD_GIFT, { - 'avatarUrl': gift.face, + 'avatarUrl': gift.face.replace('http:', '').replace('https:', ''), 'timestamp': gift.timestamp, 'authorName': gift.uname, 'giftName': gift.gift_name, @@ -163,7 +163,7 @@ class Room(blivedm.BLiveClient): async def _on_super_chat(self, message: blivedm.SuperChatMessage): self.send_message(Command.ADD_SUPER_CHAT, { - 'avatarUrl': message.face, + 'avatarUrl': message.face.replace('http:', '').replace('https:', ''), 'timestamp': message.start_time, 'authorName': message.uname, 'price': message.price, @@ -266,7 +266,7 @@ class ChatHandler(tornado.websocket.WebSocketHandler): # 测试用 def send_test_message(self): base_data = { - 'avatarUrl': 'https://i0.hdslb.com/bfs/face/29b6be8aa611e70a3d3ac219cdaf5e72b604f2de.jpg@48w_48h', + 'avatarUrl': '//i0.hdslb.com/bfs/face/29b6be8aa611e70a3d3ac219cdaf5e72b604f2de.jpg@48w_48h', 'timestamp': time.time(), 'authorName': 'xfgryujk', }