-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathresetService.js
More file actions
210 lines (183 loc) · 5.33 KB
/
resetService.js
File metadata and controls
210 lines (183 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
* 重置服务
* 负责应用的出厂重置功能
*/
import { Message, Modal } from '@arco-design/web-vue'
import { saveCSPConfig, setGlobalReferrerPolicy } from '@/utils/csp'
// 默认配置值
const DEFAULT_CONFIGS = {
// 地址设置默认值
addressSettings: {
vodConfig: '',
liveConfig: '',
proxyAccess: '',
proxyAccessEnabled: false,
proxyPlay: 'http://localhost:57572/proxy?form=base64&url=${url}&headers=${headers}&type=${type}#嗷呜',
proxyPlayEnabled: false,
proxySniff: 'http://localhost:57573/sniffer',
proxySniffEnabled: false,
snifferTimeout: 10,
apiTimeout: 30
},
// 应用设置默认值
appSettings: {
datasourceDisplay: true,
windowPreview: true,
playerType: 'ijk',
adFilter: true,
ijkCache: false,
autoLive: false,
secureDns: false,
cspBypass: true,
referrerPolicy: 'no-referrer',
searchAggregation: false // 聚合搜索功能默认关闭
},
// CSP配置默认值
cspConfig: {
enabled: true,
referrerPolicy: 'no-referrer'
},
// 跳过设置默认值
skipSettings: {},
// 解析器配置默认值
parserConfig: {},
// 页面状态默认值
pageState: {},
// 聚合搜索设置默认值
searchAggregationSettings: {
selectedSources: [] // 默认没有选中任何搜索源
},
// 侧边栏状态默认值
sidebarCollapsed: false
}
// 需要完全清空的数据键
const CLEAR_DATA_KEYS = [
// 用户数据
'drplayer-favorites', // 收藏列表
'drplayer_watch_history', // 观看历史
'drplayer_histories', // 历史页面数据
'drplayer_daily_stats', // 每日统计
'drplayer_weekly_stats', // 周统计
'drplayer_parsers', // 解析器数据
// 聚合搜索相关
'searchAggregationSettings', // 聚合搜索源选择设置
'pageState_searchAggregation', // 聚合搜索页面状态
'drplayer_search_history', // 搜索历史记录
// 站点数据
'siteStore', // 站点存储
'drplayer_config_url', // 配置地址
'drplayer_live_config_url', // 直播配置地址
'drplayer_current_site', // 当前站点
'drplayer_sites', // 站点列表数据
'site-nowSite', // 当前站点(兼容旧系统)
// 配置数据
'drplayer_config_data', // 配置数据缓存
'drplayer_config_fetch_time', // 配置获取时间
// 播放器相关
'drplayer_preferred_player_type', // 首选播放器类型
'selectedParser', // 选中的解析器
'last-clicked-video', // 最后点击的视频
// 界面状态
'sidebar-collapsed', // 侧边栏折叠状态
// 地址配置历史
'drplayer_vod_config_history',
'drplayer_live_config_history',
'drplayer_proxy_access_history',
'drplayer_proxy_play_history',
'drplayer_proxy_sniff_history'
]
/**
* 显示重置确认对话框
*/
export const showResetConfirmation = () => {
return new Promise((resolve) => {
Modal.confirm({
title: '确认重置',
content: `此操作将执行完整的出厂重置,包括:
• 重置所有配置接口地址为默认值
• 清空收藏列表
• 清空观看历史记录
• 清空解析器数据
• 清空站点数据
• 重置所有应用设置
⚠️ 此操作不可撤销,请确认是否继续?`,
width: 480,
closable: true,
okText: '确认重置',
cancelText: '取消',
okButtonProps: {
status: 'danger'
},
onOk: () => {
resolve(true)
},
onCancel: () => {
resolve(false)
}
})
})
}
/**
* 执行完整的出厂重置
*/
export const performFactoryReset = async () => {
try {
// 1. 清空需要删除的数据
CLEAR_DATA_KEYS.forEach(key => {
localStorage.removeItem(key)
})
// 2. 重置配置为默认值
Object.entries(DEFAULT_CONFIGS).forEach(([key, defaultValue]) => {
if (defaultValue !== null && defaultValue !== undefined) {
localStorage.setItem(key, JSON.stringify(defaultValue))
}
})
// 3. 重置CSP配置
try {
saveCSPConfig(DEFAULT_CONFIGS.cspConfig)
setGlobalReferrerPolicy('no-referrer')
} catch (error) {
console.warn('CSP配置重置失败:', error)
}
// 4. 显示成功消息
Message.success({
content: '出厂重置完成!应用已恢复到初始状态',
duration: 3000
})
// 5. 建议用户刷新页面
setTimeout(() => {
Modal.info({
title: '重置完成',
content: '为确保所有更改生效,建议刷新页面。是否立即刷新?',
okText: '立即刷新',
cancelText: '稍后刷新',
onOk: () => {
window.location.reload()
}
})
}, 1000)
return true
} catch (error) {
console.error('出厂重置失败:', error)
Message.error({
content: '出厂重置失败,请重试',
duration: 3000
})
return false
}
}
/**
* 带确认的出厂重置函数
*/
export const factoryResetWithConfirmation = async () => {
const confirmed = await showResetConfirmation()
if (confirmed) {
return await performFactoryReset()
}
return false
}
export default {
showResetConfirmation,
performFactoryReset,
factoryResetWithConfirmation
}