diff --git a/lib/glados.ts b/lib/glados.ts index cc4d755..de3be7b 100644 --- a/lib/glados.ts +++ b/lib/glados.ts @@ -1,15 +1,15 @@ -import { GLaDOSCookie, userAgent } from "./env.ts"; -import { GLaDOSCheckinStatus, GLaDOSCheckinType } from "./types/glados.type.ts"; +const workerFunc = async (cookie: string) => { + import { GLaDOSCookie, userAgent } from "./env.ts"; + import { GLaDOSCheckinStatus, GLaDOSCheckinType } from "./types/glados.type.ts"; -const checkinUrl = "https://glados.rocks/api/user/checkin", - statusUrl = "https://glados.rocks/api/user/status", - referer = "https://glados.rocks/console/checkin", - origin = "https://glados.rocks", - data = { - token: "glados.network", - }; + const checkinUrl = "https://glados.rocks/api/user/checkin", + statusUrl = "https://glados.rocks/api/user/status", + referer = "https://glados.rocks/console/checkin", + origin = "https://glados.rocks", + data = { + token: "glados.network", + }; -const checkin = async (cookie: string) => { const checkin: GLaDOSCheckinType = await fetch(checkinUrl, { method: "POST", headers: { @@ -38,8 +38,10 @@ const checkin = async (cookie: string) => { } }; -checkin(GLaDOSCookie); +self.addEventListener("message", (event) => { + workerFunc(event.data.cookie); +}); export { - checkin as GLaDOSCheckin + workerFunc as GLaDOSCheckin }; diff --git a/lib/nodeseek.ts b/lib/nodeseek.ts index e0a1d1e..9612923 100644 --- a/lib/nodeseek.ts +++ b/lib/nodeseek.ts @@ -1,12 +1,12 @@ -import { nodeseekCookie, userAgent } from "./env.ts"; -import { nodeseekCheckinType } from "./types/nodeseek.type.ts"; +const workerFunc = async (cookie: string, random: boolean) => { + import { nodeseekCookie, userAgent } from "./env.ts"; + import { nodeseekCheckinType } from "./types/nodeseek.type.ts"; -let checkinBaseUrl = "https://www.nodeseek.com/api/attendance"; -const boardUrl = "https://www.nodeseek.com/api/attendance/board", - origin = "https://www.nodeseek.com", - referer = "https://www.nodeseek.com/board" + let checkinBaseUrl = "https://www.nodeseek.com/api/attendance"; + const boardUrl = "https://www.nodeseek.com/api/attendance/board", + origin = "https://www.nodeseek.com", + referer = "https://www.nodeseek.com/board" -const checkin = async (cookie: string, random: boolean) => { if (random) checkinBaseUrl += "?ramdom=true"; const checkin: nodeseekCheckinType = await fetch(checkinBaseUrl, { method: "POST", @@ -28,8 +28,10 @@ const checkin = async (cookie: string, random: boolean) => { else console.log(`Nodeseek签到失败,返回的消息:${checkin.message}`); } -checkin(nodeseekCookie, false); +self.addEventListener("message", (event) => { + workerFunc(event.data.cookie, event.data.random); +}); export { - checkin as nodeseekCheckin + workerFunc as nodeseekCheckin } \ No newline at end of file diff --git a/lib/v2free.ts b/lib/v2free.ts index 75c67f9..ad327fd 100644 --- a/lib/v2free.ts +++ b/lib/v2free.ts @@ -1,10 +1,10 @@ -import { v2freeCookie } from "./env.ts"; -import { v2freeCheckinType } from "./types/v2free.type.ts"; +const workerFunc = async (cookie: string) => { + import { v2freeCookie } from "./env.ts"; + import { v2freeCheckinType } from "./types/v2free.type.ts"; -const url = "https://w1.v2free.top", - path = "/user/checkin"; + const url = "https://w1.v2free.top", + path = "/user/checkin"; -const checkin = async (cookie: string) => { const checkin: v2freeCheckinType = await fetch(url + path, { method: "POST", headers: { @@ -13,10 +13,12 @@ const checkin = async (cookie: string) => { }).then(res => res.json()); if (checkin.msg === "您似乎已经签到过了...") console.log(`v2free提示:${checkin.msg}`); else console.log(`v2free签到结果:${checkin.msg};总流量:${checkin.traffic};今日已用:${checkin.trafficInfo.todayUsedTraffic};过去已用:${checkin.trafficInfo.lastUsedTraffic};剩余流量:${checkin.trafficInfo.unUsedTraffic}`); -} +}; -checkin(v2freeCookie); +self.addEventListener("message", (event) => { + workerFunc(event.data.cookie); +}); export { - checkin as v2freeCheckin + workerFunc as v2freeCheckin }; diff --git a/main.ts b/main.ts index a9eb258..3e44fc7 100644 --- a/main.ts +++ b/main.ts @@ -1,6 +1,24 @@ -import "./lib/glados.ts"; -import "./lib/v2free.ts"; -import "./lib/ikuuu.ts"; -import "./lib/nodeseek.ts"; -import "./lib/rainyun.ts"; -import "./lib/laecloud.ts"; \ No newline at end of file +import { Worker } from "deno"; +import { GLaDOSCheckin } from "./lib/glados.ts"; +import { v2freeCheckin } from "./lib/v2free.ts"; +import { ikuuuCheckin } from "./lib/ikuuu.ts"; +import { nodeseekCheckin } from "./lib/nodeseek.ts"; +import { rainyunCheckin } from "./lib/rainyun.ts"; +import { laecloudCheckin } from "./lib/laecloud.ts"; + +const workers = [ + new Worker(GLaDOSCheckin, { type: "module" }), + new Worker(v2freeCheckin, { type: "module" }), + new Worker(ikuuuCheckin, { type: "module" }), + new Worker(nodeseekCheckin, { type: "module" }), + new Worker(rainyunCheckin, { type: "module" }), + new Worker(laecloudCheckin, { type: "module" }), +]; + +workers.forEach(worker => { + worker.postMessage({ cookie: "cookie", random: false }); + worker.onerror = (error) => { + console.error(`Error in worker: ${error.message}`); + worker.terminate(); + }; +}); \ No newline at end of file