mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-14 10:28:15 +08:00
v1.0.0
This commit is contained in:
9
app.js
9
app.js
@@ -3,7 +3,7 @@ const proxy = require("udp-proxy")
|
|||||||
const cp = require("child_process")
|
const cp = require("child_process")
|
||||||
const rs = require("./regionServer")
|
const rs = require("./regionServer")
|
||||||
const appcenter = require("./appcenter")
|
const appcenter = require("./appcenter")
|
||||||
const { initConfig, splitPacket, upload, decodeProto, log, setupHost, KPacket, debug, checkCDN, checkUpdate, keypress} = require("./utils")
|
const { initConfig, splitPacket, upload, decodeProto, log, setupHost, KPacket, debug, checkCDN, checkUpdate } = require("./utils")
|
||||||
const { exportData } = require("./export");
|
const { exportData } = require("./export");
|
||||||
|
|
||||||
// TODO: i18n
|
// TODO: i18n
|
||||||
@@ -62,6 +62,7 @@ const { exportData } = require("./export");
|
|||||||
hServer.close()
|
hServer.close()
|
||||||
gameProcess.kill()
|
gameProcess.kill()
|
||||||
clearInterval(monitor)
|
clearInterval(monitor)
|
||||||
|
setupHost(true)
|
||||||
console.log("正在处理数据,请稍后...")
|
console.log("正在处理数据,请稍后...")
|
||||||
let packets = Array.from(cache.values())
|
let packets = Array.from(cache.values())
|
||||||
cache.clear()
|
cache.clear()
|
||||||
@@ -94,8 +95,8 @@ const { exportData } = require("./export");
|
|||||||
const data = zlib.brotliDecompressSync(response.data)
|
const data = zlib.brotliDecompressSync(response.data)
|
||||||
const proto = await decodeProto(data,"AllAchievement")
|
const proto = await decodeProto(data,"AllAchievement")
|
||||||
await exportData(proto)
|
await exportData(proto)
|
||||||
console.log("按任意键退出.")
|
console.log("按任意键退出")
|
||||||
await keypress()
|
cp.execSync("pause > nul", { stdio: "inherit" })
|
||||||
}
|
}
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
@@ -131,7 +132,7 @@ const { exportData } = require("./export");
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
return server
|
return server
|
||||||
}).then(() => console.log("加载完毕."))
|
}).then(() => console.log("加载完毕"))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
appcenter.uploadError(e, true)
|
appcenter.uploadError(e, true)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ const exportToCocogoat = async proto => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
spawnSync("clip", { input: JSON.stringify(out,null,2) })
|
spawnSync("clip", { input: JSON.stringify(out,null,2) })
|
||||||
console.log("导出内容已复制到剪贴板.")
|
console.log("导出内容已复制到剪贴板")
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportToCsv = async proto => {
|
const exportToCsv = async proto => {
|
||||||
|
|||||||
18
utils.js
18
utils.js
@@ -172,7 +172,7 @@ const loadCache = async (fp, repo = "Dimbreath/GenshinData") => {
|
|||||||
validateStatus: _ => true
|
validateStatus: _ => true
|
||||||
})
|
})
|
||||||
if (headResponse.status === 304) {
|
if (headResponse.status === 304) {
|
||||||
debug("文件 %s 命中缓存", fp)
|
console.log("文件 %s 命中缓存", fp)
|
||||||
const etagLength = fd.readUInt8()
|
const etagLength = fd.readUInt8()
|
||||||
return JSON.parse(fd.subarray(1 + etagLength).toString())
|
return JSON.parse(fd.subarray(1 + etagLength).toString())
|
||||||
} else {
|
} else {
|
||||||
@@ -203,14 +203,6 @@ const upload = async data => {
|
|||||||
return await cloud.post("/achievement-export", data)
|
return await cloud.post("/achievement-export", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
const keypress = async () => {
|
|
||||||
process.stdin.setRawMode(true)
|
|
||||||
return new Promise(resolve => process.stdin.once("data", () => {
|
|
||||||
process.stdin.setRawMode(false)
|
|
||||||
resolve()
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkUpdate = async () => {
|
const checkUpdate = async () => {
|
||||||
const data = (await cloud.get("/latest-version")).data
|
const data = (await cloud.get("/latest-version")).data
|
||||||
if (data["vc"] !== version.code) {
|
if (data["vc"] !== version.code) {
|
||||||
@@ -231,9 +223,12 @@ const brotliDecompressSync = data => zlib.brotliDecompressSync(data)
|
|||||||
|
|
||||||
let hostsContent = ""
|
let hostsContent = ""
|
||||||
|
|
||||||
const setupHost = _ => {
|
const setupHost = (restore = false) => {
|
||||||
const path = "C:\\Windows\\System32\\drivers\\etc\\hosts"
|
const path = "C:\\Windows\\System32\\drivers\\etc\\hosts"
|
||||||
fs.chmodSync(path, 0o777)
|
fs.chmodSync(path, 0o777)
|
||||||
|
if (restore) {
|
||||||
|
fs.writeFileSync(path, hostsContent)
|
||||||
|
} else {
|
||||||
hostsContent = fs.readFileSync(path, "utf-8")
|
hostsContent = fs.readFileSync(path, "utf-8")
|
||||||
const requireHosts = new Map()
|
const requireHosts = new Map()
|
||||||
requireHosts.set(conf.dispatchUrl, "127.0.0.1")
|
requireHosts.set(conf.dispatchUrl, "127.0.0.1")
|
||||||
@@ -259,6 +254,7 @@ const setupHost = _ => {
|
|||||||
return `${pair[1]} ${pair[0]}`
|
return `${pair[1]} ${pair[0]}`
|
||||||
}).join("\n")
|
}).join("\n")
|
||||||
fs.writeFileSync(path, newContent)
|
fs.writeFileSync(path, newContent)
|
||||||
|
}
|
||||||
debug("修改SystemHosts")
|
debug("修改SystemHosts")
|
||||||
process.on("exit", () => {
|
process.on("exit", () => {
|
||||||
fs.writeFileSync(path, hostsContent)
|
fs.writeFileSync(path, hostsContent)
|
||||||
@@ -290,5 +286,5 @@ class KPacket {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
log, sleep, encodeProto, decodeProto, initConfig, splitPacket, upload, brotliCompressSync, brotliDecompressSync,
|
log, sleep, encodeProto, decodeProto, initConfig, splitPacket, upload, brotliCompressSync, brotliDecompressSync,
|
||||||
setupHost, loadCache, debug, checkCDN, checkUpdate, keypress, KPacket, cdnUrlFormat
|
setupHost, loadCache, debug, checkCDN, checkUpdate, KPacket, cdnUrlFormat
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user