Skip to content

Commit 78782a5

Browse files
committed
update: 更新版本号 v1.8.0-230917
fix(ChatClient): 保留 Web 接口下的进房消息 fix(Home.vue): 支持上传图片(合并原 Repo)
1 parent 70d4f7d commit 78782a5

File tree

15 files changed

+125
-98
lines changed

15 files changed

+125
-98
lines changed

api/base.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111
self.json_args: Optional[dict] = None
1212

13-
def set_default_headers(self):
14-
# 跨域测试用
15-
if not self.application.settings['debug']:
16-
return
17-
self.set_header('Access-Control-Allow-Origin', '*')
18-
self.set_header('Access-Control-Allow-Methods', 'OPTIONS, PUT, POST, GET, DELETE')
19-
if 'Access-Control-Request-Headers' in self.request.headers:
20-
self.set_header('Access-Control-Allow-Headers',
21-
self.request.headers['Access-Control-Request-Headers'])
22-
2313
def prepare(self):
2414
self.set_header('Cache-Control', 'no-cache')
2515

@@ -28,8 +18,4 @@ def prepare(self):
2818
try:
2919
self.json_args = json.loads(self.request.body)
3020
except json.JSONDecodeError:
31-
pass
32-
33-
async def options(self, *_args, **_kwargs):
34-
# 跨域测试用
35-
self.set_status(204 if self.application.settings['debug'] else 405)
21+
pass

api/chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def send_body_no_raise(self, body: Union[bytes, str, Dict[str, Any]]):
244244
self.close()
245245

246246
async def _on_joined_room(self):
247-
if self.application.settings['debug']:
247+
if self.settings['debug']:
248248
await self._send_test_message()
249249

250250
# 不允许自动翻译的提示

api/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ async def get(self):
4444
'version': update.VERSION,
4545
'config': {
4646
'enableTranslate': cfg.enable_translate,
47+
'enableUploadFile': cfg.enable_upload_file,
4748
'loaderUrl': cfg.loader_url
4849
}
4950
})

frontend/src/api/chat/ChatClientDirectWeb.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,40 @@ export default class ChatClientDirectWeb extends ChatClientOfficialBase {
175175
}
176176
this.onDelSuperChat({ ids })
177177
}
178+
179+
// TODO: 欢迎入场 ws 的信息,然后给到 Room.vue
180+
async interactWordCallback(command) {
181+
if (!this.onInteractWord) {
182+
return
183+
}
184+
if (command.data.text_large) {
185+
return
186+
}
187+
let data = command.data
188+
// console.log(`interactWordCallback data 是 ${JSON.stringify(data, null, 4)}`)
189+
190+
data = {
191+
id: getUuid4Hex(),
192+
roomId: data.roomid,
193+
timestamp: data.timestamp,
194+
avatarUrl: await chat.getAvatarUrl(data.uid, data.uname),
195+
msgType: data.msg_type,
196+
authorName: data.uname,
197+
medalName: data.fans_medal.medal_level === 0 ? undefined : data.fans_medal.medal_name,
198+
medalLevel: data.fans_medal.medal_level === 0 ? undefined : data.fans_medal.medal_level,
199+
isFanGroup: data.roomid === data.fans_medal.medal_room_id ? true : false, // 是否是粉丝团(即粉丝勋章为当前直播间的粉丝勋章)
200+
privilegeType: data.fans_medal.guard_level // 所带勋章牌子的舰队等级,0非舰队,1总督,2提督,3舰长(不一定是当前直播间的粉丝勋章)
201+
}
202+
this.onInteractWord(data)
203+
}
204+
178205
}
179206

180207
const CMD_CALLBACK_MAP = {
181208
DANMU_MSG: ChatClientDirectWeb.prototype.danmuMsgCallback,
182209
SEND_GIFT: ChatClientDirectWeb.prototype.sendGiftCallback,
183210
GUARD_BUY: ChatClientDirectWeb.prototype.guardBuyCallback,
184211
SUPER_CHAT_MESSAGE: ChatClientDirectWeb.prototype.superChatMessageCallback,
185-
SUPER_CHAT_MESSAGE_DELETE: ChatClientDirectWeb.prototype.superChatMessageDeleteCallback
212+
SUPER_CHAT_MESSAGE_DELETE: ChatClientDirectWeb.prototype.superChatMessageDeleteCallback,
213+
INTERACT_WORD: ChatClientDirectWeb.prototype.interactWordCallback,
186214
}

