From 967a5d3ee2a5ea1ab67cb41710c3315c4d6b97c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AF=E8=BE=BE=E9=B8=AD?= Date: Tue, 18 Feb 2025 13:31:15 +0800 Subject: [PATCH] =?UTF-8?q?panel.js=E6=94=AF=E6=8C=81=E5=90=91=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E6=96=B0=E5=A2=9Ecookie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parse/jd/jd_task_checkCookie.js | 2 +- util/panel.js | 71 +++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/parse/jd/jd_task_checkCookie.js b/parse/jd/jd_task_checkCookie.js index 4601a2c..4f02f07 100644 --- a/parse/jd/jd_task_checkCookie.js +++ b/parse/jd/jd_task_checkCookie.js @@ -78,7 +78,7 @@ export class Main extends Template { } ) if (y.cookie && y.cookie.includes('app_open')) { - this.dict[user] = y.cookie + this.dict[user] = {cookie: y.cookie} p.log('openKey生成成功'); if (this.profile.cache) { p.info.work = true diff --git a/util/panel.js b/util/panel.js index b4836aa..9755d8a 100644 --- a/util/panel.js +++ b/util/panel.js @@ -32,13 +32,12 @@ export class Panel { async _qlTask() { let envs = await this.getEnvs(`${this.type}_cookie`.toUpperCase()) - // let pins = [] if (envs.length) { - // console.log(envs) for (let i of envs) { let pin = this.func.userName(i.value) if (this.dict[pin]) { - i.value = this.dict[pin] + i.value = this.dict[pin].cookie + this.dict[pin].exist = true let ary = ['_id', 'id', 'name', 'value'] let d = ary.reduce((v, k) => { if (i[k]) { @@ -55,6 +54,46 @@ export class Panel { } } } + for (let i in this.dict) { + let array = [] + if (!this.dict[i].exist) { + array.push({ + name: `${this.type}_cookie`.toUpperCase(), + value: this.dict[i].cookie + }) + } + if (array.length) { + let data = await this.addEnvs(array) + if (data.code == 200) { + for (let pin in this.dict) { + this.func.msg(`新增: ${pin} 成功`) + } + } + else { + console.error('[Error] 添加账号失败'); + } + } + } + } + else { + let array = [] + for (let i in this.dict) { + array.push({ + name: `${this.type}_cookie`.toUpperCase(), + value: this.dict[i].cookie + }) + } + if (array.length) { + let data = await this.addEnvs(array) + if (data.code == 200) { + for (let pin in this.dict) { + this.func.msg(`新增: ${pin} 成功`) + } + } + else { + console.error('[Error] 添加账号失败'); + } + } } } @@ -69,10 +108,16 @@ export class Panel { for (let j in dict[i]) { let pin = this.func.userName(dict[i][j]) if (this.dict[pin]) { - dict[i][j] = this.dict[pin] + dict[i][j] = this.dict[pin].cookie + this.dict[pin].category = i } } } + for (let pin in this.dict) { + if (!this.dict[pin].category) { + dict.other.push(this.dict[pin].cookie) + } + } let text = [] for (let i in dict) { text.push(`[${i}]`) @@ -95,10 +140,16 @@ export class Panel { for (let j in dict[i]) { let pin = this.func.userName(dict[i][j]) if (this.dict[pin]) { - dict[i][j] = this.dict[pin] + dict[i][j] = this.dict[pin].cookie + this.dict[pin].category = i } } } + for (let pin in this.dict) { + if (!this.dict[pin].category) { + dict.other.push(this.dict[pin].cookie) + } + } let text = `export default ${JSON.stringify(dict, null, 4)}` await fs.writeFileSync(`${this.func.abspath}/cookie/${this.type}.js`, text) this.func.msg(`${this.type}.js 更新成功`) @@ -156,14 +207,10 @@ export class Panel { } // 添加环境变量 - async addEnv(name, value, remarks = '') { + async addEnvs(data) { const token = await this.getToken(); try { - const response = await axios.post(`${this.config.baseURL}/open/envs`, [{ - name, - value, - remarks - }], { + const response = await axios.post(`${this.config.baseURL}/open/envs`, data, { headers: { 'Authorization': `Bearer ${token}` } @@ -176,7 +223,7 @@ export class Panel { } // 删除环境变量 - async deleteEnv(envId) { + async deleteEnvs(envId) { const token = await this.getToken(); try { const response = await axios.delete(`${this.config.baseURL}/open/envs`, {