mirror of
https://github.com/j93es/browser-use-oauth.git
synced 2026-06-04 09:01:51 +09:00
feat: 코드베이스 리팩터링
* `run.py`에서 `main.py` 경로를 명시적으로 지정하고, 명령줄 인자를 보다 사용하기 쉽게 조정했습니다. * 에이전트, 리소스 정리, 공통 함수, 모델 등을 포함하는 브라우저 유틸리티용 신규 모듈 구조를 만들었습니다. * `agents.py`에 비동기 에이전트 실행 및 재시도 로직을 구현했습니다. * `scanner.py`에 OAuth URL 추출 및 로그인 테스트 기능을 추가했습니다. * 전반적인 코드베이스에 걸쳐 에러 핸들링 및 로깅을 강화했습니다. * 백엔드 URL과 Google API 키 등의 관리를 위한 환경변수 기반 설정 시스템을 도입했습니다. * 스캐닝 중 진행 상태 추적 및 시그널 핸들링을 통한 정상 종료 처리를 개선했습니다. * 텍스트 파일 읽기 및 HTML 콘텐츠 여부 확인을 위한 유틸리티 함수를 추가했습니다. * LLM과의 상호작용을 위한 구조화된 프롬프트 시스템을 구축했습니다.
This commit is contained in:
parent
1ddc3c41bc
commit
069dbf446d
29 changed files with 453 additions and 452 deletions
2
src/lib/utils/data/__init__.py
Normal file
2
src/lib/utils/data/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from lib.utils.data.backend_client import *
|
||||
from lib.utils.data.logger import *
|
||||
22
src/lib/utils/data/backend_client.py
Normal file
22
src/lib/utils/data/backend_client.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import requests
|
||||
|
||||
from lib.utils.config import BACKEND_URL
|
||||
|
||||
def notify_backend(target_url):
|
||||
# Backend에 스캔 시작을 알림
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{BACKEND_URL}/start", params={"url": target_url}, timeout=5
|
||||
)
|
||||
if response.status_code == 200:
|
||||
print(f"✅ Backend notified: {response.text}")
|
||||
else:
|
||||
print(f"⚠️ Backend notification failed: {response.status_code}")
|
||||
except requests.exceptions.ConnectionError:
|
||||
print(
|
||||
f"⚠️ Backend server not available at {BACKEND_URL}. Continuing without notification."
|
||||
)
|
||||
except requests.exceptions.Timeout:
|
||||
print(f"⚠️ Backend notification timed out. Continuing without notification.")
|
||||
except Exception as e:
|
||||
print(f"⚠️ Failed to notify backend: {e}")
|
||||
29
src/lib/utils/data/logger.py
Normal file
29
src/lib/utils/data/logger.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
# 미리 정해진 파일 경로
|
||||
FILE_PATH = Path("data/log.txt")
|
||||
|
||||
def logger(msg: str) -> None:
|
||||
try:
|
||||
"""
|
||||
msg 문자열을 파일 끝에 추가합니다.
|
||||
- 파일이 없으면 새로 생성
|
||||
- 디렉터리가 없으면 생성
|
||||
"""
|
||||
# 상위 디렉터리 생성 (이미 있으면 무시)
|
||||
FILE_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 현재 시각 구해서 포맷팅
|
||||
now = datetime.now()
|
||||
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# 메시지에 개행이 없으면 자동으로 붙이기
|
||||
newline = "" if msg.endswith("\n") else "\n"
|
||||
line = f"[{timestamp}] {msg}{newline}"
|
||||
|
||||
# 'a' 모드: 파일이 없으면 생성, 있으면 이어쓰기
|
||||
with FILE_PATH.open(mode="a", encoding="utf-8") as f:
|
||||
f.write(line)
|
||||
except:
|
||||
print(msg)
|
||||
Loading…
Add table
Add a link
Reference in a new issue