Spaces:
Running
Running
zhou12189108
commited on
Commit
•
1ec2ad3
1
Parent(s):
d0ece4e
Upload api.py
Browse files
api.py
CHANGED
@@ -11,13 +11,10 @@ app = Flask(__name__)
|
|
11 |
user_data_dir = Path(__file__).parent.joinpath("user_data_dir")
|
12 |
context_dir = user_data_dir.joinpath("context")
|
13 |
|
14 |
-
global contexts
|
15 |
|
16 |
-
|
17 |
-
async def __init__():
|
18 |
-
global contexts
|
19 |
async with async_playwright() as p:
|
20 |
-
|
21 |
user_data_dir=context_dir,
|
22 |
headless=True,
|
23 |
locale="en-US"
|
@@ -33,6 +30,7 @@ def get_ipaddr():
|
|
33 |
|
34 |
|
35 |
handler = flog.default_handler
|
|
|
36 |
|
37 |
|
38 |
def get_token():
|
@@ -84,13 +82,11 @@ def update_token():
|
|
84 |
|
85 |
@app.route("/api/solve", methods=["POST"])
|
86 |
def solver_captcha():
|
87 |
-
global contexts
|
88 |
require_data = ["token", "host", "site_key"]
|
89 |
data = request.get_json(force=True, silent=True)
|
90 |
if not check_request(require_data, data):
|
91 |
return jsonify(msg="Unauthorized Request"), 403
|
92 |
-
return asyncio.run(hcaptcha_solver.bytedance(
|
93 |
|
94 |
|
95 |
-
__init__()
|
96 |
app.run(host="0.0.0.0", port=7860)
|
|
|
11 |
user_data_dir = Path(__file__).parent.joinpath("user_data_dir")
|
12 |
context_dir = user_data_dir.joinpath("context")
|
13 |
|
|
|
14 |
|
15 |
+
async def getcontext():
|
|
|
|
|
16 |
async with async_playwright() as p:
|
17 |
+
return p.firefox.launch_persistent_context(
|
18 |
user_data_dir=context_dir,
|
19 |
headless=True,
|
20 |
locale="en-US"
|
|
|
30 |
|
31 |
|
32 |
handler = flog.default_handler
|
33 |
+
context = getcontext()
|
34 |
|
35 |
|
36 |
def get_token():
|
|
|
82 |
|
83 |
@app.route("/api/solve", methods=["POST"])
|
84 |
def solver_captcha():
|
|
|
85 |
require_data = ["token", "host", "site_key"]
|
86 |
data = request.get_json(force=True, silent=True)
|
87 |
if not check_request(require_data, data):
|
88 |
return jsonify(msg="Unauthorized Request"), 403
|
89 |
+
return asyncio.run(hcaptcha_solver.bytedance(context, data["host"], data["site_key"]))
|
90 |
|
91 |
|
|
|
92 |
app.run(host="0.0.0.0", port=7860)
|