optimize: usa重命名为cloudflare后,向下兼容原来的usa配置。

pull/321/head
王良 2024-07-08 16:48:15 +08:00
parent d1555d3238
commit 01e395c20b
7 changed files with 57 additions and 49 deletions

View File

@ -218,9 +218,9 @@ const intercepts = {
```js ```js
dns: { dns: {
mapping: { mapping: {
'api.github.com': 'usa', // "解决push的时候需要输入密码的问题", 'api.github.com': 'cloudflare', // "解决push的时候需要输入密码的问题",
'gist.github.com': 'usa' // 解决gist无法访问的问题 'gist.github.com': 'cloudflare' // 解决gist无法访问的问题
'*.githubusercontent.com': 'usa' // 解决github头像经常下载不到的问题 '*.githubusercontent.com': 'cloudflare' // 解决github头像经常下载不到的问题
} }
} }
``` ```

View File

@ -1,3 +1,4 @@
<!--
<template> <template>
<a-drawer <a-drawer
:title="title" :title="title"
@ -33,7 +34,7 @@
</a-col> </a-col>
<a-col :span="5"> <a-col :span="5">
<a-select :disabled="item.value === false" v-model="item.value"> <a-select :disabled="item.value === false" v-model="item.value">
<a-select-option value="usa">USA DNS</a-select-option> <a-select-option value="cloudflare">CloudFlare DNS</a-select-option>
<a-select-option value="aliyun">Aliyun DNS</a-select-option> <a-select-option value="aliyun">Aliyun DNS</a-select-option>
</a-select> </a-select>
</a-col> </a-col>
@ -246,3 +247,4 @@ export default {
margin-bottom: 10px; margin-bottom: 10px;
} }
</style> </style>
-->

View File

