Skip to content

Commit

Permalink
⚡ [Enhance] Enable create with new cookie item KievRPSSecAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
Hansimov committed Jan 21, 2024
1 parent 70c1e23 commit cd5bef2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions apis/chat_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def chat_completions(self, item: ChatCompletionsPostItem):
sec_access_token=creator.sec_access_token,
client_id=creator.client_id,
conversation_id=creator.conversation_id,
cookies=creator.request_cookies,
invocation_id=0,
)

Expand Down
14 changes: 11 additions & 3 deletions networks/cookies_constructor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import requests
import random
import string

from datetime import datetime
from pathlib import Path

from utils.logger import logger


Expand All @@ -14,6 +16,10 @@ def __init__(self):
self.secrets_path = Path(__file__).parents[1] / "secrets.json"
self.created_datetime_format = "%Y-%m-%d %H:%M:%S"

def generate_kiev_rps_sec_auth(self):
kiev = "".join(random.choices(string.ascii_uppercase + string.digits, k=32))
return kiev

def create_secrets_json(self):
if not self.secrets_path.exists():
self.secrets_path.parent.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -61,7 +67,9 @@ def requests_cookies(self):
)
data = res.json()
cookies_str = data["result"]["cookies"]
cookies_snapshot = data["result"]["snapshot"]
cookies_screenshot = data["result"]["screenshot"]
kiev = self.generate_kiev_rps_sec_auth()
cookies_str = f"KievRPSSecAuth={kiev}; {cookies_str}"
logger.note(f"Get Cookies: {cookies_str}")
if cookies_str:
with open(self.secrets_path, "r") as rf:
Expand All @@ -71,7 +79,7 @@ def requests_cookies(self):
"created_time": datetime.now().strftime(
self.created_datetime_format
),
"snapshot": self.bypass_url + cookies_snapshot,
"screenshot": self.bypass_url + cookies_screenshot,
}
with open(self.secrets_path, "w") as wf:
json.dump(secrets, wf)
Expand Down

0 comments on commit cd5bef2

Please sign in to comment.