frontend/src/api/chat/ChatClientOfficialBase/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export default class ChatClientOfficialBase {
5151
this.onAddSuperChat = null
5252
this.onDelSuperChat = null
5353
this.onUpdateTranslation = null
54-
this.onInteractWord = null
5554

5655
this.onFatalError = null
5756

@@ -161,7 +160,7 @@ export default class ChatClientOfficialBase {
161160
}
162161

163162
onReceiveTimeout() {
164-
window.console.warn('接收消息超时')
163+
console.warn('接收消息超时')
165164
this.discardWebsocket()
166165
}
167166

@@ -205,9 +204,10 @@ export default class ChatClientOfficialBase {
205204

206205
onWsMessage(event) {
207206
if (!(event.data instanceof ArrayBuffer)) {
208-
window.console.warn('未知的websocket消息类型,data=', event.data)
207+
console.warn('未知的websocket消息类型,data=', event.data)
209208
return
210209
}
210+
211211
let data = new Uint8Array(event.data)
212212
this.parseWsMessage(data)
213213

@@ -251,7 +251,7 @@ export default class ChatClientOfficialBase {
251251
default: {
252252
// 未知消息
253253
let body = new Uint8Array(data.buffer, offset + rawHeaderSize, packLen - rawHeaderSize)
254-
window.console.warn('未知包类型,operation=', operation, dataView, body)
254+
console.warn('未知包类型,operation=', operation, dataView, body)
255255
break
256256
}
257257
}
@@ -263,7 +263,6 @@ export default class ChatClientOfficialBase {
263263

264264
switch (operation) {
265265
case OP_SEND_MSG_REPLY: {
266-
267266
// 业务消息
268267
if (ver == WS_BODY_PROTOCOL_VERSION_BROTLI) {
269268
// 压缩过的先解压
@@ -280,7 +279,7 @@ export default class ChatClientOfficialBase {
280279
body = JSON.parse(textDecoder.decode(body))
281280
this.handlerCommand(body)
282281
} catch (e) {
283-
window.console.error('body=', body)
282+
console.error('body=', body)
284283
throw e
285284
}
286285
}
@@ -301,7 +300,7 @@ export default class ChatClientOfficialBase {
301300
}
302301
default: {
303302
// 未知消息
304-
window.console.warn('未知包类型,operation=', operation, dataView, body)
303+
console.warn('未知包类型,operation=', operation, dataView, body)
305304
break
306305
}
307306
}

frontend/src/api/chat/ChatClientRelay.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default class ChatClientRelay {
2626
this.onAddSuperChat = null
2727
this.onDelSuperChat = null
2828
this.onUpdateTranslation = null
29-
this.onInteractWord = null
3029

3130
this.onFatalError = null
3231

@@ -52,9 +51,7 @@ export default class ChatClientRelay {
5251
return
5352
}
5453
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'
55-
// 开发时使用localhost:12450
56-
const host = process.env.NODE_ENV === 'development' ? 'localhost:12450' : window.location.host
57-
const url = `${protocol}://${host}/api/chat`
54+
const url = `${protocol}://${window.location.host}/api/chat`
5855
this.websocket = new WebSocket(url)
5956
this.websocket.onopen = this.onWsOpen.bind(this)
6057
this.websocket.onclose = this.onWsClose.bind(this)

frontend/src/api/chat/ChatClientTest.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const MESSAGE_GENERATORS = [
243243
return {
244244
type: constants.MESSAGE_TYPE_INTERACT,
245245
message: {
246-
avatarUrl: avatar.DEFAULT_AVATAR_URL,
246+
avatarUrl: chat.DEFAULT_AVATAR_URL,
247247
timestamp: new Date().getTime() / 1000,
248248
msgType: randInt(1, 5),
249249
authorName: randomChoose(NAMES),
@@ -279,7 +279,6 @@ const MESSAGE_GENERATORS = [
279279
translation: '',
280280
emoticon: null,
281281
emots: randomChoose(EMOT_INFO_LIST),
282-
textEmoticons: [],
283282
}
284283
}
285284
}
@@ -305,7 +304,6 @@ const MESSAGE_GENERATORS = [
305304
translation: '',
306305
emoticon: randomChoose(EMOTICONS),
307306
emoticonDetail: randomChoose(EMOT_DETAIL_LIST),
308-
textEmoticons: [],
309307
}
310308
}
311309
}
@@ -321,8 +319,8 @@ const MESSAGE_GENERATORS = [
321319
id: getUuid4Hex(),
322320
avatarUrl: chat.DEFAULT_AVATAR_URL,
323321
timestamp: new Date().getTime() / 1000,
324-
authorName: randomChoose(NAMES)
325-
// num: 1
322+
authorName: randomChoose(NAMES),
323+
num: 1
326324
}
327325
}
328326
}

frontend/src/api/chatConfig.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ export function getLocalConfig() {
640640
}
641641
}
642642

643-
// FIXME: 前端上传表情包设置
644643
export function sanitizeConfig(config) {
645644
let newEmoticons = []
646645
if (config.emoticons instanceof Array) {

frontend/src/api/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import axios from 'axios'
2+
3+
export async function getServerInfo() {
4+
return (await axios.get('/api/server_info')).data
5+
}
6+
7+
export async function uploadEmoticon(file) {
8+
let body = new FormData()
9+
body.set('file', file)
10+
return (await axios.post('/api/emoticon', body)).data
11+
}

frontend/src/layout/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</router-link>
1010
</div>
1111
<div class="version">
12-
{{ APP_VERSION }}-230709
12+
{{ APP_VERSION }}-230917
1313
</div>
1414
<div class="version">
1515
<a href="https://space.bilibili.com/12236936" target="_blank">只熊KUMA</a>

0 commit comments

Comments
 (0)