@ -7,7 +7,6 @@
</template> </template>
<div style="height: 100%" class="json-wrapper"> <div style="height: 100%" class="json-wrapper">
<a-tabs <a-tabs
default-active-key="1" default-active-key="1"
tab-position="left" tab-position="left"
@ -194,7 +193,7 @@
<a-icon v-if="item.alive.length>0" type="check"/> <a-icon v-if="item.alive.length>0" type="check"/>
<a-icon v-else type="info-circle"/> <a-icon v-else type="info-circle"/>
</a> </a>
<a-tag style="margin:2px;" v-for="(element,index) of item.backupList" <a-tag style="margin:2px;" v-for="(element,index) of item.backupList" :title="element.dns"
:color="element.time?'green':'red'" :key='index'>{{ element.host }} :color="element.time?'green':'red'" :key='index'>{{ element.host }}
{{ element.time }}{{ element.time ? 'ms' : '' }} {{ element.time }}{{ element.time ? 'ms' : '' }}
</a-tag> </a-tag>
@ -230,8 +229,8 @@ export default {
key: 'server', key: 'server',
dnsMappings: [], dnsMappings: [],
speedTestList: [], speedTestList: [],
whiteList: [], whiteList: []
sniList: [] // sniList: []
} }
}, },
created () { created () {
@ -270,7 +269,7 @@ export default {
ready () { ready () {
this.initDnsMapping() this.initDnsMapping()
this.initWhiteList() this.initWhiteList()
this.initSniList() // this.initSniList()
if (this.config.server.dns.speedTest.dnsProviders) { if (this.config.server.dns.speedTest.dnsProviders) {
this.speedDns = this.config.server.dns.speedTest.dnsProviders this.speedDns = this.config.server.dns.speedTest.dnsProviders
} }
@ -278,7 +277,7 @@ export default {
async applyBefore () { async applyBefore () {
this.submitDnsMapping() this.submitDnsMapping()
this.submitWhiteList() this.submitWhiteList()
this.submitSniList() // this.submitSniList()
}, },
async applyAfter () { async applyAfter () {
if (this.status.server.enabled) { if (this.status.server.enabled) {
@ -343,34 +342,34 @@ export default {
this.whiteList.unshift({ key: '', value: true }) this.whiteList.unshift({ key: '', value: true })
}, },
// sniList // // sniList
initSniList () { // initSniList () {
this.sniList = [] // this.sniList = []
for (const key in this.config.server.sniList) { // for (const key in this.config.server.sniList) {
const value = this.config.server.sniList[key] // const value = this.config.server.sniList[key]
this.sniList.push({ // this.sniList.push({
key, value // key, value
}) // })
} // }
}, // },
submitSniList () { // submitSniList () {
const sniList = {} // const sniList = {}
for (const item of this.sniList) { // for (const item of this.sniList) {
if (item.key) { // if (item.key) {
sniList[item.key] = item.value // sniList[item.key] = item.value
} // }
} // }
this.config.server.sniList = sniList // this.config.server.sniList = sniList
}, // },
deleteSniList (item, index) { // deleteSniList (item, index) {
this.sniList.splice(index, 1) // this.sniList.splice(index, 1)
}, // },
restoreDefSniList (item, index) { // restoreDefSniList (item, index) {
//
}, // },
addSniList () { // addSniList () {
this.sniList.unshift({ key: '', value: true }) // this.sniList.unshift({ key: '', value: true })
}, // },
async openLog () { async openLog () {
const dir = await this.$api.info.getConfigDir() const dir = await this.$api.info.getConfigDir()

View File

@ -54,6 +54,7 @@ module.exports = class DNSOverHTTPS extends BaseDNS {
return ['54.156.140.159', '52.44.227.212', '44.221.37.199'] return ['54.156.140.159', '52.44.227.212', '44.221.37.199']
} }
// 未预设当前域名的IP列表则从dns服务器获取
try { try {
const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }]) const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }])
if (result.answers.length === 0) { if (result.answers.length === 0) {

View File

@ -17,7 +17,13 @@ module.exports = {
return dnsMap return dnsMap
}, },
hasDnsLookup (dnsConfig, hostname) { hasDnsLookup (dnsConfig, hostname) {
const providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName') let providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
// usa已重命名为cloudflare以下为向下兼容处理
if (providerName === 'usa') {
providerName = 'cloudflare'
}
if (providerName) { if (providerName) {
return dnsConfig.providers[providerName] return dnsConfig.providers[providerName]
} }

View File

@ -8,7 +8,7 @@ const dnsMap = dns.initDNS({
// server: 'ipaddress', // server: 'ipaddress',
// cacheSize: 1000 // cacheSize: 1000
// }, // },
usa: { cloudflare: {
type: 'https', type: 'https',
server: 'https://1.1.1.1/dns-query', server: 'https://1.1.1.1/dns-query',
cacheSize: 1000 cacheSize: 1000

View File

@ -6,7 +6,7 @@ const dnsProviders = dns.initDNS({
server: 'https://dns.alidns.com/dns-query', server: 'https://dns.alidns.com/dns-query',
cacheSize: 1000 cacheSize: 1000
}, },
usa: { cloudflare: {
type: 'https', type: 'https',
server: 'https://1.1.1.1/dns-query', server: 'https://1.1.1.1/dns-query',
cacheSize: 1000 cacheSize: 1000
@ -54,24 +54,24 @@ const dnsProviders = dns.initDNS({
const hostname0 = 'github.com' const hostname0 = 'github.com'
// console.log('first') // console.log('first')
// dnsProviders.usa.lookup(hostname0) // dnsProviders.cloudflare.lookup(hostname0)
console.log('test') console.log('test')
dnsProviders.py233.lookup(hostname0) dnsProviders.py233.lookup(hostname0)
// dnsProviders.usa.lookup(hostname0) // dnsProviders.cloudflare.lookup(hostname0)
// dnsProviders.ipaddress.lookup(hostname0) // dnsProviders.ipaddress.lookup(hostname0)
// dnsProviders.ipaddress.lookup(hostname0) // dnsProviders.ipaddress.lookup(hostname0)
// const hostname = 'api.github.com' // const hostname = 'api.github.com'
// dnsProviders.usa.lookup(hostname) // dnsProviders.cloudflare.lookup(hostname)
// const hostname1 = 'api.github.com' // const hostname1 = 'api.github.com'
// dnsProviders.usa.lookup(hostname1) // dnsProviders.cloudflare.lookup(hostname1)
// //
// const hostname2 = 'hk.docmirror.cn' // const hostname2 = 'hk.docmirror.cn'
// dnsProviders.usa.lookup(hostname2) // dnsProviders.cloudflare.lookup(hostname2)
// const hostname3 = 'github.docmirror.cn' // const hostname3 = 'github.docmirror.cn'
// dnsProviders.usa.lookup(hostname3) // dnsProviders.cloudflare.lookup(hostname3)
// const hostname4 = 'gh.docmirror.top' // const hostname4 = 'gh.docmirror.top'
// dnsProviders.usa.lookup(hostname4) // dnsProviders.cloudflare.lookup(hostname4)
// const hostname5 = 'gh2.docmirror.top' // const hostname5 = 'gh2.docmirror.top'
// dnsProviders.usa.lookup(hostname5) // dnsProviders.cloudflare.lookup(hostname5)