mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: 修复Poe formkey失效的问题
This commit is contained in:
parent
1a94d92943
commit
15f579aab8
2 changed files with 24 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ import { readFileSync, writeFile } from 'fs'
|
||||||
const scrape = async (pbCookie, proxy) => {
|
const scrape = async (pbCookie, proxy) => {
|
||||||
let option = { headers: { cookie: `${pbCookie}` } }
|
let option = { headers: { cookie: `${pbCookie}` } }
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
option.proxy = proxy
|
option.agent = proxy
|
||||||
}
|
}
|
||||||
const _setting = await fetch(
|
const _setting = await fetch(
|
||||||
'https://poe.com/api/settings',
|
'https://poe.com/api/settings',
|
||||||
|
|
@ -24,7 +24,7 @@ const scrape = async (pbCookie, proxy) => {
|
||||||
const getUpdatedSettings = async (channelName, pbCookie, proxy) => {
|
const getUpdatedSettings = async (channelName, pbCookie, proxy) => {
|
||||||
let option = { headers: { cookie: `${pbCookie}` } }
|
let option = { headers: { cookie: `${pbCookie}` } }
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
option.proxy = proxy
|
option.agent = proxy
|
||||||
}
|
}
|
||||||
const _setting = await fetch(
|
const _setting = await fetch(
|
||||||
`https://poe.com/api/settings?channel=${channelName}`,
|
`https://poe.com/api/settings?channel=${channelName}`,
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ export class PoeClient {
|
||||||
this.config.app_settings = result.appSettings
|
this.config.app_settings = result.appSettings
|
||||||
|
|
||||||
// set value
|
// set value
|
||||||
this.headers['poe-formkey'] = this.config.quora_formkey
|
this.headers['poe-formkey'] = this.config.quora_formkey // unused
|
||||||
this.headers['poe-tchannel'] = this.config.channel_name
|
this.headers['poe-tchannel'] = this.config.channel_name
|
||||||
this.headers.Cookie = this.config.quora_cookie
|
this.headers.Cookie = this.config.quora_cookie
|
||||||
console.log(this.headers)
|
console.log(this.headers)
|
||||||
|
|
@ -150,7 +150,9 @@ export class PoeClient {
|
||||||
const nextData = JSON.parse(jsonText)
|
const nextData = JSON.parse(jsonText)
|
||||||
this.nextData = nextData
|
this.nextData = nextData
|
||||||
this.viewer = nextData.props.pageProps.payload.viewer
|
this.viewer = nextData.props.pageProps.payload.viewer
|
||||||
this.formkey = nextData.props.formkey
|
|
||||||
|
this.formkey = this.extract_formkey(text)
|
||||||
|
this.headers['poe-formkey'] = this.formkey
|
||||||
let bots = this.viewer.availableBots
|
let bots = this.viewer.availableBots
|
||||||
this.bots = {}
|
this.bots = {}
|
||||||
for (let i = 0; i < bots.length; i++) {
|
for (let i = 0; i < bots.length; i++) {
|
||||||
|
|
@ -161,6 +163,24 @@ export class PoeClient {
|
||||||
console.log(this.bots)
|
console.log(this.bots)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extract_formkey (html) {
|
||||||
|
const scriptRegex = /<script>if\(.+\)throw new Error;(.+)<\/script>/
|
||||||
|
const scriptText = html.match(scriptRegex)[1]
|
||||||
|
const keyRegex = /var .="([0-9a-f]+)",/
|
||||||
|
const keyText = scriptText.match(keyRegex)[1]
|
||||||
|
const cipherRegex = /.\[(\d+)]=.\[(\d+)]/g
|
||||||
|
const cipherPairs = scriptText.match(cipherRegex)
|
||||||
|
|
||||||
|
const formkeyList = Array(cipherPairs.length).fill('')
|
||||||
|
for (const pair of cipherPairs) {
|
||||||
|
const [formkeyIndex, keyIndex] = pair.match(/\d+/g).map(Number)
|
||||||
|
formkeyList[formkeyIndex] = keyText[keyIndex]
|
||||||
|
}
|
||||||
|
const formkey = formkeyList.join('')
|
||||||
|
|
||||||
|
return formkey
|
||||||
|
}
|
||||||
|
|
||||||
async clearContext (bot) {
|
async clearContext (bot) {
|
||||||
try {
|
try {
|
||||||
const data = await this.makeRequest({
|
const data = await this.makeRequest({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue