panel.js支持向面板新增cookie

This commit is contained in:
可达鸭 2025-02-18 13:31:15 +08:00
parent b8ad005f1d
commit 967a5d3ee2
2 changed files with 60 additions and 13 deletions

View File

@ -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

View File

@ -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`, {