mirror of
https://github.com/lanqian528/chat2api.git
synced 2026-06-13 21:02:46 +08:00
update pow
This commit is contained in:
parent
295abc8fc0
commit
8dda39672f
@ -11,7 +11,7 @@ from starlette.concurrency import run_in_threadpool
|
||||
from api.files import get_image_size, get_file_extension, determine_file_use_case
|
||||
from api.models import model_proxy
|
||||
from chatgpt.chatFormat import api_messages_to_chat, stream_response, wss_stream_response, format_not_stream_response
|
||||
from chatgpt.proofofWork import calc_proof_token, calc_config_token, get_config, get_dpl
|
||||
from chatgpt.proofofWork import get_config, get_dpl, get_answer, get_requirements_token
|
||||
from chatgpt.wssClient import ac2wss, set_wss
|
||||
from utils.Client import Client
|
||||
from utils.Logger import logger
|
||||
@ -98,7 +98,7 @@ class ChatService:
|
||||
try:
|
||||
await get_dpl(self)
|
||||
config = get_config(self.user_agent)
|
||||
data = {'p': calc_config_token(config)}
|
||||
data = {'p': get_requirements_token(config)}
|
||||
r = await self.s.post(url, headers=headers, json=data, timeout=5)
|
||||
if r.status_code == 200:
|
||||
resp = r.json()
|
||||
@ -121,7 +121,7 @@ class ChatService:
|
||||
if proofofwork_diff.startswith("0" * (pow_difficulty + 1)):
|
||||
raise HTTPException(status_code=403, detail=f"Proof of work difficulty too high: {proofofwork_diff}")
|
||||
proofofwork_seed = proofofwork.get("seed")
|
||||
self.proof_token = await run_in_threadpool(calc_proof_token, proofofwork_seed, proofofwork_diff, config)
|
||||
self.proof_token = await run_in_threadpool(get_answer, proofofwork_seed, proofofwork_diff, config)
|
||||
|
||||
arkose_required = arkose.get('required')
|
||||
if arkose_required:
|
||||
|
||||
@ -8,7 +8,7 @@ from html.parser import HTMLParser
|
||||
|
||||
from utils.Logger import logger
|
||||
|
||||
cores = [8, 12, 16, 24, 32]
|
||||
cores = [16, 24, 32]
|
||||
screens = [3000, 4000, 6000]
|
||||
timeLayout = "%a %b %d %Y %H:%M:%S"
|
||||
|
||||
@ -17,6 +17,262 @@ cached_dpl = ""
|
||||
cached_time = 0
|
||||
cached_require_proof = ""
|
||||
|
||||
navigator_key = ['hardwareConcurrency−16', 'login−[object NavigatorLogin]']
|
||||
document_key = ['_reactListeningpa877jnmig', 'location']
|
||||
window_key = [
|
||||
"0",
|
||||
"window",
|
||||
"self",
|
||||
"document",
|
||||
"name",
|
||||
"location",
|
||||
"customElements",
|
||||
"history",
|
||||
"navigation",
|
||||
"locationbar",
|
||||
"menubar",
|
||||
"personalbar",
|
||||
"scrollbars",
|
||||
"statusbar",
|
||||
"toolbar",
|
||||
"status",
|
||||
"closed",
|
||||
"frames",
|
||||
"length",
|
||||
"top",
|
||||
"opener",
|
||||
"parent",
|
||||
"frameElement",
|
||||
"navigator",
|
||||
"origin",
|
||||
"external",
|
||||
"screen",
|
||||
"innerWidth",
|
||||
"innerHeight",
|
||||
"scrollX",
|
||||
"pageXOffset",
|
||||
"scrollY",
|
||||
"pageYOffset",
|
||||
"visualViewport",
|
||||
"screenX",
|
||||
"screenY",
|
||||
"outerWidth",
|
||||
"outerHeight",
|
||||
"devicePixelRatio",
|
||||
"clientInformation",
|
||||
"screenLeft",
|
||||
"screenTop",
|
||||
"styleMedia",
|
||||
"onsearch",
|
||||
"isSecureContext",
|
||||
"trustedTypes",
|
||||
"performance",
|
||||
"onappinstalled",
|
||||
"onbeforeinstallprompt",
|
||||
"crypto",
|
||||
"indexedDB",
|
||||
"sessionStorage",
|
||||
"localStorage",
|
||||
"onbeforexrselect",
|
||||
"onabort",
|
||||
"onbeforeinput",
|
||||
"onbeforematch",
|
||||
"onbeforetoggle",
|
||||
"onblur",
|
||||
"oncancel",
|
||||
"oncanplay",
|
||||
"oncanplaythrough",
|
||||
"onchange",
|
||||
"onclick",
|
||||
"onclose",
|
||||
"oncontentvisibilityautostatechange",
|
||||
"oncontextlost",
|
||||
"oncontextmenu",
|
||||
"oncontextrestored",
|
||||
"oncuechange",
|
||||
"ondblclick",
|
||||
"ondrag",
|
||||
"ondragend",
|
||||
"ondragenter",
|
||||
"ondragleave",
|
||||
"ondragover",
|
||||
"ondragstart",
|
||||
"ondrop",
|
||||
"ondurationchange",
|
||||
"onemptied",
|
||||
"onended",
|
||||
"onerror",
|
||||
"onfocus",
|
||||
"onformdata",
|
||||
"oninput",
|
||||
"oninvalid",
|
||||
"onkeydown",
|
||||
"onkeypress",
|
||||
"onkeyup",
|
||||
"onload",
|
||||
"onloadeddata",
|
||||
"onloadedmetadata",
|
||||
"onloadstart",
|
||||
"onmousedown",
|
||||
"onmouseenter",
|
||||
"onmouseleave",
|
||||
"onmousemove",
|
||||
"onmouseout",
|
||||
"onmouseover",
|
||||
"onmouseup",
|
||||
"onmousewheel",
|
||||
"onpause",
|
||||
"onplay",
|
||||
"onplaying",
|
||||
"onprogress",
|
||||
"onratechange",
|
||||
"onreset",
|
||||
"onresize",
|
||||
"onscroll",
|
||||
"onsecuritypolicyviolation",
|
||||
"onseeked",
|
||||
"onseeking",
|
||||
"onselect",
|
||||
"onslotchange",
|
||||
"onstalled",
|
||||
"onsubmit",
|
||||
"onsuspend",
|
||||
"ontimeupdate",
|
||||
"ontoggle",
|
||||
"onvolumechange",
|
||||
"onwaiting",
|
||||
"onwebkitanimationend",
|
||||
"onwebkitanimationiteration",
|
||||
"onwebkitanimationstart",
|
||||
"onwebkittransitionend",
|
||||
"onwheel",
|
||||
"onauxclick",
|
||||
"ongotpointercapture",
|
||||
"onlostpointercapture",
|
||||
"onpointerdown",
|
||||
"onpointermove",
|
||||
"onpointerrawupdate",
|
||||
"onpointerup",
|
||||
"onpointercancel",
|
||||
"onpointerover",
|
||||
"onpointerout",
|
||||
"onpointerenter",
|
||||
"onpointerleave",
|
||||
"onselectstart",
|
||||
"onselectionchange",
|
||||
"onanimationend",
|
||||
"onanimationiteration",
|
||||
"onanimationstart",
|
||||
"ontransitionrun",
|
||||
"ontransitionstart",
|
||||
"ontransitionend",
|
||||
"ontransitioncancel",
|
||||
"onafterprint",
|
||||
"onbeforeprint",
|
||||
"onbeforeunload",
|
||||
"onhashchange",
|
||||
"onlanguagechange",
|
||||
"onmessage",
|
||||
"onmessageerror",
|
||||
"onoffline",
|
||||
"ononline",
|
||||
"onpagehide",
|
||||
"onpageshow",
|
||||
"onpopstate",
|
||||
"onrejectionhandled",
|
||||
"onstorage",
|
||||
"onunhandledrejection",
|
||||
"onunload",
|
||||
"crossOriginIsolated",
|
||||
"scheduler",
|
||||
"alert",
|
||||
"atob",
|
||||
"blur",
|
||||
"btoa",
|
||||
"cancelAnimationFrame",
|
||||
"cancelIdleCallback",
|
||||
"captureEvents",
|
||||
"clearInterval",
|
||||
"clearTimeout",
|
||||
"close",
|
||||
"confirm",
|
||||
"createImageBitmap",
|
||||
"fetch",
|
||||
"find",
|
||||
"focus",
|
||||
"getComputedStyle",
|
||||
"getSelection",
|
||||
"matchMedia",
|
||||
"moveBy",
|
||||
"moveTo",
|
||||
"open",
|
||||
"postMessage",
|
||||
"print",
|
||||
"prompt",
|
||||
"queueMicrotask",
|
||||
"releaseEvents",
|
||||
"reportError",
|
||||
"requestAnimationFrame",
|
||||
"requestIdleCallback",
|
||||
"resizeBy",
|
||||
"resizeTo",
|
||||
"scroll",
|
||||
"scrollBy",
|
||||
"scrollTo",
|
||||
"setInterval",
|
||||
"setTimeout",
|
||||
"stop",
|
||||
"structuredClone",
|
||||
"webkitCancelAnimationFrame",
|
||||
"webkitRequestAnimationFrame",
|
||||
"chrome",
|
||||
"caches",
|
||||
"cookieStore",
|
||||
"ondevicemotion",
|
||||
"ondeviceorientation",
|
||||
"ondeviceorientationabsolute",
|
||||
"launchQueue",
|
||||
"documentPictureInPicture",
|
||||
"getScreenDetails",
|
||||
"queryLocalFonts",
|
||||
"showDirectoryPicker",
|
||||
"showOpenFilePicker",
|
||||
"showSaveFilePicker",
|
||||
"originAgentCluster",
|
||||
"onpageswap",
|
||||
"onpagereveal",
|
||||
"credentialless",
|
||||
"speechSynthesis",
|
||||
"onscrollend",
|
||||
"webkitRequestFileSystem",
|
||||
"webkitResolveLocalFileSystemURL",
|
||||
"sendMsgToSolverCS",
|
||||
"webpackChunk_N_E",
|
||||
"__next_set_public_path__",
|
||||
"next",
|
||||
"__NEXT_DATA__",
|
||||
"__SSG_MANIFEST_CB",
|
||||
"__NEXT_P",
|
||||
"_N_E",
|
||||
"regeneratorRuntime",
|
||||
"__REACT_INTL_CONTEXT__",
|
||||
"DD_RUM",
|
||||
"_",
|
||||
"filterCSS",
|
||||
"filterXSS",
|
||||
"__SEGMENT_INSPECTOR__",
|
||||
"__NEXT_PRELOADREADY",
|
||||
"Intercom",
|
||||
"__MIDDLEWARE_MATCHERS",
|
||||
"__STATSIG_SDK__",
|
||||
"__STATSIG_JS_SDK__",
|
||||
"__STATSIG_RERENDER_OVERRIDE__",
|
||||
"_oaiHandleSessionExpired",
|
||||
"__BUILD_MANIFEST",
|
||||
"__SSG_MANIFEST",
|
||||
"__intercomAssignLocation",
|
||||
"__intercomReloadLocation"
|
||||
]
|
||||
|
||||
class ScriptSrcParser(HTMLParser):
|
||||
def handle_starttag(self, tag, attrs):
|
||||
@ -32,7 +288,8 @@ class ScriptSrcParser(HTMLParser):
|
||||
|
||||
|
||||
async def get_dpl(service):
|
||||
if int(time.time()) - cached_time < 10 * 60:
|
||||
global cached_scripts, cached_dpl, cached_time
|
||||
if int(time.time()) - cached_time < 15 * 60:
|
||||
return True
|
||||
headers = service.base_headers.copy()
|
||||
try:
|
||||
@ -40,14 +297,18 @@ async def get_dpl(service):
|
||||
r.raise_for_status()
|
||||
parser = ScriptSrcParser()
|
||||
parser.feed(r.text)
|
||||
return len(cached_scripts) != 0
|
||||
if len(cached_scripts) == 0:
|
||||
cached_scripts.append("https://cdn.oaistatic.com/_next/static/cXh69klOLzS0Gy2joLDRS/_ssgManifest.js?dpl=453ebaec0d44c2decab71692e1bfe39be35a24b3")
|
||||
cached_dpl = "453ebaec0d44c2decab71692e1bfe39be35a24b3"
|
||||
cached_time = int(time.time())
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def get_parse_time():
|
||||
now = datetime.now(timezone(timedelta(hours=-8)))
|
||||
return now.strftime(timeLayout) + " GMT-0800 (Pacific Time)"
|
||||
now = datetime.now(timezone(timedelta(hours=+9)))
|
||||
return now.strftime(timeLayout) + " GMT+0900 (Japan Standard Time)"
|
||||
|
||||
|
||||
def get_config(user_agent):
|
||||
@ -65,20 +326,20 @@ def get_config(user_agent):
|
||||
"en-US",
|
||||
"en-US,en",
|
||||
0,
|
||||
"login−[object NavigatorLogin]",
|
||||
"_reactListeningpa877jnmig",
|
||||
"onpointerout"
|
||||
random.choice(navigator_key),
|
||||
random.choice(document_key),
|
||||
random.choice(window_key)
|
||||
]
|
||||
return config
|
||||
|
||||
|
||||
def calc_proof_token(seed, diff, config):
|
||||
def get_answer(seed, diff, config):
|
||||
proof = generate_answer(seed, diff, config)
|
||||
return "gAAAAAB" + proof
|
||||
|
||||
|
||||
def generate_answer(seed, diff, config):
|
||||
diff_len = len(diff) // 2
|
||||
diff_len = len(diff)
|
||||
start = time.time()
|
||||
seed_encoded = seed.encode()
|
||||
|
||||
@ -90,7 +351,7 @@ def generate_answer(seed, diff, config):
|
||||
hasher = hashlib.sha3_512()
|
||||
hasher.update(seed_encoded + base.encode())
|
||||
hash_value = hasher.digest()
|
||||
if hash_value[:diff_len].hex() <= diff:
|
||||
if hash_value.hex()[:diff_len] <= diff:
|
||||
end = time.time()
|
||||
logger.info(f'seed: {seed}, diff: {diff}, count: {i}, time: {int((end - start) * 1000000) / 1000}ms')
|
||||
return base
|
||||
@ -98,8 +359,8 @@ def generate_answer(seed, diff, config):
|
||||
return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.b64encode(f'"{seed}"'.encode()).decode()
|
||||
|
||||
|
||||
def calc_config_token(config):
|
||||
def get_requirements_token(config):
|
||||
global cached_require_proof, cached_time
|
||||
if not cached_require_proof or int(time.time()) - cached_time >= 10 * 60:
|
||||
if not cached_require_proof or int(time.time()) - cached_time >= 15 * 60:
|
||||
cached_require_proof = generate_answer(format(random.random()), "0", config)
|
||||
return 'gAAAAAC' + cached_require_proof
|
||||
|
||||
Loading…
Reference in New Issue
Block a user