-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathdefaults.js
More file actions
104 lines (84 loc) · 4.72 KB
/
Copy pathdefaults.js
File metadata and controls
104 lines (84 loc) · 4.72 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
const getLocationHost = () => {
if (typeof location === 'undefined') {
return ''
}
return location.href.substring(0, location.href.indexOf('/', 10))
}
const getEnvValue = (key, fallback = '') => {
const value = import.meta.env[key]
return value === undefined || value === null || value === '' ? fallback : value
}
const getEnvBoolean = (key, fallback = false) => {
const value = import.meta.env[key]
if (value === undefined || value === null || value === '') {
return fallback
}
return value === 'true' || value === '1'
}
const getEnvNumber = (key, fallback) => {
const value = Number(import.meta.env[key])
return Number.isFinite(value) ? value : fallback
}
const withLocationHost = (value) => value.replaceAll('${locationHost}', getLocationHost())
export const getDefaultAddressSettings = () => ({
vodConfig: withLocationHost(getEnvValue('VITE_DEFAULT_VOD_CONFIG', 'http://127.0.0.1:5757/config/1?healthy=1&pwd=dzyyds')),
liveConfig: withLocationHost(getEnvValue('VITE_DEFAULT_LIVE_CONFIG', '')),
proxyAccess: withLocationHost(getEnvValue('VITE_DEFAULT_PROXY_ACCESS', 'http://127.0.0.1:5757/req/${url}')),
proxyAccessEnabled: getEnvBoolean('VITE_DEFAULT_PROXY_ACCESS_ENABLED', true),
proxyPlay: withLocationHost(getEnvValue('VITE_DEFAULT_PROXY_PLAY', 'http://localhost:5757/unified-proxy/proxy?form=base64&auth=drpys&url=${url}&headers=${headers}&type=${type}#DS')),
proxyPlayEnabled: getEnvBoolean('VITE_DEFAULT_PROXY_PLAY_ENABLED', false),
proxySniff: withLocationHost(getEnvValue('VITE_DEFAULT_PROXY_SNIFF', 'http://localhost:57573/sniffer')),
proxySniffEnabled: getEnvBoolean('VITE_DEFAULT_PROXY_SNIFF_ENABLED', false),
snifferTimeout: getEnvNumber('VITE_DEFAULT_SNIFFER_TIMEOUT', 10),
apiTimeout: getEnvNumber('VITE_DEFAULT_API_TIMEOUT', 30)
})
export const getDefaultAppSettings = () => ({
datasourceDisplay: getEnvBoolean('VITE_DEFAULT_DATASOURCE_DISPLAY', true),
windowPreview: getEnvBoolean('VITE_DEFAULT_WINDOW_PREVIEW', true),
playerType: getEnvValue('VITE_DEFAULT_PLAYER_TYPE', 'ijk'),
adFilter: getEnvBoolean('VITE_DEFAULT_AD_FILTER', true),
ijkCache: getEnvBoolean('VITE_DEFAULT_IJK_CACHE', false),
autoLive: getEnvBoolean('VITE_DEFAULT_AUTO_LIVE', false),
secureDns: getEnvBoolean('VITE_DEFAULT_SECURE_DNS', false),
cspBypass: getEnvBoolean('VITE_DEFAULT_CSP_BYPASS', true),
referrerPolicy: getEnvValue('VITE_DEFAULT_REFERRER_POLICY', 'no-referrer'),
searchAggregation: getEnvBoolean('VITE_DEFAULT_SEARCH_AGGREGATION', false),
themeMode: getEnvValue('VITE_DEFAULT_THEME_MODE', 'light')
})
export const initDefaultLocalStorage = () => {
const addressSettings = getDefaultAddressSettings()
const appSettings = getDefaultAppSettings()
if (!localStorage.getItem('drplayer_config_url') && addressSettings.vodConfig) {
localStorage.setItem('drplayer_config_url', addressSettings.vodConfig)
}
if (!localStorage.getItem('addressSettings')) {
localStorage.setItem('addressSettings', JSON.stringify(addressSettings, null, 4))
}
if (!localStorage.getItem('appSettings')) {
localStorage.setItem('appSettings', JSON.stringify(appSettings))
}
if (!localStorage.getItem('address-history-vod-config') && addressSettings.vodConfig) {
localStorage.setItem('address-history-vod-config', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.vodConfig }]))
}
if (!localStorage.getItem('address-history-live-config') && addressSettings.liveConfig) {
localStorage.setItem('address-history-live-config', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.liveConfig }]))
}
if (!localStorage.getItem('address-history-proxy-access') && addressSettings.proxyAccess) {
localStorage.setItem('address-history-proxy-access', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.proxyAccess }]))
}
if (!localStorage.getItem('address-history-proxy-play') && addressSettings.proxyPlay) {
localStorage.setItem('address-history-proxy-play', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.proxyPlay }]))
}
if (!localStorage.getItem('address-history-proxy-sniff') && addressSettings.proxySniff) {
localStorage.setItem('address-history-proxy-sniff', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.proxySniff }]))
}
if (!localStorage.getItem('drplayer_preferred_player_type')) {
localStorage.setItem('drplayer_preferred_player_type', getEnvValue('VITE_DEFAULT_PREFERRED_PLAYER_TYPE', 'artplayer'))
}
if (!localStorage.getItem('autoNextEnabled')) {
localStorage.setItem('autoNextEnabled', JSON.stringify(getEnvBoolean('VITE_DEFAULT_AUTO_NEXT_ENABLED', true)))
}
if (!localStorage.getItem('loopEnabled')) {
localStorage.setItem('loopEnabled', JSON.stringify(getEnvBoolean('VITE_DEFAULT_LOOP_ENABLED', false)))
}
}