mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Poe client sync with upstream
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -19,3 +19,4 @@ whitelist.txt
|
|||||||
.vscode
|
.vscode
|
||||||
secrets.json
|
secrets.json
|
||||||
/dist
|
/dist
|
||||||
|
poe_device.json
|
||||||
|
@@ -4,3 +4,4 @@ node_modules/
|
|||||||
/thumbnails
|
/thumbnails
|
||||||
secrets.json
|
secrets.json
|
||||||
/dist
|
/dist
|
||||||
|
poe_device.json
|
||||||
|
@@ -25,7 +25,36 @@ const path = require('path');
|
|||||||
const http = require('http');
|
const http = require('http');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
|
|
||||||
const parent_path = path.resolve(__dirname);
|
const directory = __dirname;
|
||||||
|
|
||||||
|
function uuidv4() {
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||||
|
const r = Math.random() * 16 | 0;
|
||||||
|
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const getSavedDeviceId = (userId) => {
|
||||||
|
const device_id_path = 'poe_device.json';
|
||||||
|
let device_ids = {};
|
||||||
|
|
||||||
|
if (fs.existsSync(device_id_path)) {
|
||||||
|
device_ids = JSON.parse(fs.readFileSync(device_id_path, 'utf8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device_ids.hasOwnProperty(userId)) {
|
||||||
|
return device_ids[userId];
|
||||||
|
}
|
||||||
|
|
||||||
|
const device_id = uuidv4();
|
||||||
|
device_ids[userId] = device_id;
|
||||||
|
fs.writeFileSync(device_id_path, JSON.stringify(device_ids, null, 2));
|
||||||
|
|
||||||
|
return device_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
const parent_path = path.resolve(directory);
|
||||||
const queries_path = path.join(parent_path, "poe_graphql");
|
const queries_path = path.join(parent_path, "poe_graphql");
|
||||||
let queries = {};
|
let queries = {};
|
||||||
|
|
||||||
@@ -203,6 +232,18 @@ function md5() {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateNonce(length = 16) {
|
||||||
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
let result = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
const randomIndex = Math.floor(Math.random() * characters.length);
|
||||||
|
result += characters[randomIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
function load_queries() {
|
function load_queries() {
|
||||||
const files = fs.readdirSync(queries_path);
|
const files = fs.readdirSync(queries_path);
|
||||||
for (const filename of files) {
|
for (const filename of files) {
|
||||||
@@ -257,6 +298,7 @@ class Client {
|
|||||||
ws_connected = false;
|
ws_connected = false;
|
||||||
auto_reconnect = false;
|
auto_reconnect = false;
|
||||||
use_cached_bots = false;
|
use_cached_bots = false;
|
||||||
|
device_id = null;
|
||||||
|
|
||||||
constructor(auto_reconnect = false, use_cached_bots = false) {
|
constructor(auto_reconnect = false, use_cached_bots = false) {
|
||||||
this.auto_reconnect = auto_reconnect;
|
this.auto_reconnect = auto_reconnect;
|
||||||
@@ -302,11 +344,20 @@ class Client {
|
|||||||
"poe-tchannel": this.channel["channel"],
|
"poe-tchannel": this.channel["channel"],
|
||||||
...this.headers,
|
...this.headers,
|
||||||
};
|
};
|
||||||
|
if (this.device_id === null) {
|
||||||
|
this.device_id = this.get_device_id();
|
||||||
|
}
|
||||||
await this.subscribe();
|
await this.subscribe();
|
||||||
await this.connect_ws();
|
await this.connect_ws();
|
||||||
console.log('Client initialized.');
|
console.log('Client initialized.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_device_id() {
|
||||||
|
const user_id = this.viewer["poeUser"]["id"];
|
||||||
|
const device_id = getSavedDeviceId(user_id);
|
||||||
|
return device_id;
|
||||||
|
}
|
||||||
|
|
||||||
async get_next_data() {
|
async get_next_data() {
|
||||||
logger.info('Downloading next_data...');
|
logger.info('Downloading next_data...');
|
||||||
|
|
||||||
@@ -569,6 +620,8 @@ class Client {
|
|||||||
"query": message,
|
"query": message,
|
||||||
"chatId": this.bots[chatbot]["chatId"],
|
"chatId": this.bots[chatbot]["chatId"],
|
||||||
"source": null,
|
"source": null,
|
||||||
|
"clientNonce": generateNonce(),
|
||||||
|
"sdid": this.device_id,
|
||||||
"withChatBreak": with_chat_break
|
"withChatBreak": with_chat_break
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user