diff --git a/2MB.bin b/2MB.bin new file mode 100644 index 0000000..3301331 Binary files /dev/null and b/2MB.bin differ diff --git a/65536.bin b/65536.bin deleted file mode 100644 index c97c12f..0000000 Binary files a/65536.bin and /dev/null differ diff --git a/README.md b/README.md index f1461c8..a615204 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ [issues](https://github.com/HolographicHat/genshin-achievement-export/issues)或[QQ群: 913777414](https://qm.qq.com/cgi-bin/qm/qr?k=9UGz-chQVTjZa4b82RA_A41vIcBVNpms&jump_from=webapi) ## 常见问题 -0. Q: 程序异常退出或被强行终止后,原神启动时报错: 无法连接网络(4201) +0. Q: 程序异常退出或被强行终止后,程序报错:网络错误(22-1) 或 原神启动时报错: 无法连接网络(4201) A: 用文本编辑器打开```C:\Windows\System32\drivers\etc\hosts```,删除```127.0.0.1 dispatch**global.yuanshen.com```后保存,重启原神 1. Q: 原神启动时报错: 数据异常(31-4302) diff --git a/utils.js b/utils.js index 929329d..18711b7 100644 --- a/utils.js +++ b/utils.js @@ -129,7 +129,7 @@ const md5 = str => { return h.digest("hex") } -let cdnUrlFormat = null +let cdnUrlFormat = undefined String.prototype.format = function() { const args = arguments; @@ -137,35 +137,31 @@ String.prototype.format = function() { } const checkCDN = async () => { - try { - cdnUrlFormat = "https://cdn.jsdelivr.net/gh/{0}@master/{1}" - await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore")) - return - } catch (e) {} - try { - cdnUrlFormat = "https://raw.githubusercontent.com/{0}/master/{1}" - await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore")) - return - } catch (e) {} - try { - const s = conf === undefined ? "" : conf.customCDN.trim() - if (s.length > 0) { - cdnUrlFormat = s - await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore")) - return - } - } catch (e) {} - try { - cdnUrlFormat = "https://raw.fastgit.org/{0}/master/{1}" - await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore")) - return - } catch (e) {} - try { - cdnUrlFormat = "https://ghproxy.net/https://raw.githubusercontent.com/{0}/master/{1}" - await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore")) - return - } catch (e) {} - throw "网络错误,请检查配置文件/网络后重试 (11-3)" + const controller = new AbortController() + const a = new Promise(resolve => axios.get("https://cdn.jsdelivr.net/gh/HolographicHat/genshin-achievement-export@master/2MB.bin", { + signal: controller.signal + }).then(_ => resolve(["jsdelivr", "https://cdn.jsdelivr.net/gh/{0}@master/{1}"]))) + const b = new Promise(resolve => axios.get("https://raw.githubusercontent.com/HolographicHat/genshin-achievement-export/master/2MB.bin", { + signal: controller.signal + }).then(_ => resolve(["githubusercontent", "https://raw.githubusercontent.com/{0}/master/{1}"]))) + const c = new Promise(resolve => axios.get("https://ghproxy.net/https://raw.githubusercontent.com/HolographicHat/genshin-achievement-export/master/2MB.bin", { + signal: controller.signal + }).then(_ => resolve(["ghproxy", "https://ghproxy.net/https://raw.githubusercontent.com/{0}/master/{1}"]))) + const d = new Promise(resolve => { + const s = conf === undefined ? "" : conf.customCDN.trim() // 🤔 + if (s.length === 0) throw "empty" + axios.get(s.format("HolographicHat/genshin-achievement-export", "2MB.bin"), { + signal: controller.signal + }).then(_ => resolve(["customCDN", s])) + }) + await Promise.any([a, b, c, d]).then(([name, url]) => { + debug(`Fastest: ${name}`) + controller.abort() + cdnUrlFormat = url + }).catch() + if (cdnUrlFormat === undefined) { + throw "网络错误,请检查配置文件/网络后重试 (11-3)" + } } const loadCache = async (fp, repo = "Dimbreath/GenshinData") => { @@ -203,7 +199,7 @@ const loadCache = async (fp, repo = "Dimbreath/GenshinData") => { } } -const isDebug = false +const isDebug = true const debug = (msg, ...params) => { if (isDebug) log(msg, ...params)