feat: 远程浏览器功能 - Web面板内嵌操作滑块验证
- 新增 remote_browser.py: CDP screencast截图流 + 鼠标/键盘事件转发 - Flask-SocketIO 实时通信 - 短信登录时弹出远程浏览器窗口,用户直接在Web页面拖滑块 - 自动检测登录成功并保存auth状态
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
# 确保项目根目录在 sys.path 中
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from flask import Flask, redirect, url_for
|
||||
from flask_socketio import SocketIO
|
||||
from server.database import init_db
|
||||
from server.routers import accounts, tasks, orders
|
||||
|
||||
socketio = SocketIO(cors_allowed_origins="*")
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(
|
||||
@@ -27,9 +29,50 @@ def create_app():
|
||||
def index():
|
||||
return redirect(url_for('tasks.list_tasks'))
|
||||
|
||||
socketio.init_app(app)
|
||||
_register_socketio_events()
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def _register_socketio_events():
|
||||
import asyncio
|
||||
from server.services.remote_browser import get_session
|
||||
|
||||
@socketio.on('rb_mouse', namespace='/rb')
|
||||
def handle_mouse(data):
|
||||
s = get_session(data.get('session_id', ''))
|
||||
if s and s.loop and s.loop.is_running():
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
s.handle_mouse(
|
||||
data.get('action', 'click'),
|
||||
data.get('x', 0), data.get('y', 0)),
|
||||
s.loop)
|
||||
|
||||
@socketio.on('rb_keyboard', namespace='/rb')
|
||||
def handle_keyboard(data):
|
||||
s = get_session(data.get('session_id', ''))
|
||||
if s and s.loop and s.loop.is_running():
|
||||
text = data.get('text', '')
|
||||
if text:
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
s.handle_keyboard(text), s.loop)
|
||||
|
||||
@socketio.on('rb_key', namespace='/rb')
|
||||
def handle_key(data):
|
||||
s = get_session(data.get('session_id', ''))
|
||||
if s and s.loop and s.loop.is_running():
|
||||
key = data.get('key', '')
|
||||
if key:
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
s.handle_key(key), s.loop)
|
||||
|
||||
@socketio.on('rb_close', namespace='/rb')
|
||||
def handle_close(data):
|
||||
from server.services.remote_browser import close_session
|
||||
close_session(data.get('session_id', ''))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = create_app()
|
||||
app.run(host='0.0.0.0', port=9000, debug=True)
|
||||
socketio.run(app, host='0.0.0.0', port=9000, debug=True)
|
||||
|
||||
Reference in New Issue
Block a user