Skip to content

Commit c271aa0

Browse files
author
Taois
committed
fix:代理播放功能优化
1 parent a3c9b6f commit c271aa0

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

dashboard/src/components/players/PlayerHeader.vue

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,21 @@ const loadProxyConfig = () => {
196196
// 先加载历史记录
197197
loadProxyHistory()
198198
199+
// 如果启用了代理播放且有配置地址
199200
if (proxyPlayEnabled && proxyPlay) {
200201
// 检查当前配置的代理是否已在历史记录中
201-
const exists = proxyOptions.value.some(option => option.url === proxyPlay)
202-
if (!exists) {
203-
// 如果不在历史记录中,添加到选项列表
202+
const existingIndex = proxyOptions.value.findIndex(option => option.url === proxyPlay)
203+
204+
if (existingIndex !== -1) {
205+
// 如果在历史记录中,将其移到最前面
206+
const currentOption = proxyOptions.value.splice(existingIndex, 1)[0]
207+
proxyOptions.value.unshift(currentOption)
208+
} else {
209+
// 如果不在历史记录中,添加到最前面
204210
const proxyName = getProxyName(proxyPlay)
205211
proxyOptions.value.unshift({
206212
value: proxyPlay,
207-
label: proxyName,
213+
label: `${proxyName} (当前)`,
208214
url: proxyPlay
209215
})
210216
}
@@ -215,6 +221,13 @@ const loadProxyConfig = () => {
215221
// 如果代理播放开关关闭,默认选择关闭
216222
currentProxyOption.value = 'disabled'
217223
}
224+
225+
console.log('代理播放配置加载完成:', {
226+
enabled: proxyPlayEnabled,
227+
current: proxyPlay,
228+
optionsCount: proxyOptions.value.length,
229+
selected: currentProxyOption.value
230+
})
218231
} catch (error) {
219232
console.error('加载代理播放配置失败:', error)
220233
currentProxyOption.value = 'disabled'
@@ -224,20 +237,27 @@ const loadProxyConfig = () => {
224237
// 加载代理播放地址历史记录
225238
const loadProxyHistory = () => {
226239
try {
227-
const history = JSON.parse(localStorage.getItem('proxy-play-history') || '[]')
240+
// 只从设置界面的存储位置加载
241+
const addressHistoryKey = 'address-history-proxy-play'
242+
const addressHistory = JSON.parse(localStorage.getItem(addressHistoryKey) || '[]')
228243
229-
// 添加历史记录到选项中(去重)
230-
history.forEach(item => {
231-
const exists = proxyOptions.value.some(option => option.url === item.url)
244+
// 添加历史记录到选项中
245+
addressHistory.forEach(item => {
246+
const url = item.url || item.value || ''
247+
if (!url) return
248+
249+
const exists = proxyOptions.value.some(option => option.url === url)
232250
if (!exists) {
233-
const proxyName = getProxyName(item.url)
251+
const proxyName = getProxyName(url)
234252
proxyOptions.value.push({
235-
value: item.url,
253+
value: url,
236254
label: proxyName,
237-
url: item.url
255+
url: url
238256
})
239257
}
240258
})
259+
260+
console.log('已加载代理播放历史记录:', proxyOptions.value.length, '个选项')
241261
} catch (error) {
242262
console.error('加载代理播放历史记录失败:', error)
243263
}
@@ -248,30 +268,35 @@ const saveToProxyHistory = (url) => {
248268
if (!url || url === 'disabled') return
249269
250270
try {
251-
const history = JSON.parse(localStorage.getItem('proxy-play-history') || '[]')
252271
const proxyName = getProxyName(url)
272+
const timestamp = Date.now()
273+
274+
// 只保存到设置界面使用的存储位置
275+
const addressHistoryKey = 'address-history-proxy-play'
276+
const addressHistory = JSON.parse(localStorage.getItem(addressHistoryKey) || '[]')
253277
254278
// 检查是否已存在
255-
const existingIndex = history.findIndex(item => item.url === url)
279+
const existingIndex = addressHistory.findIndex(item => item.url === url)
256280
257281
if (existingIndex !== -1) {
258282
// 如果存在,移到最前面
259-
history.splice(existingIndex, 1)
283+
addressHistory.splice(existingIndex, 1)
260284
}
261285
262286
// 添加到最前面
263-
history.unshift({
287+
addressHistory.unshift({
264288
url: url,
265-
name: proxyName,
266-
timestamp: Date.now()
289+
timestamp: timestamp
267290
})
268291
269292
// 限制历史记录数量(最多保存10个)
270-
if (history.length > 10) {
271-
history.splice(10)
293+
if (addressHistory.length > 10) {
294+
addressHistory.splice(10)
272295
}
273296
274-
localStorage.setItem('proxy-play-history', JSON.stringify(history))
297+
localStorage.setItem(addressHistoryKey, JSON.stringify(addressHistory))
298+
299+
console.log('已保存代理播放地址到历史记录:', url)
275300
} catch (error) {
276301
console.error('保存代理播放历史记录失败:', error)
277302
}

dashboard/src/utils/proxyPlayer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ export function buildProxyPlayUrl(originalUrl, proxyAddress, headers = {}) {
5353
// 对 URL 和 headers 进行 URL 安全的 base64 编码
5454
const encodedUrl = base64Encode(originalUrl)
5555
const encodedHeaders = base64Encode(headersJson)
56+
const encodedType = originalUrl.split('/').slice(-1)[0].split('?')[0]
5657

5758
// 替换模板字符串中的${url}和${headers}
5859
let proxyUrl = cleanProxyAddress
5960
.replace(/\$\{url\}/g, encodedUrl)
6061
.replace(/\$\{headers\}/g, encodedHeaders)
62+
.replace(/\$\{type\}/g, encodedType)
6163

6264
console.log('🔄 [代理播放] 构建代理URL:')
6365
console.log('📺 原始地址:', originalUrl)

dashboard/src/views/Settings.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ const addressSettings = reactive({
853853
liveConfig: '',
854854
proxyAccess: '',
855855
proxyAccessEnabled: false,
856-
proxyPlay: 'http://localhost:57572/proxy?form=base64&url=${url}&header=${headers}#嗷呜',
856+
proxyPlay: 'http://localhost:57572/proxy?form=base64&url=${url}&header=${headers}&type=${type}#嗷呜',
857857
proxyPlayEnabled: false,
858858
proxySniff: 'http://localhost:57573/sniffer',
859859
proxySniffEnabled: false,
@@ -1134,7 +1134,7 @@ const resetProxyPlay = async () => {
11341134
addressSaving.proxyPlayReset = true
11351135
try {
11361136
// 重置为默认值
1137-
addressSettings.proxyPlay = 'http://localhost:57572/proxy?form=base64&url=${url}&header=${headers}#嗷呜'
1137+
addressSettings.proxyPlay = 'http://localhost:57572/proxy?form=base64&url=${url}&header=${headers}&type=${type}#嗷呜'
11381138
addressSettings.proxyPlayEnabled = false
11391139
11401140
// 保存到本地存储
@@ -1332,7 +1332,7 @@ const resetAllSettings = () => {
13321332
liveConfig: '',
13331333
proxyAccess: '',
13341334
proxyAccessEnabled: false,
1335-
proxyPlay: 'http://localhost:57572/proxy?form=base64&url=${url}&header=${headers}#嗷呜',
1335+
proxyPlay: 'http://localhost:57572/proxy?form=base64&url=${url}&header=${headers}&type=${type}#嗷呜',
13361336
proxyPlayEnabled: false,
13371337
proxySniff: 'http://localhost:57573/sniffer',
13381338
proxySniffEnabled: false

0 commit comments

Comments
 (0)