Skip to content

Commit

Permalink
fix: POE not work
Browse files Browse the repository at this point in the history
fix #329
fix #461
fix #481
  • Loading branch information
sunner committed Aug 11, 2023
1 parent ddae817 commit fa3630b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
5 changes: 5 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ function createNewWindow(url, userAgent = "") {
} else if (url.startsWith("https://claude.ai/")) {
const org = await getLocalStorage("lastActiveOrg");
mainWindow.webContents.send("CLAUDE-2-ORG", org);
} else if (url.startsWith("https://poe.com/")) {
const formkey = await newWin.webContents.executeJavaScript(
"window.ereNdsRqhp2Rd3LEW();",
);
mainWindow.webContents.send("POE-FORMKEY", formkey);
}

newWin.destroy(); // Destroy the window manually
Expand Down
40 changes: 12 additions & 28 deletions src/bots/poe/PoeBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from "axios";
import md5 from "md5";
import WebSocketAsPromised from "websocket-as-promised";
import AsyncLock from "async-lock";
import store from "@/store";

export default class PoeBot extends Bot {
static _brandId = "poe"; // Brand id of the bot, should be unique. Used in i18n.
Expand All @@ -12,7 +13,6 @@ export default class PoeBot extends Bot {
static _lock = new AsyncLock();

context = {
formkey: "",
buildId: "",
chatId: 0,
settings: null,
Expand All @@ -24,7 +24,8 @@ export default class PoeBot extends Bot {
}

async gqlPost(queryName, variables) {
const { formkey, settings } = this.context;
const { settings } = this.context;
const formkey = store.state.poe.formkey;
const queryHashs = {
AnnotateWithIdsProviderQuery:
"b4e6992c3af8f208ab2b3979dce48889835736ed29f623ea9f609265018d0d8f",
Expand All @@ -41,7 +42,7 @@ export default class PoeBot extends Bot {
queryName,
variables,
};
const tagId = md5(JSON.stringify(payload) + formkey + "WpuLMiXEKKE98j56k");
const tagId = md5(JSON.stringify(payload) + formkey + "4LxgHM6KpFqokX0Ox");
const headers = {
"Content-Type": "application/json",
"poe-formkey": formkey,
Expand Down Expand Up @@ -75,34 +76,17 @@ export default class PoeBot extends Bot {
this.constructor._loginUrl + modelHandles[this.constructor._model];

try {
await axios.get(url).then((response) => {
if (response.request.responseURL !== url) {
// A 307 redirect to the login page means the bot is not logged in
// Axios always do the redirect, so we have to check the responseURL
return;
}
const response = await axios.get(url);

// Parse buildId
const buildId = response.data.match(/"buildId":"(.*?)",/);
this.context.buildId = buildId[1];
// Parse buildId
const buildId = response.data.match(/"buildId":"(.*?)",/);
this.context.buildId = buildId[1];

// Parse chatId
const chatId = response.data.match(/"chatId":(\d+),/);
this.context.chatId = chatId[1];
// Parse chatId
const chatId = response.data.match(/"chatId":(\d+),/);
this.context.chatId = chatId[1];

// Parse and run the secret code of Poe for formkey
const secretCode = response.data.match(
/var .=".*",.*window\..*=function\(\)\{return .\.join\(""\)\};/,
);

const secretFunction = secretCode[0].match(
/(window\..*)=function\(\)\{.*\};/,
);

this.context.formkey = eval(`${secretCode[0]}${secretFunction[1]}();`);

isAvailable = true;
});
isAvailable = true;
} catch (error) {
console.error("Error checking Poe login status:", error);
}
Expand Down
11 changes: 11 additions & 0 deletions src/components/BotSettings/PoeBotSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<script>
import Bot from "@/bots/poe/PoeBot";
import LoginSetting from "@/components/BotSettings/LoginSetting.vue";
import { mapMutations } from "vuex";
const { ipcRenderer } = window.require("electron");
export default {
components: {
Expand All @@ -15,5 +17,14 @@ export default {
bot: Bot.getInstance(),
};
},
mounted() {
// Listen for the POE-FORMKEY message from background.js
ipcRenderer.on("POE-FORMKEY", (event, formkey) => {
this.setPoe({ formkey });
});
},
methods: {
...mapMutations(["setPoe"]),
},
};
</script>
6 changes: 6 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export default createStore({
claudeAi: {
org: "",
},
poe: {
formkey: "",
},
chats: [
{
title: "New Chat",
Expand Down Expand Up @@ -172,6 +175,9 @@ export default createStore({
setClaudeAi(state, values) {
state.claudeAi = { ...state.claudeAi, ...values };
},
setPoe(state, values) {
state.poe = { ...state.poe, ...values };
},
setLatestPromptIndex(state, promptIndex) {
const currentChat = state.chats[state.currentChatIndex];
currentChat.latestPromptIndex = promptIndex;
Expand Down

1 comment on commit fa3630b

@vercel
Copy link

@vercel vercel bot commented on fa3630b Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chatall – ./

chatall-llm.vercel.app
chatall-sunner.vercel.app
chatall-git-main-sunner.vercel.app

Please sign in to comment.