Skip to content

Commit 672ae03

Browse files
author
Taois
committed
feat: 完成嗅探功能调优
1 parent d190191 commit 672ae03

File tree

3 files changed

+62
-33
lines changed

3 files changed

+62
-33
lines changed

dashboard/src/api/services/sniffer.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
export const sniffVideo = async (urlOrParseData, options = {}) => {
1717
const {
1818
snifferUrl = 'http://localhost:57573/sniffer',
19-
timeout = 15,
19+
timeout = 10,
2020
mode = '0',
2121
is_pc = '0'
2222
} = options
@@ -149,7 +149,7 @@ export const getSnifferConfig = () => {
149149
return {
150150
enabled: parsed.proxySniffEnabled || false,
151151
url: parsed.proxySniff || 'http://localhost:57573/sniffer',
152-
timeout: parsed.snifferTimeout || 15
152+
timeout: parsed.snifferTimeout || 10
153153
}
154154
}
155155
} catch (error) {
@@ -160,17 +160,39 @@ export const getSnifferConfig = () => {
160160
return {
161161
enabled: false,
162162
url: 'http://localhost:57573/sniffer',
163-
timeout: 15
163+
timeout: 10
164164
}
165165
}
166166

167167
/**
168-
* 检查是否启用嗅探功能
169-
* @returns {boolean} 是否启用嗅探
168+
* 检查嗅探器是否启用
169+
* @returns {boolean} 是否启用
170170
*/
171171
export const isSnifferEnabled = () => {
172172
const config = getSnifferConfig()
173-
return config.enabled && config.url
173+
174+
// 检查URL是否有效
175+
const hasValidUrl = config.url && config.url.trim() !== '' && config.url !== 'undefined'
176+
177+
if (!hasValidUrl) {
178+
return false
179+
}
180+
181+
// 检查是否有保存的设置
182+
try {
183+
const savedAddresses = localStorage.getItem('addressSettings')
184+
if (savedAddresses) {
185+
const parsed = JSON.parse(savedAddresses)
186+
// 如果用户明确保存了设置,使用保存的enabled状态
187+
return parsed.proxySniffEnabled === true
188+
}
189+
} catch (error) {
190+
console.error('检查嗅探器配置失败:', error)
191+
}
192+
193+
// 如果没有保存的设置,但有有效的URL(包括默认URL),认为嗅探可用
194+
// 这样可以处理用户打开开关但未保存设置的情况
195+
return true
174196
}
175197

176198
/**

dashboard/src/views/Settings.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ const addressSettings = reactive({
832832
proxyPlayEnabled: false,
833833
proxySniff: 'http://localhost:57573/sniffer',
834834
proxySniffEnabled: false,
835-
snifferTimeout: 15
835+
snifferTimeout: 10
836836
})
837837
838838
const addressSaving = reactive({
@@ -888,8 +888,20 @@ const playerSelectVisible = ref(false)
888888
const saveAddress = async (configType) => {
889889
const addressValue = addressSettings[configType]
890890
891-
if (!addressValue || !addressValue.trim()) {
892-
Message.warning('请输入地址')
891+
// 对于字符串类型,检查是否为空或只包含空白字符
892+
// 对于数字类型,检查是否为有效数字
893+
if (typeof addressValue === 'string') {
894+
if (!addressValue || !addressValue.trim()) {
895+
Message.warning('请输入地址')
896+
return
897+
}
898+
} else if (typeof addressValue === 'number') {
899+
if (isNaN(addressValue) || addressValue <= 0) {
900+
Message.warning('请输入有效的数值')
901+
return
902+
}
903+
} else {
904+
Message.warning('请输入有效的配置值')
893905
return
894906
}
895907
@@ -1306,7 +1318,7 @@ const loadConfig = async () => {
13061318
}
13071319
// 确保嗅探超时有默认值
13081320
if (!addressSettings.snifferTimeout) {
1309-
addressSettings.snifferTimeout = 15
1321+
addressSettings.snifferTimeout = 10
13101322
}
13111323
} catch (error) {
13121324
console.error('Failed to load address settings:', error)

dashboard/src/views/VideoDetail.vue

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,7 @@
218218
{{ parseDialogConfig.message }}
219219
</div>
220220

221-
<!-- 嗅探进度显示 -->
222-
<div v-if="sniffing" class="sniff-progress">
223-
<div class="progress-icon">
224-
<a-spin :size="16" />
225-
</div>
226-
<div class="progress-text">
227-
{{ sniffProgress }}
228-
</div>
229-
</div>
221+
230222

231223
<!-- 嗅探结果显示 -->
232224
<div v-if="sniffResults.length > 0" class="sniff-results">
@@ -249,7 +241,7 @@
249241
</div>
250242
</div>
251243

252-
<div v-if="!sniffing && parseDialogConfig.type !== 'sniff'" class="parse-hint">
244+
<div v-if="!sniffing" class="parse-hint">
253245
<div class="hint-icon">
254246
<icon-eye />
255247
</div>
@@ -356,7 +348,6 @@ const parseDialogConfig = ref({
356348
357349
// 嗅探相关
358350
const sniffing = ref(false)
359-
const sniffProgress = ref('')
360351
const sniffResults = ref([])
361352
362353
// 从localStorage读取用户的播放器偏好,默认为'default'
@@ -1062,13 +1053,8 @@ const selectEpisode = async (index) => {
10621053
// 执行嗅探,传递原始的T4数据(parseResult.data)
10631054
const sniffSuccess = await sniffVideoUrl(parseResult.data)
10641055
if (!sniffSuccess) {
1065-
// 嗅探失败,显示错误信息
1066-
parseDialogConfig.value = {
1067-
title: '嗅探失败',
1068-
message: sniffProgress.value || '嗅探视频链接失败,请检查嗅探器配置或稍后重试。',
1069-
type: 'sniff'
1070-
}
1071-
showParseDialog.value = true
1056+
// 嗅探失败,已在sniffVideoUrl函数中通过Message.error显示错误信息
1057+
// 不需要额外的弹窗处理
10721058
}
10731059
}
10741060
} else if (parseResult.playType === 'parse') {
@@ -1150,15 +1136,22 @@ const selectEpisode = async (index) => {
11501136
11511137
// 嗅探视频链接
11521138
const sniffVideoUrl = async (parseDataOrUrl) => {
1139+
let loadingMessage = null
1140+
11531141
try {
11541142
// 检查嗅探功能是否启用
11551143
if (!isSnifferEnabled()) {
11561144
throw new Error('嗅探功能未启用,请在设置中配置嗅探器')
11571145
}
11581146
11591147
sniffing.value = true
1160-
sniffProgress.value = '正在启动嗅探器,请稍等...'
11611148
sniffResults.value = []
1149+
1150+
// 使用全局消息提示,设置duration为0让消息持续显示直到手动关闭
1151+
loadingMessage = Message.info({
1152+
content: '正在全力嗅探中,请稍等...',
1153+
duration: 0
1154+
})
11621155
11631156
console.log('开始嗅探视频链接:', parseDataOrUrl)
11641157
@@ -1167,12 +1160,10 @@ const sniffVideoUrl = async (parseDataOrUrl) => {
11671160
if (typeof parseDataOrUrl === 'object' && parseDataOrUrl.parse === 1) {
11681161
// T4解析数据格式,直接使用
11691162
sniffData = parseDataOrUrl
1170-
sniffProgress.value = '正在全力嗅探中,请稍等...'
11711163
console.log('使用T4解析数据进行嗅探:', sniffData)
11721164
} else {
11731165
// 普通URL格式
11741166
sniffData = typeof parseDataOrUrl === 'string' ? parseDataOrUrl : parseDataOrUrl.toString()
1175-
sniffProgress.value = '正在全力嗅探中,请稍等...'
11761167
console.log('使用普通URL进行嗅探:', sniffData)
11771168
}
11781169
@@ -1206,7 +1197,8 @@ const sniffVideoUrl = async (parseDataOrUrl) => {
12061197
throw new Error('嗅探结果格式无效')
12071198
}
12081199
1209-
sniffProgress.value = `嗅探完成,找到 ${videoCount} 个视频链接`
1200+
// 关闭loading消息
1201+
loadingMessage.close()
12101202
12111203
// 自动选择第一个链接进行播放
12121204
const firstVideo = videoData[0]
@@ -1230,7 +1222,10 @@ const sniffVideoUrl = async (parseDataOrUrl) => {
12301222
12311223
} catch (error) {
12321224
console.error('嗅探失败:', error)
1233-
sniffProgress.value = `嗅探失败: ${error.message}`
1225+
// 关闭loading消息(如果存在)
1226+
if (loadingMessage) {
1227+
loadingMessage.close()
1228+
}
12341229
Message.error(`嗅探失败: ${error.message}`)
12351230
return false
12361231
} finally {

0 commit comments

Comments
 (0)