mirror of
https://github.com/qitoqito/psyduck.git
synced 2026-01-15 23:21:16 +08:00
panel.js支持向面板新增cookie
This commit is contained in:
parent
b8ad005f1d
commit
967a5d3ee2
@ -78,7 +78,7 @@ export class Main extends Template {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if (y.cookie && y.cookie.includes('app_open')) {
|
if (y.cookie && y.cookie.includes('app_open')) {
|
||||||
this.dict[user] = y.cookie
|
this.dict[user] = {cookie: y.cookie}
|
||||||
p.log('openKey生成成功');
|
p.log('openKey生成成功');
|
||||||
if (this.profile.cache) {
|
if (this.profile.cache) {
|
||||||
p.info.work = true
|
p.info.work = true
|
||||||
|
|||||||
@ -32,13 +32,12 @@ export class Panel {
|
|||||||
|
|
||||||
async _qlTask() {
|
async _qlTask() {
|
||||||
let envs = await this.getEnvs(`${this.type}_cookie`.toUpperCase())
|
let envs = await this.getEnvs(`${this.type}_cookie`.toUpperCase())
|
||||||
// let pins = []
|
|
||||||
if (envs.length) {
|
if (envs.length) {
|
||||||
// console.log(envs)
|
|
||||||
for (let i of envs) {
|
for (let i of envs) {
|
||||||
let pin = this.func.userName(i.value)
|
let pin = this.func.userName(i.value)
|
||||||
if (this.dict[pin]) {
|
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 ary = ['_id', 'id', 'name', 'value']
|
||||||
let d = ary.reduce((v, k) => {
|
let d = ary.reduce((v, k) => {
|
||||||
if (i[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]) {
|
for (let j in dict[i]) {
|
||||||
let pin = this.func.userName(dict[i][j])
|
let pin = this.func.userName(dict[i][j])
|
||||||
if (this.dict[pin]) {
|
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 = []
|
let text = []
|
||||||
for (let i in dict) {
|
for (let i in dict) {
|
||||||
text.push(`[${i}]`)
|
text.push(`[${i}]`)
|
||||||
@ -95,10 +140,16 @@ export class Panel {
|
|||||||
for (let j in dict[i]) {
|
for (let j in dict[i]) {
|
||||||
let pin = this.func.userName(dict[i][j])
|
let pin = this.func.userName(dict[i][j])
|
||||||
if (this.dict[pin]) {
|
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)}`
|
let text = `export default ${JSON.stringify(dict, null, 4)}`
|
||||||
await fs.writeFileSync(`${this.func.abspath}/cookie/${this.type}.js`, text)
|
await fs.writeFileSync(`${this.func.abspath}/cookie/${this.type}.js`, text)
|
||||||
this.func.msg(`${this.type}.js 更新成功`)
|
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();
|
const token = await this.getToken();
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`${this.config.baseURL}/open/envs`, [{
|
const response = await axios.post(`${this.config.baseURL}/open/envs`, data, {
|
||||||
name,
|
|
||||||
value,
|
|
||||||
remarks
|
|
||||||
}], {
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
@ -176,7 +223,7 @@ export class Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 删除环境变量
|
// 删除环境变量
|
||||||
async deleteEnv(envId) {
|
async deleteEnvs(envId) {
|
||||||
const token = await this.getToken();
|
const token = await this.getToken();
|
||||||
try {
|
try {
|
||||||
const response = await axios.delete(`${this.config.baseURL}/open/envs`, {
|
const response = await axios.delete(`${this.config.baseURL}/open/envs`, {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user