mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-06 22:52:49 +08:00
fix appcenter log upload error
This commit is contained in:
8
app.js
8
app.js
@@ -17,18 +17,18 @@ const onExit = () => {
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
process.once("SIGHUP", () => setupHost(true))
|
||||
process.on("SIGHUP", () => setupHost(true))
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
console.log("Unhandled Rejection at: ", promise, "\n0Reason:", reason)
|
||||
})
|
||||
process.once("uncaughtException", (err, origin) => {
|
||||
process.on("uncaughtException", (err, origin) => {
|
||||
appcenter.uploadError(err, true)
|
||||
console.log(err)
|
||||
console.log(`Origin: ${origin}`)
|
||||
process.exit(1)
|
||||
})
|
||||
process.once("exit", onExit)
|
||||
process.once("SIGINT", onExit)
|
||||
process.on("exit", onExit)
|
||||
process.on("SIGINT", onExit)
|
||||
try {
|
||||
enablePrivilege()
|
||||
} catch (e) {
|
||||
|
||||
27
appcenter.js
27
appcenter.js
@@ -30,15 +30,17 @@ const device = (() => {
|
||||
|
||||
const upload = () => {
|
||||
if (queue.length > 0) {
|
||||
const data = JSON.stringify({ "logs": queue })
|
||||
const logs = []
|
||||
for (let i = 0; i <= queue.length; i++) {
|
||||
logs.push(queue.pop())
|
||||
}
|
||||
const data = JSON.stringify({"logs": logs})
|
||||
axios.post("https://in.appcenter.ms/logs?api-version=1.0.0", data,{
|
||||
headers: {
|
||||
"App-Secret": key,
|
||||
"Install-ID": install
|
||||
}
|
||||
}).then(_ => {
|
||||
queue.length = 0
|
||||
}).catch(_ => {})
|
||||
}).catch(_ => {}).then()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +81,19 @@ const uploadError = (err, fatal) => {
|
||||
upload()
|
||||
}
|
||||
|
||||
const uploadEvent = (name, prop) => {
|
||||
const content = {
|
||||
type: "event",
|
||||
id: crypto.randomUUID(),
|
||||
sid: session,
|
||||
name: name,
|
||||
properties: prop,
|
||||
timestamp: getTimestamp(),
|
||||
device: device
|
||||
}
|
||||
queue.push(content)
|
||||
}
|
||||
|
||||
const startup = () => {
|
||||
queue.push({
|
||||
type: "startService",
|
||||
@@ -93,9 +108,9 @@ const startup = () => {
|
||||
device: device
|
||||
})
|
||||
upload()
|
||||
setInterval(() => upload(), 10000)
|
||||
setInterval(() => upload(), 5000)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
startup, upload, uploadError
|
||||
startup, upload, uploadError, uploadEvent
|
||||
}
|
||||
|
||||
2
utils.js
2
utils.js
@@ -10,6 +10,7 @@ const { version } = require("./version")
|
||||
const { promisify } = require("util")
|
||||
const { createHash } = require("crypto")
|
||||
const path = require("path")
|
||||
const { uploadEvent } = require("./appcenter")
|
||||
const messages = path.join(__dirname, "./proto/Messages.proto")
|
||||
|
||||
const encodeProto = (object, name) => protobuf.load(messages).then(r => {
|
||||
@@ -91,6 +92,7 @@ const initConfig = async () => {
|
||||
conf.executable = conf.isOversea ? `${conf.path}/GenshinImpact.exe` : `${conf.path}/YuanShen.exe`
|
||||
conf.dispatchUrl = `dispatch${conf.isOversea ? "os" : "cn"}global.yuanshen.com`
|
||||
conf.dispatchIP = (await promisify(dns.lookup).bind(dns)(conf.dispatchUrl, 4)).address
|
||||
uploadEvent("AppInitialize", { ClientVersion: version.name, GameVersion: conf.version })
|
||||
return conf
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user