|
| 1 | +const getLocationHost = () => { |
| 2 | + if (typeof location === 'undefined') { |
| 3 | + return '' |
| 4 | + } |
| 5 | + |
| 6 | + return location.href.substring(0, location.href.indexOf('/', 10)) |
| 7 | +} |
| 8 | + |
| 9 | +const getEnvValue = (key, fallback = '') => { |
| 10 | + const value = import.meta.env[key] |
| 11 | + return value === undefined || value === null || value === '' ? fallback : value |
| 12 | +} |
| 13 | + |
| 14 | +const getEnvBoolean = (key, fallback = false) => { |
| 15 | + const value = import.meta.env[key] |
| 16 | + if (value === undefined || value === null || value === '') { |
| 17 | + return fallback |
| 18 | + } |
| 19 | + |
| 20 | + return value === 'true' || value === '1' |
| 21 | +} |
| 22 | + |
| 23 | +const getEnvNumber = (key, fallback) => { |
| 24 | + const value = Number(import.meta.env[key]) |
| 25 | + return Number.isFinite(value) ? value : fallback |
| 26 | +} |
| 27 | + |
| 28 | +const withLocationHost = (value) => value.replaceAll('${locationHost}', getLocationHost()) |
| 29 | + |
| 30 | +export const getDefaultAddressSettings = () => ({ |
| 31 | + vodConfig: withLocationHost(getEnvValue('VITE_DEFAULT_VOD_CONFIG', 'http://127.0.0.1:5757/config/1?healthy=1&pwd=dzyyds')), |
| 32 | + liveConfig: withLocationHost(getEnvValue('VITE_DEFAULT_LIVE_CONFIG', '')), |
| 33 | + proxyAccess: withLocationHost(getEnvValue('VITE_DEFAULT_PROXY_ACCESS', 'http://127.0.0.1:5757/req/${url}')), |
| 34 | + proxyAccessEnabled: getEnvBoolean('VITE_DEFAULT_PROXY_ACCESS_ENABLED', true), |
| 35 | + proxyPlay: withLocationHost(getEnvValue('VITE_DEFAULT_PROXY_PLAY', 'http://localhost:5757/unified-proxy/proxy?form=base64&auth=drpys&url=${url}&headers=${headers}&type=${type}#DS')), |
| 36 | + proxyPlayEnabled: getEnvBoolean('VITE_DEFAULT_PROXY_PLAY_ENABLED', false), |
| 37 | + proxySniff: withLocationHost(getEnvValue('VITE_DEFAULT_PROXY_SNIFF', 'http://localhost:57573/sniffer')), |
| 38 | + proxySniffEnabled: getEnvBoolean('VITE_DEFAULT_PROXY_SNIFF_ENABLED', false), |
| 39 | + snifferTimeout: getEnvNumber('VITE_DEFAULT_SNIFFER_TIMEOUT', 10), |
| 40 | + apiTimeout: getEnvNumber('VITE_DEFAULT_API_TIMEOUT', 30) |
| 41 | +}) |
| 42 | + |
| 43 | +export const getDefaultAppSettings = () => ({ |
| 44 | + datasourceDisplay: getEnvBoolean('VITE_DEFAULT_DATASOURCE_DISPLAY', true), |
| 45 | + windowPreview: getEnvBoolean('VITE_DEFAULT_WINDOW_PREVIEW', true), |
| 46 | + playerType: getEnvValue('VITE_DEFAULT_PLAYER_TYPE', 'ijk'), |
| 47 | + adFilter: getEnvBoolean('VITE_DEFAULT_AD_FILTER', true), |
| 48 | + ijkCache: getEnvBoolean('VITE_DEFAULT_IJK_CACHE', false), |
| 49 | + autoLive: getEnvBoolean('VITE_DEFAULT_AUTO_LIVE', false), |
| 50 | + secureDns: getEnvBoolean('VITE_DEFAULT_SECURE_DNS', false), |
| 51 | + cspBypass: getEnvBoolean('VITE_DEFAULT_CSP_BYPASS', true), |
| 52 | + referrerPolicy: getEnvValue('VITE_DEFAULT_REFERRER_POLICY', 'no-referrer'), |
| 53 | + searchAggregation: getEnvBoolean('VITE_DEFAULT_SEARCH_AGGREGATION', false), |
| 54 | + themeMode: getEnvValue('VITE_DEFAULT_THEME_MODE', 'light') |
| 55 | +}) |
| 56 | + |
| 57 | +export const initDefaultLocalStorage = () => { |
| 58 | + const addressSettings = getDefaultAddressSettings() |
| 59 | + const appSettings = getDefaultAppSettings() |
| 60 | + |
| 61 | + if (!localStorage.getItem('drplayer_config_url') && addressSettings.vodConfig) { |
| 62 | + localStorage.setItem('drplayer_config_url', addressSettings.vodConfig) |
| 63 | + } |
| 64 | + |
| 65 | + if (!localStorage.getItem('addressSettings')) { |
| 66 | + localStorage.setItem('addressSettings', JSON.stringify(addressSettings, null, 4)) |
| 67 | + } |
| 68 | + |
| 69 | + if (!localStorage.getItem('appSettings')) { |
| 70 | + localStorage.setItem('appSettings', JSON.stringify(appSettings)) |
| 71 | + } |
| 72 | + |
| 73 | + if (!localStorage.getItem('address-history-vod-config') && addressSettings.vodConfig) { |
| 74 | + localStorage.setItem('address-history-vod-config', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.vodConfig }])) |
| 75 | + } |
| 76 | + |
| 77 | + if (!localStorage.getItem('address-history-live-config') && addressSettings.liveConfig) { |
| 78 | + localStorage.setItem('address-history-live-config', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.liveConfig }])) |
| 79 | + } |
| 80 | + |
| 81 | + if (!localStorage.getItem('address-history-proxy-access') && addressSettings.proxyAccess) { |
| 82 | + localStorage.setItem('address-history-proxy-access', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.proxyAccess }])) |
| 83 | + } |
| 84 | + |
| 85 | + if (!localStorage.getItem('address-history-proxy-play') && addressSettings.proxyPlay) { |
| 86 | + localStorage.setItem('address-history-proxy-play', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.proxyPlay }])) |
| 87 | + } |
| 88 | + |
| 89 | + if (!localStorage.getItem('address-history-proxy-sniff') && addressSettings.proxySniff) { |
| 90 | + localStorage.setItem('address-history-proxy-sniff', JSON.stringify([{ timestamp: Date.now(), url: addressSettings.proxySniff }])) |
| 91 | + } |
| 92 | + |
| 93 | + if (!localStorage.getItem('drplayer_preferred_player_type')) { |
| 94 | + localStorage.setItem('drplayer_preferred_player_type', getEnvValue('VITE_DEFAULT_PREFERRED_PLAYER_TYPE', 'artplayer')) |
| 95 | + } |
| 96 | + |
| 97 | + if (!localStorage.getItem('autoNextEnabled')) { |
| 98 | + localStorage.setItem('autoNextEnabled', JSON.stringify(getEnvBoolean('VITE_DEFAULT_AUTO_NEXT_ENABLED', true))) |
| 99 | + } |
| 100 | + |
| 101 | + if (!localStorage.getItem('loopEnabled')) { |
| 102 | + localStorage.setItem('loopEnabled', JSON.stringify(getEnvBoolean('VITE_DEFAULT_LOOP_ENABLED', false))) |
| 103 | + } |
| 104 | +} |
0 commit comments