mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-09-05 23:47:33 +08:00
feat(register): 注册后自动操作增加服务
This commit is contained in:
+158
-54
@@ -70,24 +70,32 @@ class RegistrationTaskCreate(BaseModel):
|
|||||||
email_service_type: str = "tempmail"
|
email_service_type: str = "tempmail"
|
||||||
proxy: Optional[str] = None
|
proxy: Optional[str] = None
|
||||||
email_service_config: Optional[dict] = None
|
email_service_config: Optional[dict] = None
|
||||||
email_service_id: Optional[int] = None # 使用数据库中已配置的邮箱服务 ID
|
email_service_id: Optional[int] = None
|
||||||
auto_upload_cpa: bool = False # 注册成功后自动上传到 CPA
|
auto_upload_cpa: bool = False
|
||||||
cpa_service_id: Optional[int] = None # 指定 CPA 服务 ID,不传则使用全局配置
|
cpa_service_ids: List[int] = [] # 指定 CPA 服务 ID 列表,空则取第一个启用的
|
||||||
|
auto_upload_sub2api: bool = False
|
||||||
|
sub2api_service_ids: List[int] = [] # 指定 Sub2API 服务 ID 列表
|
||||||
|
auto_upload_tm: bool = False
|
||||||
|
tm_service_ids: List[int] = [] # 指定 TM 服务 ID 列表
|
||||||
|
|
||||||
|
|
||||||
class BatchRegistrationRequest(BaseModel):
|
class BatchRegistrationRequest(BaseModel):
|
||||||
"""批量注册请求"""
|
"""批量注册请求"""
|
||||||
count: int = 1 # 注册数量
|
count: int = 1
|
||||||
email_service_type: str = "tempmail"
|
email_service_type: str = "tempmail"
|
||||||
proxy: Optional[str] = None
|
proxy: Optional[str] = None
|
||||||
email_service_config: Optional[dict] = None
|
email_service_config: Optional[dict] = None
|
||||||
email_service_id: Optional[int] = None # 使用数据库中已配置的邮箱服务 ID
|
email_service_id: Optional[int] = None
|
||||||
interval_min: int = 5 # 最小间隔秒数
|
interval_min: int = 5
|
||||||
interval_max: int = 30 # 最大间隔秒数
|
interval_max: int = 30
|
||||||
concurrency: int = 1 # 并发线程数 (1-50)
|
concurrency: int = 1
|
||||||
mode: str = "pipeline" # 执行模式: "parallel" 或 "pipeline"
|
mode: str = "pipeline"
|
||||||
auto_upload_cpa: bool = False # 注册成功后自动上传到 CPA
|
auto_upload_cpa: bool = False
|
||||||
cpa_service_id: Optional[int] = None # 指定 CPA 服务 ID,不传则使用全局配置
|
cpa_service_ids: List[int] = []
|
||||||
|
auto_upload_sub2api: bool = False
|
||||||
|
sub2api_service_ids: List[int] = []
|
||||||
|
auto_upload_tm: bool = False
|
||||||
|
tm_service_ids: List[int] = []
|
||||||
|
|
||||||
|
|
||||||
class RegistrationTaskResponse(BaseModel):
|
class RegistrationTaskResponse(BaseModel):
|
||||||
@@ -143,15 +151,19 @@ class OutlookAccountsListResponse(BaseModel):
|
|||||||
|
|
||||||
class OutlookBatchRegistrationRequest(BaseModel):
|
class OutlookBatchRegistrationRequest(BaseModel):
|
||||||
"""Outlook 批量注册请求"""
|
"""Outlook 批量注册请求"""
|
||||||
service_ids: List[int] # 选中的 EmailService ID
|
service_ids: List[int]
|
||||||
skip_registered: bool = True # 自动跳过已注册邮箱
|
skip_registered: bool = True
|
||||||
proxy: Optional[str] = None
|
proxy: Optional[str] = None
|
||||||
interval_min: int = 5
|
interval_min: int = 5
|
||||||
interval_max: int = 30
|
interval_max: int = 30
|
||||||
concurrency: int = 1 # 并发线程数 (1-50)
|
concurrency: int = 1
|
||||||
mode: str = "pipeline" # 执行模式: "parallel" 或 "pipeline"
|
mode: str = "pipeline"
|
||||||
auto_upload_cpa: bool = False # 注册成功后自动上传到 CPA
|
auto_upload_cpa: bool = False
|
||||||
cpa_service_id: Optional[int] = None # 指定 CPA 服务 ID,不传则使用全局配置
|
cpa_service_ids: List[int] = []
|
||||||
|
auto_upload_sub2api: bool = False
|
||||||
|
sub2api_service_ids: List[int] = []
|
||||||
|
auto_upload_tm: bool = False
|
||||||
|
tm_service_ids: List[int] = []
|
||||||
|
|
||||||
|
|
||||||
class OutlookBatchRegistrationResponse(BaseModel):
|
class OutlookBatchRegistrationResponse(BaseModel):
|
||||||
@@ -182,7 +194,7 @@ def task_to_response(task: RegistrationTask) -> RegistrationTaskResponse:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy: Optional[str], email_service_config: Optional[dict], email_service_id: Optional[int] = None, log_prefix: str = "", batch_id: str = "", auto_upload_cpa: bool = False, cpa_service_id: Optional[int] = None):
|
def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy: Optional[str], email_service_config: Optional[dict], email_service_id: Optional[int] = None, log_prefix: str = "", batch_id: str = "", auto_upload_cpa: bool = False, cpa_service_ids: List[int] = None, auto_upload_sub2api: bool = False, sub2api_service_ids: List[int] = None, auto_upload_tm: bool = False, tm_service_ids: List[int] = None):
|
||||||
"""
|
"""
|
||||||
在线程池中执行的同步注册任务
|
在线程池中执行的同步注册任务
|
||||||
|
|
||||||
@@ -339,7 +351,7 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy:
|
|||||||
# 保存到数据库
|
# 保存到数据库
|
||||||
engine.save_to_database(result)
|
engine.save_to_database(result)
|
||||||
|
|
||||||
# 自动上传到 CPA
|
# 自动上传到 CPA(可多服务)
|
||||||
if auto_upload_cpa:
|
if auto_upload_cpa:
|
||||||
try:
|
try:
|
||||||
from ...core.cpa_upload import upload_to_cpa, generate_token_json
|
from ...core.cpa_upload import upload_to_cpa, generate_token_json
|
||||||
@@ -347,33 +359,81 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy:
|
|||||||
saved_account = db.query(AccountModel).filter_by(email=result.email).first()
|
saved_account = db.query(AccountModel).filter_by(email=result.email).first()
|
||||||
if saved_account and saved_account.access_token:
|
if saved_account and saved_account.access_token:
|
||||||
token_data = generate_token_json(saved_account)
|
token_data = generate_token_json(saved_account)
|
||||||
# 解析指定 CPA 服务,未指定则取第一个启用的服务
|
_cpa_ids = cpa_service_ids or []
|
||||||
_cpa_api_url = None
|
if not _cpa_ids:
|
||||||
_cpa_api_token = None
|
# 未指定则取所有启用的服务
|
||||||
_svc = None
|
_cpa_ids = [s.id for s in crud.get_cpa_services(db, enabled=True)]
|
||||||
if cpa_service_id:
|
if not _cpa_ids:
|
||||||
|
log_callback("[CPA] 无可用 CPA 服务,跳过上传")
|
||||||
|
for _sid in _cpa_ids:
|
||||||
try:
|
try:
|
||||||
_svc = crud.get_cpa_service_by_id(db, cpa_service_id)
|
_svc = crud.get_cpa_service_by_id(db, _sid)
|
||||||
except Exception:
|
if not _svc:
|
||||||
pass
|
continue
|
||||||
if _svc is None:
|
log_callback(f"[CPA] 上传到服务: {_svc.name}")
|
||||||
svcs = crud.get_cpa_services(db, enabled=True)
|
_ok, _msg = upload_to_cpa(token_data, api_url=_svc.api_url, api_token=_svc.api_token)
|
||||||
_svc = svcs[0] if svcs else None
|
if _ok:
|
||||||
if _svc:
|
|
||||||
_cpa_api_url = _svc.api_url
|
|
||||||
_cpa_api_token = _svc.api_token
|
|
||||||
log_callback(f"[CPA] 使用服务: {_svc.name}")
|
|
||||||
cpa_success, cpa_msg = upload_to_cpa(token_data, api_url=_cpa_api_url, api_token=_cpa_api_token)
|
|
||||||
if cpa_success:
|
|
||||||
saved_account.cpa_uploaded = True
|
saved_account.cpa_uploaded = True
|
||||||
saved_account.cpa_uploaded_at = datetime.utcnow()
|
saved_account.cpa_uploaded_at = datetime.utcnow()
|
||||||
db.commit()
|
db.commit()
|
||||||
log_callback(f"[CPA] 已自动上传到 CPA: {result.email}")
|
log_callback(f"[CPA] 上传成功: {_svc.name}")
|
||||||
else:
|
else:
|
||||||
log_callback(f"[CPA] 上传失败: {cpa_msg}")
|
log_callback(f"[CPA] 上传失败({_svc.name}): {_msg}")
|
||||||
|
except Exception as _e:
|
||||||
|
log_callback(f"[CPA] 异常({_sid}): {_e}")
|
||||||
except Exception as cpa_err:
|
except Exception as cpa_err:
|
||||||
log_callback(f"[CPA] 上传异常: {cpa_err}")
|
log_callback(f"[CPA] 上传异常: {cpa_err}")
|
||||||
|
|
||||||
|
# 自动上传到 Sub2API(可多服务)
|
||||||
|
if auto_upload_sub2api:
|
||||||
|
try:
|
||||||
|
from ...core.sub2api_upload import upload_to_sub2api
|
||||||
|
from ...database.models import Account as AccountModel
|
||||||
|
saved_account = db.query(AccountModel).filter_by(email=result.email).first()
|
||||||
|
if saved_account and saved_account.access_token:
|
||||||
|
_s2a_ids = sub2api_service_ids or []
|
||||||
|
if not _s2a_ids:
|
||||||
|
_s2a_ids = [s.id for s in crud.get_sub2api_services(db, enabled=True)]
|
||||||
|
if not _s2a_ids:
|
||||||
|
log_callback("[Sub2API] 无可用 Sub2API 服务,跳过上传")
|
||||||
|
for _sid in _s2a_ids:
|
||||||
|
try:
|
||||||
|
_svc = crud.get_sub2api_service_by_id(db, _sid)
|
||||||
|
if not _svc:
|
||||||
|
continue
|
||||||
|
log_callback(f"[Sub2API] 上传到服务: {_svc.name}")
|
||||||
|
_ok, _msg = upload_to_sub2api([saved_account], _svc.api_url, _svc.api_key)
|
||||||
|
log_callback(f"[Sub2API] {'成功' if _ok else '失败'}({_svc.name}): {_msg}")
|
||||||
|
except Exception as _e:
|
||||||
|
log_callback(f"[Sub2API] 异常({_sid}): {_e}")
|
||||||
|
except Exception as s2a_err:
|
||||||
|
log_callback(f"[Sub2API] 上传异常: {s2a_err}")
|
||||||
|
|
||||||
|
# 自动上传到 Team Manager(可多服务)
|
||||||
|
if auto_upload_tm:
|
||||||
|
try:
|
||||||
|
from ...core.team_manager import upload_account_to_tm
|
||||||
|
from ...database.models import Account as AccountModel
|
||||||
|
saved_account = db.query(AccountModel).filter_by(email=result.email).first()
|
||||||
|
if saved_account and saved_account.access_token:
|
||||||
|
_tm_ids = tm_service_ids or []
|
||||||
|
if not _tm_ids:
|
||||||
|
_tm_ids = [s.id for s in crud.get_tm_services(db, enabled=True)]
|
||||||
|
if not _tm_ids:
|
||||||
|
log_callback("[TM] 无可用 Team Manager 服务,跳过上传")
|
||||||
|
for _sid in _tm_ids:
|
||||||
|
try:
|
||||||
|
_svc = crud.get_tm_service_by_id(db, _sid)
|
||||||
|
if not _svc:
|
||||||
|
continue
|
||||||
|
log_callback(f"[TM] 上传到服务: {_svc.name}")
|
||||||
|
_ok, _msg = upload_account_to_tm(saved_account, _svc.api_url, _svc.api_key)
|
||||||
|
log_callback(f"[TM] {'成功' if _ok else '失败'}({_svc.name}): {_msg}")
|
||||||
|
except Exception as _e:
|
||||||
|
log_callback(f"[TM] 异常({_sid}): {_e}")
|
||||||
|
except Exception as tm_err:
|
||||||
|
log_callback(f"[TM] 上传异常: {tm_err}")
|
||||||
|
|
||||||
# 更新任务状态
|
# 更新任务状态
|
||||||
crud.update_registration_task(
|
crud.update_registration_task(
|
||||||
db, task_uuid,
|
db, task_uuid,
|
||||||
@@ -418,7 +478,7 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def run_registration_task(task_uuid: str, email_service_type: str, proxy: Optional[str], email_service_config: Optional[dict], email_service_id: Optional[int] = None, log_prefix: str = "", batch_id: str = "", auto_upload_cpa: bool = False, cpa_service_id: Optional[int] = None):
|
async def run_registration_task(task_uuid: str, email_service_type: str, proxy: Optional[str], email_service_config: Optional[dict], email_service_id: Optional[int] = None, log_prefix: str = "", batch_id: str = "", auto_upload_cpa: bool = False, cpa_service_ids: List[int] = None, auto_upload_sub2api: bool = False, sub2api_service_ids: List[int] = None, auto_upload_tm: bool = False, tm_service_ids: List[int] = None):
|
||||||
"""
|
"""
|
||||||
异步执行注册任务
|
异步执行注册任务
|
||||||
|
|
||||||
@@ -446,7 +506,11 @@ async def run_registration_task(task_uuid: str, email_service_type: str, proxy:
|
|||||||
log_prefix,
|
log_prefix,
|
||||||
batch_id,
|
batch_id,
|
||||||
auto_upload_cpa,
|
auto_upload_cpa,
|
||||||
cpa_service_id
|
cpa_service_ids or [],
|
||||||
|
auto_upload_sub2api,
|
||||||
|
sub2api_service_ids or [],
|
||||||
|
auto_upload_tm,
|
||||||
|
tm_service_ids or [],
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"线程池执行异常: {task_uuid}, 错误: {e}")
|
logger.error(f"线程池执行异常: {task_uuid}, 错误: {e}")
|
||||||
@@ -494,7 +558,11 @@ async def run_batch_parallel(
|
|||||||
email_service_id: Optional[int],
|
email_service_id: Optional[int],
|
||||||
concurrency: int,
|
concurrency: int,
|
||||||
auto_upload_cpa: bool = False,
|
auto_upload_cpa: bool = False,
|
||||||
cpa_service_id: Optional[int] = None
|
cpa_service_ids: List[int] = None,
|
||||||
|
auto_upload_sub2api: bool = False,
|
||||||
|
sub2api_service_ids: List[int] = None,
|
||||||
|
auto_upload_tm: bool = False,
|
||||||
|
tm_service_ids: List[int] = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
并行模式:所有任务同时提交,Semaphore 控制最大并发数
|
并行模式:所有任务同时提交,Semaphore 控制最大并发数
|
||||||
@@ -510,8 +578,10 @@ async def run_batch_parallel(
|
|||||||
async with semaphore:
|
async with semaphore:
|
||||||
await run_registration_task(
|
await run_registration_task(
|
||||||
uuid, email_service_type, proxy, email_service_config, email_service_id,
|
uuid, email_service_type, proxy, email_service_config, email_service_id,
|
||||||
log_prefix=prefix, batch_id=batch_id, auto_upload_cpa=auto_upload_cpa,
|
log_prefix=prefix, batch_id=batch_id,
|
||||||
cpa_service_id=cpa_service_id
|
auto_upload_cpa=auto_upload_cpa, cpa_service_ids=cpa_service_ids or [],
|
||||||
|
auto_upload_sub2api=auto_upload_sub2api, sub2api_service_ids=sub2api_service_ids or [],
|
||||||
|
auto_upload_tm=auto_upload_tm, tm_service_ids=tm_service_ids or [],
|
||||||
)
|
)
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
t = crud.get_registration_task(db, uuid)
|
t = crud.get_registration_task(db, uuid)
|
||||||
@@ -554,7 +624,11 @@ async def run_batch_pipeline(
|
|||||||
interval_max: int,
|
interval_max: int,
|
||||||
concurrency: int,
|
concurrency: int,
|
||||||
auto_upload_cpa: bool = False,
|
auto_upload_cpa: bool = False,
|
||||||
cpa_service_id: Optional[int] = None
|
cpa_service_ids: List[int] = None,
|
||||||
|
auto_upload_sub2api: bool = False,
|
||||||
|
sub2api_service_ids: List[int] = None,
|
||||||
|
auto_upload_tm: bool = False,
|
||||||
|
tm_service_ids: List[int] = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
流水线模式:每隔 interval 秒启动一个新任务,Semaphore 限制最大并发数
|
流水线模式:每隔 interval 秒启动一个新任务,Semaphore 限制最大并发数
|
||||||
@@ -570,8 +644,10 @@ async def run_batch_pipeline(
|
|||||||
try:
|
try:
|
||||||
await run_registration_task(
|
await run_registration_task(
|
||||||
uuid, email_service_type, proxy, email_service_config, email_service_id,
|
uuid, email_service_type, proxy, email_service_config, email_service_id,
|
||||||
log_prefix=pfx, batch_id=batch_id, auto_upload_cpa=auto_upload_cpa,
|
log_prefix=pfx, batch_id=batch_id,
|
||||||
cpa_service_id=cpa_service_id
|
auto_upload_cpa=auto_upload_cpa, cpa_service_ids=cpa_service_ids or [],
|
||||||
|
auto_upload_sub2api=auto_upload_sub2api, sub2api_service_ids=sub2api_service_ids or [],
|
||||||
|
auto_upload_tm=auto_upload_tm, tm_service_ids=tm_service_ids or [],
|
||||||
)
|
)
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
t = crud.get_registration_task(db, uuid)
|
t = crud.get_registration_task(db, uuid)
|
||||||
@@ -638,21 +714,29 @@ async def run_batch_registration(
|
|||||||
concurrency: int = 1,
|
concurrency: int = 1,
|
||||||
mode: str = "pipeline",
|
mode: str = "pipeline",
|
||||||
auto_upload_cpa: bool = False,
|
auto_upload_cpa: bool = False,
|
||||||
cpa_service_id: Optional[int] = None
|
cpa_service_ids: List[int] = None,
|
||||||
|
auto_upload_sub2api: bool = False,
|
||||||
|
sub2api_service_ids: List[int] = None,
|
||||||
|
auto_upload_tm: bool = False,
|
||||||
|
tm_service_ids: List[int] = None,
|
||||||
):
|
):
|
||||||
"""根据 mode 分发到并行或流水线执行"""
|
"""根据 mode 分发到并行或流水线执行"""
|
||||||
if mode == "parallel":
|
if mode == "parallel":
|
||||||
await run_batch_parallel(
|
await run_batch_parallel(
|
||||||
batch_id, task_uuids, email_service_type, proxy,
|
batch_id, task_uuids, email_service_type, proxy,
|
||||||
email_service_config, email_service_id, concurrency,
|
email_service_config, email_service_id, concurrency,
|
||||||
auto_upload_cpa=auto_upload_cpa, cpa_service_id=cpa_service_id
|
auto_upload_cpa=auto_upload_cpa, cpa_service_ids=cpa_service_ids,
|
||||||
|
auto_upload_sub2api=auto_upload_sub2api, sub2api_service_ids=sub2api_service_ids,
|
||||||
|
auto_upload_tm=auto_upload_tm, tm_service_ids=tm_service_ids,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await run_batch_pipeline(
|
await run_batch_pipeline(
|
||||||
batch_id, task_uuids, email_service_type, proxy,
|
batch_id, task_uuids, email_service_type, proxy,
|
||||||
email_service_config, email_service_id,
|
email_service_config, email_service_id,
|
||||||
interval_min, interval_max, concurrency,
|
interval_min, interval_max, concurrency,
|
||||||
auto_upload_cpa=auto_upload_cpa, cpa_service_id=cpa_service_id
|
auto_upload_cpa=auto_upload_cpa, cpa_service_ids=cpa_service_ids,
|
||||||
|
auto_upload_sub2api=auto_upload_sub2api, sub2api_service_ids=sub2api_service_ids,
|
||||||
|
auto_upload_tm=auto_upload_tm, tm_service_ids=tm_service_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -700,7 +784,11 @@ async def start_registration(
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
request.auto_upload_cpa,
|
request.auto_upload_cpa,
|
||||||
request.cpa_service_id
|
request.cpa_service_ids,
|
||||||
|
request.auto_upload_sub2api,
|
||||||
|
request.sub2api_service_ids,
|
||||||
|
request.auto_upload_tm,
|
||||||
|
request.tm_service_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
return task_to_response(task)
|
return task_to_response(task)
|
||||||
@@ -773,7 +861,11 @@ async def start_batch_registration(
|
|||||||
request.concurrency,
|
request.concurrency,
|
||||||
request.mode,
|
request.mode,
|
||||||
request.auto_upload_cpa,
|
request.auto_upload_cpa,
|
||||||
request.cpa_service_id
|
request.cpa_service_ids,
|
||||||
|
request.auto_upload_sub2api,
|
||||||
|
request.sub2api_service_ids,
|
||||||
|
request.auto_upload_tm,
|
||||||
|
request.tm_service_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
return BatchRegistrationResponse(
|
return BatchRegistrationResponse(
|
||||||
@@ -1103,7 +1195,11 @@ async def run_outlook_batch_registration(
|
|||||||
concurrency: int = 1,
|
concurrency: int = 1,
|
||||||
mode: str = "pipeline",
|
mode: str = "pipeline",
|
||||||
auto_upload_cpa: bool = False,
|
auto_upload_cpa: bool = False,
|
||||||
cpa_service_id: Optional[int] = None
|
cpa_service_ids: List[int] = None,
|
||||||
|
auto_upload_sub2api: bool = False,
|
||||||
|
sub2api_service_ids: List[int] = None,
|
||||||
|
auto_upload_tm: bool = False,
|
||||||
|
tm_service_ids: List[int] = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
异步执行 Outlook 批量注册任务,复用通用并发逻辑
|
异步执行 Outlook 批量注册任务,复用通用并发逻辑
|
||||||
@@ -1142,7 +1238,11 @@ async def run_outlook_batch_registration(
|
|||||||
concurrency=concurrency,
|
concurrency=concurrency,
|
||||||
mode=mode,
|
mode=mode,
|
||||||
auto_upload_cpa=auto_upload_cpa,
|
auto_upload_cpa=auto_upload_cpa,
|
||||||
cpa_service_id=cpa_service_id
|
cpa_service_ids=cpa_service_ids,
|
||||||
|
auto_upload_sub2api=auto_upload_sub2api,
|
||||||
|
sub2api_service_ids=sub2api_service_ids,
|
||||||
|
auto_upload_tm=auto_upload_tm,
|
||||||
|
tm_service_ids=tm_service_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1242,7 +1342,11 @@ async def start_outlook_batch_registration(
|
|||||||
request.concurrency,
|
request.concurrency,
|
||||||
request.mode,
|
request.mode,
|
||||||
request.auto_upload_cpa,
|
request.auto_upload_cpa,
|
||||||
request.cpa_service_id
|
request.cpa_service_ids,
|
||||||
|
request.auto_upload_sub2api,
|
||||||
|
request.sub2api_service_ids,
|
||||||
|
request.auto_upload_tm,
|
||||||
|
request.tm_service_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
return OutlookBatchRegistrationResponse(
|
return OutlookBatchRegistrationResponse(
|
||||||
|
|||||||
+61
-43
@@ -85,7 +85,13 @@ const elements = {
|
|||||||
// 注册后自动操作
|
// 注册后自动操作
|
||||||
autoUploadCpa: document.getElementById('auto-upload-cpa'),
|
autoUploadCpa: document.getElementById('auto-upload-cpa'),
|
||||||
cpaServiceSelectGroup: document.getElementById('cpa-service-select-group'),
|
cpaServiceSelectGroup: document.getElementById('cpa-service-select-group'),
|
||||||
cpaServiceSelect: document.getElementById('cpa-service-select')
|
cpaServiceCheckboxes: document.getElementById('cpa-service-checkboxes'),
|
||||||
|
autoUploadSub2api: document.getElementById('auto-upload-sub2api'),
|
||||||
|
sub2apiServiceSelectGroup: document.getElementById('sub2api-service-select-group'),
|
||||||
|
sub2apiServiceCheckboxes: document.getElementById('sub2api-service-checkboxes'),
|
||||||
|
autoUploadTm: document.getElementById('auto-upload-tm'),
|
||||||
|
tmServiceSelectGroup: document.getElementById('tm-service-select-group'),
|
||||||
|
tmServiceCheckboxes: document.getElementById('tm-service-checkboxes'),
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
@@ -96,48 +102,54 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
startAccountsPolling();
|
startAccountsPolling();
|
||||||
initVisibilityReconnect();
|
initVisibilityReconnect();
|
||||||
restoreActiveTask();
|
restoreActiveTask();
|
||||||
checkCpaEnabled();
|
initAutoUploadOptions();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 检查 CPA 是否启用,未启用则禁用复选框;同时加载 CPA 服务列表
|
// 初始化注册后自动操作选项(CPA / Sub2API / TM)
|
||||||
async function checkCpaEnabled() {
|
async function initAutoUploadOptions() {
|
||||||
if (!elements.autoUploadCpa) return;
|
await Promise.all([
|
||||||
// 加载 CPA 服务列表,列表为空则禁用复选框
|
loadServiceCheckboxes('cpa', '/cpa-services?enabled=true', elements.cpaServiceCheckboxes, elements.autoUploadCpa, elements.cpaServiceSelectGroup),
|
||||||
await loadCpaServiceOptions();
|
loadServiceCheckboxes('sub2api', '/sub2api-services?enabled=true', elements.sub2apiServiceCheckboxes, elements.autoUploadSub2api, elements.sub2apiServiceSelectGroup),
|
||||||
try {
|
loadServiceCheckboxes('tm', '/tm-services?enabled=true', elements.tmServiceCheckboxes, elements.autoUploadTm, elements.tmServiceSelectGroup),
|
||||||
const services = await api.get('/cpa-services?enabled=true');
|
]);
|
||||||
if (!services || services.length === 0) {
|
|
||||||
elements.autoUploadCpa.disabled = true;
|
|
||||||
elements.autoUploadCpa.title = '请先在设置中添加 CPA 服务';
|
|
||||||
const label = elements.autoUploadCpa.closest('label');
|
|
||||||
if (label) label.style.opacity = '0.5';
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
elements.autoUploadCpa.disabled = true;
|
|
||||||
}
|
|
||||||
// 复选框联动显示/隐藏服务选择器
|
|
||||||
if (elements.autoUploadCpa) {
|
|
||||||
elements.autoUploadCpa.addEventListener('change', () => {
|
|
||||||
if (elements.cpaServiceSelectGroup) {
|
|
||||||
elements.cpaServiceSelectGroup.style.display =
|
|
||||||
elements.autoUploadCpa.checked ? 'block' : 'none';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCpaServiceOptions() {
|
// 通用:加载服务 checkbox 列表,并处理联动
|
||||||
if (!elements.cpaServiceSelect) return;
|
async function loadServiceCheckboxes(type, apiPath, container, checkbox, selectGroup) {
|
||||||
|
if (!checkbox || !container) return;
|
||||||
|
let services = [];
|
||||||
try {
|
try {
|
||||||
const services = await api.get('/cpa-services?enabled=true');
|
services = await api.get(apiPath);
|
||||||
const defaultOpt = '<option value="">自动选择(第一个启用的服务)</option>';
|
} catch (e) {}
|
||||||
const opts = services.map(s =>
|
|
||||||
`<option value="${s.id}">${s.name.replace(/</g,'<')}</option>`
|
if (!services || services.length === 0) {
|
||||||
).join('');
|
checkbox.disabled = true;
|
||||||
elements.cpaServiceSelect.innerHTML = defaultOpt + opts;
|
checkbox.title = '请先在设置中添加对应服务';
|
||||||
} catch (e) {
|
const label = checkbox.closest('label');
|
||||||
// 加载失败静默处理,保持默认选项
|
if (label) label.style.opacity = '0.5';
|
||||||
|
if (container) container.innerHTML = '<div style="color:var(--text-muted);font-size:0.8rem;">暂无可用服务</div>';
|
||||||
|
} else {
|
||||||
|
container.innerHTML = services.map(s => `
|
||||||
|
<label style="display:flex;align-items:center;gap:6px;cursor:pointer;">
|
||||||
|
<input type="checkbox" class="upload-svc-cb upload-svc-${type}" value="${s.id}" checked>
|
||||||
|
<span style="font-size:0.85rem;">${escapeHtml(s.name)}</span>
|
||||||
|
</label>
|
||||||
|
`).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 联动显示/隐藏服务选择区
|
||||||
|
checkbox.addEventListener('change', () => {
|
||||||
|
if (selectGroup) selectGroup.style.display = checkbox.checked ? 'block' : 'none';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取选中的服务 ID 列表
|
||||||
|
function getCheckedServiceIds(type) {
|
||||||
|
const ids = [];
|
||||||
|
document.querySelectorAll(`.upload-svc-${type}:checked`).forEach(cb => {
|
||||||
|
ids.push(parseInt(cb.value));
|
||||||
|
});
|
||||||
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 事件监听
|
// 事件监听
|
||||||
@@ -382,12 +394,13 @@ async function handleStartRegistration(e) {
|
|||||||
// 构建请求数据(代理从设置中自动获取)
|
// 构建请求数据(代理从设置中自动获取)
|
||||||
const requestData = {
|
const requestData = {
|
||||||
email_service_type: emailServiceType,
|
email_service_type: emailServiceType,
|
||||||
auto_upload_cpa: elements.autoUploadCpa ? elements.autoUploadCpa.checked : false
|
auto_upload_cpa: elements.autoUploadCpa ? elements.autoUploadCpa.checked : false,
|
||||||
|
cpa_service_ids: elements.autoUploadCpa && elements.autoUploadCpa.checked ? getCheckedServiceIds('cpa') : [],
|
||||||
|
auto_upload_sub2api: elements.autoUploadSub2api ? elements.autoUploadSub2api.checked : false,
|
||||||
|
sub2api_service_ids: elements.autoUploadSub2api && elements.autoUploadSub2api.checked ? getCheckedServiceIds('sub2api') : [],
|
||||||
|
auto_upload_tm: elements.autoUploadTm ? elements.autoUploadTm.checked : false,
|
||||||
|
tm_service_ids: elements.autoUploadTm && elements.autoUploadTm.checked ? getCheckedServiceIds('tm') : [],
|
||||||
};
|
};
|
||||||
// 带上指定 CPA 服务
|
|
||||||
if (requestData.auto_upload_cpa && elements.cpaServiceSelect && elements.cpaServiceSelect.value) {
|
|
||||||
requestData.cpa_service_id = parseInt(elements.cpaServiceSelect.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果选择了数据库中的服务,传递 service_id
|
// 如果选择了数据库中的服务,传递 service_id
|
||||||
if (serviceId && serviceId !== 'default') {
|
if (serviceId && serviceId !== 'default') {
|
||||||
@@ -1085,7 +1098,12 @@ async function handleOutlookBatchRegistration() {
|
|||||||
interval_max: intervalMax,
|
interval_max: intervalMax,
|
||||||
concurrency: Math.min(50, Math.max(1, concurrency)),
|
concurrency: Math.min(50, Math.max(1, concurrency)),
|
||||||
mode: mode,
|
mode: mode,
|
||||||
auto_upload_cpa: elements.autoUploadCpa ? elements.autoUploadCpa.checked : false
|
auto_upload_cpa: elements.autoUploadCpa ? elements.autoUploadCpa.checked : false,
|
||||||
|
cpa_service_ids: elements.autoUploadCpa && elements.autoUploadCpa.checked ? getCheckedServiceIds('cpa') : [],
|
||||||
|
auto_upload_sub2api: elements.autoUploadSub2api ? elements.autoUploadSub2api.checked : false,
|
||||||
|
sub2api_service_ids: elements.autoUploadSub2api && elements.autoUploadSub2api.checked ? getCheckedServiceIds('sub2api') : [],
|
||||||
|
auto_upload_tm: elements.autoUploadTm ? elements.autoUploadTm.checked : false,
|
||||||
|
tm_service_ids: elements.autoUploadTm && elements.autoUploadTm.checked ? getCheckedServiceIds('tm') : [],
|
||||||
};
|
};
|
||||||
|
|
||||||
addLog('info', `[系统] 正在启动 Outlook 批量注册 (${selectedIds.length} 个账户)...`);
|
addLog('info', `[系统] 正在启动 Outlook 批量注册 (${selectedIds.length} 个账户)...`);
|
||||||
|
|||||||
+25
-5
@@ -224,15 +224,35 @@
|
|||||||
|
|
||||||
<div class="form-group" id="auto-upload-group">
|
<div class="form-group" id="auto-upload-group">
|
||||||
<label style="font-weight: 500; margin-bottom: var(--spacing-xs); display: block;">注册后自动操作</label>
|
<label style="font-weight: 500; margin-bottom: var(--spacing-xs); display: block;">注册后自动操作</label>
|
||||||
|
|
||||||
|
<!-- CPA -->
|
||||||
<label style="display: flex; align-items: center; gap: var(--spacing-sm); cursor: pointer;">
|
<label style="display: flex; align-items: center; gap: var(--spacing-sm); cursor: pointer;">
|
||||||
<input type="checkbox" id="auto-upload-cpa">
|
<input type="checkbox" id="auto-upload-cpa">
|
||||||
<span>上传到 CPA</span>
|
<span>上传到 CPA</span>
|
||||||
</label>
|
</label>
|
||||||
<div id="cpa-service-select-group" style="display:none; margin-top: 8px; padding-left: 4px;">
|
<div id="cpa-service-select-group" style="display:none; margin-top: 6px; margin-bottom: 8px; padding-left: 4px;">
|
||||||
<label style="font-size:0.85rem; color:var(--text-muted); margin-bottom:4px; display:block;">选择 CPA 服务</label>
|
<label style="font-size:0.85rem; color:var(--text-muted); margin-bottom:4px; display:block;">选择 CPA 服务(可多选)</label>
|
||||||
<select id="cpa-service-select" style="width:100%; padding:6px 10px; border:1px solid var(--border); border-radius:6px; background:var(--surface); color:var(--text-primary); font-size:0.9rem;">
|
<div id="cpa-service-checkboxes" style="display:flex; flex-direction:column; gap:4px; max-height:120px; overflow-y:auto; border:1px solid var(--border); border-radius:6px; padding:6px;"></div>
|
||||||
<option value="">使用全局配置</option>
|
</div>
|
||||||
</select>
|
|
||||||
|
<!-- Sub2API -->
|
||||||
|
<label style="display: flex; align-items: center; gap: var(--spacing-sm); cursor: pointer; margin-top: 6px;">
|
||||||
|
<input type="checkbox" id="auto-upload-sub2api">
|
||||||
|
<span>上传到 Sub2API</span>
|
||||||
|
</label>
|
||||||
|
<div id="sub2api-service-select-group" style="display:none; margin-top: 6px; margin-bottom: 8px; padding-left: 4px;">
|
||||||
|
<label style="font-size:0.85rem; color:var(--text-muted); margin-bottom:4px; display:block;">选择 Sub2API 服务(可多选)</label>
|
||||||
|
<div id="sub2api-service-checkboxes" style="display:flex; flex-direction:column; gap:4px; max-height:120px; overflow-y:auto; border:1px solid var(--border); border-radius:6px; padding:6px;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Team Manager -->
|
||||||
|
<label style="display: flex; align-items: center; gap: var(--spacing-sm); cursor: pointer; margin-top: 6px;">
|
||||||
|
<input type="checkbox" id="auto-upload-tm">
|
||||||
|
<span>上传到 Team Manager</span>
|
||||||
|
</label>
|
||||||
|
<div id="tm-service-select-group" style="display:none; margin-top: 6px; padding-left: 4px;">
|
||||||
|
<label style="font-size:0.85rem; color:var(--text-muted); margin-bottom:4px; display:block;">选择 TM 服务(可多选)</label>
|
||||||
|
<div id="tm-service-checkboxes" style="display:flex; flex-direction:column; gap:4px; max-height:120px; overflow-y:auto; border:1px solid var(--border); border-radius:6px; padding:6px;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user