mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-13 01:48:13 +08:00
auto export to cocogoat
This commit is contained in:
29
export.js
29
export.js
@@ -1,7 +1,8 @@
|
|||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
|
const axios = require("axios")
|
||||||
const readline = require("readline")
|
const readline = require("readline")
|
||||||
const { loadCache, log } = require("./utils")
|
const { loadCache, log } = require("./utils")
|
||||||
const { copyToClipboard } = require("./native")
|
const { openUrl } = require("./native")
|
||||||
|
|
||||||
const exportToSeelie = proto => {
|
const exportToSeelie = proto => {
|
||||||
const out = { achievements: {} }
|
const out = { achievements: {} }
|
||||||
@@ -34,9 +35,7 @@ const exportToPaimon = async proto => {
|
|||||||
|
|
||||||
const exportToCocogoat = async proto => {
|
const exportToCocogoat = async proto => {
|
||||||
const out = {
|
const out = {
|
||||||
value: {
|
achievements: []
|
||||||
achievements: []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const achTable = new Map()
|
const achTable = new Map()
|
||||||
const preStageAchievementIdList = []
|
const preStageAchievementIdList = []
|
||||||
@@ -53,19 +52,27 @@ const exportToCocogoat = async proto => {
|
|||||||
return `${d.getFullYear()}/${p(d.getMonth()+1)}/${p(d.getDate())}`
|
return `${d.getFullYear()}/${p(d.getMonth()+1)}/${p(d.getDate())}`
|
||||||
}
|
}
|
||||||
proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({current, finishTimestamp, id, require}) => {
|
proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({current, finishTimestamp, id, require}) => {
|
||||||
out.value.achievements.push({
|
out.achievements.push({
|
||||||
id: id,
|
id: id,
|
||||||
status: current === undefined || current === 0 || preStageAchievementIdList.includes(id) ? `${require}/${require}` : `${current}/${require}`,
|
status: current === undefined || current === 0 || preStageAchievementIdList.includes(id) ? `${require}/${require}` : `${current}/${require}`,
|
||||||
categoryId: achTable.get(id),
|
categoryId: achTable.get(id),
|
||||||
date: getDate(finishTimestamp)
|
date: getDate(finishTimestamp)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
const ts = Date.now()
|
const response = await axios.post(`https://77.cocogoat.work/v1/memo?source=${encodeURI("全部成就")}`, out).catch(_ => {
|
||||||
const json = JSON.stringify(out,null,2)
|
console.log("网络错误,请检查网络后重试 (26-1)")
|
||||||
copyToClipboard(json)
|
process.exit(261)
|
||||||
const fp = `./export-${ts}-cocogoat.json`
|
})
|
||||||
fs.writeFileSync(fp, json)
|
if (response.status !== 201) {
|
||||||
log(`导出内容已复制到剪贴板`)
|
console.log(`API StatusCode 错误,请联系开发者以获取帮助 (26-2-${response.status})`)
|
||||||
|
process.exit(262)
|
||||||
|
}
|
||||||
|
const retcode = openUrl(`https://cocogoat.work/achievement?memo=${response.data.key}`)
|
||||||
|
if (retcode > 32) {
|
||||||
|
log("在浏览器内进行下一步操作")
|
||||||
|
} else {
|
||||||
|
log(`导出失败,请联系开发者以获取帮助 (26-3-${retcode})`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportToCsv = async proto => {
|
const exportToCsv = async proto => {
|
||||||
|
|||||||
1
native.d.ts
vendored
1
native.d.ts
vendored
@@ -5,4 +5,5 @@ export function copyToClipboard(value: string): any
|
|||||||
export function enablePrivilege(): any
|
export function enablePrivilege(): any
|
||||||
export function getDeviceInfo(): any
|
export function getDeviceInfo(): any
|
||||||
export function getDeviceID(): string
|
export function getDeviceID(): string
|
||||||
|
export function openUrl(url: string): number
|
||||||
export function pause(): any
|
export function pause(): any
|
||||||
|
|||||||
@@ -169,8 +169,16 @@ namespace native {
|
|||||||
return info.Env().Undefined();
|
return info.Env().Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value openUrl(const CallbackInfo &info) {
|
||||||
|
Env env = info.Env();
|
||||||
|
wstring url = StringToWString(info[0].As<Napi::String>().Utf8Value());
|
||||||
|
HINSTANCE retcode = ShellExecute(GetConsoleWindow(), L"open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||||
|
return Napi::Number::New(env, (INT_PTR)retcode); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||||
|
}
|
||||||
|
|
||||||
Object init(Env env, Object exports) {
|
Object init(Env env, Object exports) {
|
||||||
exports.Set("pause", Function::New(env, pause));
|
exports.Set("pause", Function::New(env, pause));
|
||||||
|
exports.Set("openUrl", Function::New(env, openUrl));
|
||||||
exports.Set("getDeviceID", Function::New(env, getDeviceID));
|
exports.Set("getDeviceID", Function::New(env, getDeviceID));
|
||||||
exports.Set("getDeviceInfo", Function::New(env, getDeviceInfo));
|
exports.Set("getDeviceInfo", Function::New(env, getDeviceInfo));
|
||||||
exports.Set("whoUseThePort", Function::New(env, whoUseThePort));
|
exports.Set("whoUseThePort", Function::New(env, whoUseThePort));
|
||||||
|
|||||||
Reference in New Issue
Block a user