UNPKG

@hopeio/utils

Version:
305 lines (304 loc) 8.49 kB
var P = Object.defineProperty; var q = (e, t, s) => t in e ? P(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s; var l = (e, t, s) => q(e, typeof t != "symbol" ? t + "" : t, s); import { e as I, d as g } from "./compatible-D7WEyggZ.js"; import "crypto"; import C from "spark-md5"; var u = /* @__PURE__ */ ((e) => (e.APIUser = "api-user", e.WoHome = "wohome", e.WoCloud = "wocloud", e.Wostore = "wostore", e))(u || {}), m = /* @__PURE__ */ ((e) => (e.Personal = "0", e.Family = "1", e.Private = "4", e))(m || {}); const y = "XFmi9GS2hzk98jGX", p = "1001000021"; var R = /* @__PURE__ */ ((e) => (e[e.NameAsc = 0] = "NameAsc", e[e.NameDesc = 1] = "NameDesc", e[e.SizeAsc = 2] = "SizeAsc", e[e.SizeDesc = 3] = "SizeDesc", e[e.TimeAsc = 4] = "TimeAsc", e[e.TimeDesc = 5] = "TimeDesc", e))(R || {}); const A = { clientId: p }, w = { clientId: p, secret: !0 }, d = { secret: !0 }, U = new Error("invalid psToken"), h = class h { constructor() { l(this, "_fetch", async function(t, s, r, o) { const a = await fetch(t, { headers: r, body: JSON.stringify(o), method: s }); return { status: a.status, data: await a.json(), headers: a.headers }; }); l(this, "_failCallback"); l(this, "accessToken", ""); l(this, "accessKey", ""); l(this, "refreshToken", ""); l(this, "psToken", ""); l(this, "_proxy", ""); l(this, "iv", "wNSOYIB1k1DjY5lA"); l(this, "DefaultBaseURL", "https://panservice.mail.wo.cn"); l(this, "DefaultZoneURL", "https://tjupload.pan.wo.cn"); l(this, "DefaultPartSize", 8 * 1024 * 1024); } static getInstance() { return h.instance || (h.instance = new h()), h.instance; } set fetch(t) { this._fetch = t; } set failCallback(t) { this._failCallback = t; } set proxy(t) { this._proxy = t; } setToken(t, s) { this.accessToken = t, this.accessKey = t.slice(0, 16), this.refreshToken = s; } async request(t, s, r, o, a = "dispatcher") { const c = { "Content-Type": "application/json", Origin: "https://pan.wo.cn", Referer: "https://pan.wo.cn/" }; this.accessToken !== "" && (c.Accesstoken = this.accessToken); let f = await this.newBody(t, r, o); s !== "" && (f = { header: $(t, s), body: f }); let k = u.WoHome; t != u.WoHome && (k = u.APIUser); let T = `${this.DefaultBaseURL}/${k}/${a}`; this._proxy != "" && (c["Target-Url"] = this.DefaultBaseURL, c["Target-Origin"] = "https://pan.wo.cn", c["Target-Referer"] = "https://pan.wo.cn/", T = `${this._proxy}/${k}/${a}`); const { status: D, data: i } = await this._fetch(T, "POST", c, f); if (D > 399) if (this._failCallback) this._failCallback(`request failed: ${D}, data: ${i}`); else throw new Error(`request failed: ${D}, data: ${i}`); if (i.STATUS != "200") if (this._failCallback) this._failCallback(`request failed with status: ${i.STATUS}, msg: ${i.MSG}`); else throw new Error(`request failed with status: ${i.STATUS}, msg: ${i.MSG}`); if (i.RSP.RSP_CODE != "0000") if (this._failCallback) this._failCallback(`request failed with rsp_code: ${i.RSP.RSP_CODE},rep_desc: ${i.RSP.RSP_DESC}`); else throw new Error(`request failed with rsp_code: ${i.RSP.RSP_CODE},rep_desc: ${i.RSP.RSP_DESC}`); return typeof i.RSP.DATA == "string" && i.RSP.DATA !== "" ? JSON.parse(await this.decrypt(i.RSP.DATA, t)) : i.RSP.DATA; } requestApiUser(t, s, r) { return this.request(u.APIUser, t, s, r); } requestWoStore(t, s, r) { return this.request(u.Wostore, t, s, r); } requestWoHome(t, s, r) { return this.request(u.WoHome, t, s, r); } async encrypt(t, s) { try { let r = this.accessKey; return s != u.WoHome && (r = y), I(t, r, this.iv); } catch (r) { throw console.log(r), r; } } async decrypt(t, s = u.WoHome) { try { let r = this.accessKey; return s != u.WoHome && (r = y), await g(t, r, this.iv); } catch (r) { throw console.log(r), r; } } async newBody(t, s, r) { return { ...r, param: s ? await this.encrypt(JSON.stringify(s), t) : "" }; } }; l(h, "instance"); let S = h; function $(e, t) { const s = Date.now(), r = Math.floor(Math.random() * 8999) + 1e5, o = "", a = C.hash(`${t}${s}${r}${e}${o}`); return { key: t, resTime: s, reqSeq: r, channel: e, sign: a, version: o }; } const n = S.getInstance(); function O(e, t) { return n.requestApiUser("PcWebLogin", { phone: e, password: t, uuid: "", verifyCode: "", clientSecret: y }, w); } async function M(e, t, s) { const r = await n.requestApiUser("PcLoginVerifyCode", { phone: e, messageCode: s, verifyCode: null, uuid: null, clientSecret: y, password: t }, w); return n.setToken(r.access_token, r.refresh_token), r; } function B() { return n.requestApiUser("AppQueryUser", { accessToken: n.accessToken }, w); } function V() { return n.requestWoStore("AppQueryUserV2", { psToken: n.psToken }, w); } async function N() { const e = await n.requestApiUser("AppRefreshToken", { refreshToken: n.refreshToken, clientSecret: y }, w); return n.setToken(e.access_token, e.refresh_token), e; } function G(e) { return n.request(u.APIUser, "", { operateType: "1", phone: e }, { ...A, func: "app_send" }, "sendMessageCodeBase"); } async function Q(e, t) { const s = await n.requestWoStore("AppLoginByMobile", { phone: e, smsCode: t, clientSecret: y }, A); return n.setToken(s.access_token, s.refresh_token), s; } function j(e, t, s, r, o, a) { const c = { spaceType: e, parentDirectoryId: t, pageNum: s, pageSize: r, sortRule: o, clientId: p }; if (e == m.Family && (c.familyId = a), e == m.Private) { if (n.psToken == "") throw U; c.psToken = n.psToken; } return n.requestWoHome("QueryAllFiles", c, d); } async function z(e) { const t = await n.requestWoHome("PrivateSpaceLogin", { pwd: e, clientId: p }, d); return n.psToken = t.psToken, t; } function x(e) { return n.requestWoHome("GetDownloadUrlV2", { type: "1", fidList: e, clientId: p }, d); } function J(e, t) { return n.requestWoHome("GetDownloadUrl", { fidList: t, spaceType: e, clientId: p }, d); } function K(e, t, s, r, o, a, c) { const f = { targetDirId: s, sourceType: r, targetType: o, dirList: e, fileList: t, secret: !1, clientId: p }; return r == m.Family && (f.fromFamilyId = a), o == m.Family && (f.familyId = c), n.requestWoHome("MoveFile", f, d); } function X(e, t, s, r, o, a, c) { const f = { targetDirId: s, sourceType: r, targetType: o, dirList: e, fileList: t, secret: !1, clientId: p }; return r == m.Family && (f.fromFamilyId = a), o == m.Family && (f.familyId = c), n.requestWoHome("CopyFile", f, d); } function Y(e, t, s) { return n.requestWoHome("DeleteFile", { spaceType: e, vipLevel: "0", dirList: t, fileList: s, clientId: p }, d); } function Z() { return n.requestWoHome("EmptyRecycleData", { clientId: p }, d); } function ee() { return n.requestWoHome("VerifySetPwd", { psToken: n.psToken }, d); } function te() { return n.request(u.Wostore, "FCloudProductOrdListQry", {}, { ...d, qryType: "1" }); } const W = "https://tjtn.pan.wo.cn/compressed/preview?fid=", _ = "https://tjtn.pan.wo.cn/thumbnailsV3?fid=", L = "https://du.smartont.net:8442/openapi/thumbnails?fid="; function se(e) { return `${W}${encodeURIComponent(e)}`; } function re(e) { return `${_}${encodeURIComponent(e)}`; } function ne(e) { return `${L}${encodeURIComponent(e)}`; } export { Q as AppLoginByMobile, B as AppQueryUser, V as AppQueryUser2, N as AppRefreshToken, u as Channel, X as CopyFile, p as DefaultClientID, y as DefaultClientSecret, Y as DeleteFile, Z as EmptyRecycleData, U as ErrInvalidPsToken, te as FCloudProductOrdListQry, J as GetDownloadUrl, x as GetDownloadUrlV2, A as JsonClientID, w as JsonClientIDSecret, d as JsonSecret, K as MoveFile, M as PcLoginVerifyCode, O as PcWebLogin, z as PrivateSpaceLogin, j as QueryAllFiles, R as SortType, m as SpaceType, ee as VerifySetPwd, n as client, se as preview, G as sendMessageCodeBase, ne as thumbnails, re as thumbnailsV3 };