mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-07-12 16:01:22 +08:00
Merge branch 'master' into master
This commit is contained in:
33
README.md
33
README.md
@@ -10,7 +10,9 @@
|
|||||||
- **多邮箱服务支持**
|
- **多邮箱服务支持**
|
||||||
- Tempmail.lol(临时邮箱,无需配置)
|
- Tempmail.lol(临时邮箱,无需配置)
|
||||||
- Outlook(IMAP + XOAUTH2,支持批量导入)
|
- Outlook(IMAP + XOAUTH2,支持批量导入)
|
||||||
- 自定义域名(REST API)
|
- 自定义域名(两种子类型)
|
||||||
|
- **MoeMail**:标准 REST API,配置 API 地址 + API 密钥
|
||||||
|
- **TempMail**:自部署 Cloudflare Worker 临时邮箱,配置 Worker 地址 + Admin 密码
|
||||||
|
|
||||||
- **注册模式**
|
- **注册模式**
|
||||||
- 单次注册
|
- 单次注册
|
||||||
@@ -40,12 +42,21 @@
|
|||||||
- 单个账号导出为独立 `.json` 文件
|
- 单个账号导出为独立 `.json` 文件
|
||||||
- 多个账号打包为 `.zip`,每个账号一个独立文件
|
- 多个账号打包为 `.zip`,每个账号一个独立文件
|
||||||
- CPA 上传(Codex Protocol API,直连不走代理)
|
- CPA 上传(Codex Protocol API,直连不走代理)
|
||||||
|
- 订阅状态管理(手动标记 / 自动检测 plus/team)
|
||||||
|
- Team Manager 上传(直连不走代理)
|
||||||
|
|
||||||
|
- **支付升级**
|
||||||
|
- 为账号生成 ChatGPT Plus 或 Team 订阅支付链接
|
||||||
|
- 后端命令行以无痕模式自动打开 Chrome/Edge
|
||||||
|
- Team 套餐支持自定义工作区名称、座位数、计费周期
|
||||||
|
|
||||||
- **系统设置**
|
- **系统设置**
|
||||||
- 代理配置(静态 + 动态)
|
- 代理配置(静态 + 动态)
|
||||||
- Outlook OAuth 参数
|
- Outlook OAuth 参数
|
||||||
- 注册参数(超时、重试、密码长度等)
|
- 注册参数(超时、重试、密码长度等)
|
||||||
- 验证码等待配置
|
- 验证码等待配置
|
||||||
|
- CPA 上传配置
|
||||||
|
- Team Manager 配置(API URL + API Key)
|
||||||
- 数据库管理(备份、清理)
|
- 数据库管理(备份、清理)
|
||||||
- 支持远程 PostgreSQL
|
- 支持远程 PostgreSQL
|
||||||
|
|
||||||
@@ -113,7 +124,7 @@ codex-register-v2/
|
|||||||
├── build.sh # Linux/macOS 打包脚本
|
├── build.sh # Linux/macOS 打包脚本
|
||||||
├── src/
|
├── src/
|
||||||
│ ├── config/ # 配置管理(Pydantic Settings)
|
│ ├── config/ # 配置管理(Pydantic Settings)
|
||||||
│ ├── core/ # 核心功能(注册引擎、HTTP 客户端、CPA 上传)
|
│ ├── core/ # 核心功能(注册引擎、HTTP 客户端、CPA 上传、支付、TM 上传)
|
||||||
│ ├── database/ # 数据库(SQLAlchemy + SQLite)
|
│ ├── database/ # 数据库(SQLAlchemy + SQLite)
|
||||||
│ ├── services/ # 邮箱服务实现
|
│ ├── services/ # 邮箱服务实现
|
||||||
│ └── web/ # FastAPI Web 应用
|
│ └── web/ # FastAPI Web 应用
|
||||||
@@ -177,6 +188,17 @@ codex-register-v2/
|
|||||||
| POST | `/api/accounts/{id}/upload-cpa` | 上传到 CPA |
|
| POST | `/api/accounts/{id}/upload-cpa` | 上传到 CPA |
|
||||||
| POST | `/api/accounts/batch-upload-cpa` | 批量上传到 CPA |
|
| POST | `/api/accounts/batch-upload-cpa` | 批量上传到 CPA |
|
||||||
|
|
||||||
|
### 支付升级
|
||||||
|
|
||||||
|
| 方法 | 路径 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| POST | `/api/payment/generate-link` | 生成 Plus/Team 支付链接 |
|
||||||
|
| POST | `/api/payment/open-incognito` | 后端无痕模式打开浏览器 |
|
||||||
|
| POST | `/api/payment/accounts/{id}/mark-subscription` | 手动标记订阅类型 |
|
||||||
|
| POST | `/api/payment/accounts/batch-check-subscription` | 批量检测订阅状态 |
|
||||||
|
| POST | `/api/payment/accounts/{id}/upload-tm` | 上传单账号到 Team Manager |
|
||||||
|
| POST | `/api/payment/accounts/batch-upload-tm` | 批量上传到 Team Manager |
|
||||||
|
|
||||||
### 邮箱服务
|
### 邮箱服务
|
||||||
|
|
||||||
| 方法 | 路径 | 说明 |
|
| 方法 | 路径 | 说明 |
|
||||||
@@ -198,6 +220,8 @@ codex-register-v2/
|
|||||||
| POST | `/api/settings/dynamic-proxy` | 更新动态代理设置 |
|
| POST | `/api/settings/dynamic-proxy` | 更新动态代理设置 |
|
||||||
| POST | `/api/settings/cpa` | 更新 CPA 设置 |
|
| POST | `/api/settings/cpa` | 更新 CPA 设置 |
|
||||||
| POST | `/api/settings/cpa/test` | 测试 CPA 连接 |
|
| POST | `/api/settings/cpa/test` | 测试 CPA 连接 |
|
||||||
|
| GET/POST | `/api/settings/team-manager` | Team Manager 设置 |
|
||||||
|
| POST | `/api/settings/team-manager/test` | 测试 Team Manager 连接 |
|
||||||
| GET | `/api/settings/database` | 数据库信息 |
|
| GET | `/api/settings/database` | 数据库信息 |
|
||||||
|
|
||||||
### WebSocket
|
### WebSocket
|
||||||
@@ -266,6 +290,11 @@ docker-compose build --no-cache
|
|||||||
- 代理设置优先级:动态代理 > 代理列表(随机) > 静态默认代理
|
- 代理设置优先级:动态代理 > 代理列表(随机) > 静态默认代理
|
||||||
- 注册时自动随机生成用户名和生日(年龄范围 18-45 岁)
|
- 注册时自动随机生成用户名和生日(年龄范围 18-45 岁)
|
||||||
- CPA 上传始终直连,不经过代理
|
- CPA 上传始终直连,不经过代理
|
||||||
|
- Team Manager 上传始终直连,不经过代理
|
||||||
|
- 支付链接生成使用账号 access_token 鉴权,走全局代理配置
|
||||||
|
- 无痕浏览器优先使用 playwright(注入 cookie 直达支付页);未安装时降级为系统 Chrome/Edge 无痕模式
|
||||||
|
- 安装完整支付功能:`pip install playwright && playwright install chromium`(可选)
|
||||||
|
- 订阅状态自动检测调用 `chatgpt.com/backend-api/me`,走全局代理
|
||||||
- 批量注册并发数上限为 50,线程池大小已相应调整
|
- 批量注册并发数上限为 50,线程池大小已相应调整
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "codex-register-v2"
|
name = "codex-register-v2"
|
||||||
version = "0.1.0"
|
version = "1.0.4"
|
||||||
description = "OpenAI/Codex CLI 自动注册系统"
|
description = "OpenAI 自动注册系统 v2"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"curl-cffi>=0.14.0",
|
"curl-cffi>=0.14.0",
|
||||||
@@ -22,6 +22,9 @@ dev = [
|
|||||||
"pytest>=7.0.0",
|
"pytest>=7.0.0",
|
||||||
"httpx>=0.24.0",
|
"httpx>=0.24.0",
|
||||||
]
|
]
|
||||||
|
payment = [
|
||||||
|
"playwright>=1.40.0",
|
||||||
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
codex-webui = "webui:main"
|
codex-webui = "webui:main"
|
||||||
|
|||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@@ -34,6 +34,7 @@ class EmailServiceType(str, Enum):
|
|||||||
TEMPMAIL = "tempmail"
|
TEMPMAIL = "tempmail"
|
||||||
OUTLOOK = "outlook"
|
OUTLOOK = "outlook"
|
||||||
CUSTOM_DOMAIN = "custom_domain"
|
CUSTOM_DOMAIN = "custom_domain"
|
||||||
|
TEMP_MAIL = "temp_mail"
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
@@ -301,6 +301,27 @@ SETTING_DEFINITIONS: Dict[str, SettingDefinition] = {
|
|||||||
is_secret=True
|
is_secret=True
|
||||||
),
|
),
|
||||||
|
|
||||||
|
# Team Manager 配置
|
||||||
|
"tm_enabled": SettingDefinition(
|
||||||
|
db_key="tm.enabled",
|
||||||
|
default_value=False,
|
||||||
|
category=SettingCategory.GENERAL,
|
||||||
|
description="是否启用 Team Manager 上传"
|
||||||
|
),
|
||||||
|
"tm_api_url": SettingDefinition(
|
||||||
|
db_key="tm.api_url",
|
||||||
|
default_value="",
|
||||||
|
category=SettingCategory.GENERAL,
|
||||||
|
description="Team Manager API 地址"
|
||||||
|
),
|
||||||
|
"tm_api_key": SettingDefinition(
|
||||||
|
db_key="tm.api_key",
|
||||||
|
default_value="",
|
||||||
|
category=SettingCategory.GENERAL,
|
||||||
|
description="Team Manager API Key",
|
||||||
|
is_secret=True
|
||||||
|
),
|
||||||
|
|
||||||
# CPA 上传配置
|
# CPA 上传配置
|
||||||
"cpa_enabled": SettingDefinition(
|
"cpa_enabled": SettingDefinition(
|
||||||
db_key="cpa.enabled",
|
db_key="cpa.enabled",
|
||||||
@@ -382,6 +403,7 @@ SETTING_TYPES: Dict[str, Type] = {
|
|||||||
"email_service_priority": dict,
|
"email_service_priority": dict,
|
||||||
"tempmail_timeout": int,
|
"tempmail_timeout": int,
|
||||||
"tempmail_max_retries": int,
|
"tempmail_max_retries": int,
|
||||||
|
"tm_enabled": bool,
|
||||||
"cpa_enabled": bool,
|
"cpa_enabled": bool,
|
||||||
"email_code_timeout": int,
|
"email_code_timeout": int,
|
||||||
"email_code_poll_interval": int,
|
"email_code_poll_interval": int,
|
||||||
@@ -642,6 +664,11 @@ class Settings(BaseModel):
|
|||||||
# 安全配置
|
# 安全配置
|
||||||
encryption_key: SecretStr = SecretStr("your-encryption-key-change-in-production")
|
encryption_key: SecretStr = SecretStr("your-encryption-key-change-in-production")
|
||||||
|
|
||||||
|
# Team Manager 配置
|
||||||
|
tm_enabled: bool = False
|
||||||
|
tm_api_url: str = ""
|
||||||
|
tm_api_key: Optional[SecretStr] = None
|
||||||
|
|
||||||
# CPA 上传配置
|
# CPA 上传配置
|
||||||
cpa_enabled: bool = False
|
cpa_enabled: bool = False
|
||||||
cpa_api_url: str = ""
|
cpa_api_url: str = ""
|
||||||
|
|||||||
261
src/core/payment.py
Normal file
261
src/core/payment.py
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
"""
|
||||||
|
支付核心逻辑 — 生成 Plus/Team 支付链接、无痕打开浏览器、检测订阅状态
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from curl_cffi import requests as cffi_requests
|
||||||
|
|
||||||
|
from ..database.models import Account
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
PAYMENT_CHECKOUT_URL = "https://chatgpt.com/backend-api/payments/checkout"
|
||||||
|
TEAM_CHECKOUT_BASE_URL = "https://chatgpt.com/checkout/openai_llc/"
|
||||||
|
|
||||||
|
|
||||||
|
def _build_proxies(proxy: Optional[str]) -> Optional[dict]:
|
||||||
|
if proxy:
|
||||||
|
return {"http": proxy, "https": proxy}
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
_COUNTRY_CURRENCY_MAP = {
|
||||||
|
"SG": "SGD",
|
||||||
|
"US": "USD",
|
||||||
|
"TR": "TRY",
|
||||||
|
"JP": "JPY",
|
||||||
|
"HK": "HKD",
|
||||||
|
"GB": "GBP",
|
||||||
|
"EU": "EUR",
|
||||||
|
"AU": "AUD",
|
||||||
|
"CA": "CAD",
|
||||||
|
"IN": "INR",
|
||||||
|
"BR": "BRL",
|
||||||
|
"MX": "MXN",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_oai_did(cookies_str: str) -> Optional[str]:
|
||||||
|
"""从 cookie 字符串中提取 oai-device-id"""
|
||||||
|
for part in cookies_str.split(";"):
|
||||||
|
part = part.strip()
|
||||||
|
if part.startswith("oai-did="):
|
||||||
|
return part[len("oai-did="):].strip()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_cookie_str(cookies_str: str, domain: str) -> list:
|
||||||
|
"""将 'key=val; key2=val2' 格式解析为 Playwright cookie 列表"""
|
||||||
|
cookies = []
|
||||||
|
for part in cookies_str.split(";"):
|
||||||
|
part = part.strip()
|
||||||
|
if "=" not in part:
|
||||||
|
continue
|
||||||
|
name, _, value = part.partition("=")
|
||||||
|
cookies.append({
|
||||||
|
"name": name.strip(),
|
||||||
|
"value": value.strip(),
|
||||||
|
"domain": domain,
|
||||||
|
"path": "/",
|
||||||
|
})
|
||||||
|
return cookies
|
||||||
|
|
||||||
|
|
||||||
|
def _open_url_system_browser(url: str) -> bool:
|
||||||
|
"""回退方案:调用系统浏览器以无痕模式打开"""
|
||||||
|
platform = sys.platform
|
||||||
|
try:
|
||||||
|
if platform == "win32":
|
||||||
|
for browser, flag in [("chrome", "--incognito"), ("msedge", "--inprivate")]:
|
||||||
|
try:
|
||||||
|
subprocess.Popen(f'start {browser} {flag} "{url}"', shell=True)
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
elif platform == "darwin":
|
||||||
|
subprocess.Popen(["open", "-a", "Google Chrome", "--args", "--incognito", url])
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
for binary in ["google-chrome", "chromium-browser", "chromium"]:
|
||||||
|
try:
|
||||||
|
subprocess.Popen([binary, "--incognito", url])
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"系统浏览器无痕打开失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def generate_plus_link(
|
||||||
|
account: Account,
|
||||||
|
proxy: Optional[str] = None,
|
||||||
|
country: str = "SG",
|
||||||
|
) -> str:
|
||||||
|
"""生成 Plus 支付链接(后端携带账号 cookie 发请求)"""
|
||||||
|
if not account.access_token:
|
||||||
|
raise ValueError("账号缺少 access_token")
|
||||||
|
|
||||||
|
currency = _COUNTRY_CURRENCY_MAP.get(country, "USD")
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {account.access_token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"oai-language": "zh-CN",
|
||||||
|
}
|
||||||
|
if account.cookies:
|
||||||
|
headers["cookie"] = account.cookies
|
||||||
|
oai_did = _extract_oai_did(account.cookies)
|
||||||
|
if oai_did:
|
||||||
|
headers["oai-device-id"] = oai_did
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"plan_name": "chatgptplusplan",
|
||||||
|
"billing_details": {"country": country, "currency": currency},
|
||||||
|
"promo_campaign": {
|
||||||
|
"promo_campaign_id": "plus-1-month-free",
|
||||||
|
"is_coupon_from_query_param": False,
|
||||||
|
},
|
||||||
|
"checkout_ui_mode": "custom",
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = cffi_requests.post(
|
||||||
|
PAYMENT_CHECKOUT_URL,
|
||||||
|
headers=headers,
|
||||||
|
json=payload,
|
||||||
|
proxies=_build_proxies(proxy),
|
||||||
|
timeout=30,
|
||||||
|
impersonate="chrome110",
|
||||||
|
)
|
||||||
|
resp.raise_for_status()
|
||||||
|
data = resp.json()
|
||||||
|
if "checkout_session_id" in data:
|
||||||
|
return TEAM_CHECKOUT_BASE_URL + data["checkout_session_id"]
|
||||||
|
raise ValueError(data.get("detail", "API 未返回 checkout_session_id"))
|
||||||
|
|
||||||
|
|
||||||
|
def generate_team_link(
|
||||||
|
account: Account,
|
||||||
|
workspace_name: str = "MyTeam",
|
||||||
|
price_interval: str = "month",
|
||||||
|
seat_quantity: int = 5,
|
||||||
|
proxy: Optional[str] = None,
|
||||||
|
country: str = "SG",
|
||||||
|
) -> str:
|
||||||
|
"""生成 Team 支付链接(后端携带账号 cookie 发请求)"""
|
||||||
|
if not account.access_token:
|
||||||
|
raise ValueError("账号缺少 access_token")
|
||||||
|
|
||||||
|
currency = _COUNTRY_CURRENCY_MAP.get(country, "USD")
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {account.access_token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"oai-language": "zh-CN",
|
||||||
|
}
|
||||||
|
if account.cookies:
|
||||||
|
headers["cookie"] = account.cookies
|
||||||
|
oai_did = _extract_oai_did(account.cookies)
|
||||||
|
if oai_did:
|
||||||
|
headers["oai-device-id"] = oai_did
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"plan_name": "chatgptteamplan",
|
||||||
|
"team_plan_data": {
|
||||||
|
"workspace_name": workspace_name,
|
||||||
|
"price_interval": price_interval,
|
||||||
|
"seat_quantity": seat_quantity,
|
||||||
|
},
|
||||||
|
"billing_details": {"country": country, "currency": currency},
|
||||||
|
"promo_campaign": {
|
||||||
|
"promo_campaign_id": "team-1-month-free",
|
||||||
|
"is_coupon_from_query_param": True,
|
||||||
|
},
|
||||||
|
"cancel_url": "https://chatgpt.com/#pricing",
|
||||||
|
"checkout_ui_mode": "custom",
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = cffi_requests.post(
|
||||||
|
PAYMENT_CHECKOUT_URL,
|
||||||
|
headers=headers,
|
||||||
|
json=payload,
|
||||||
|
proxies=_build_proxies(proxy),
|
||||||
|
timeout=30,
|
||||||
|
impersonate="chrome110",
|
||||||
|
)
|
||||||
|
resp.raise_for_status()
|
||||||
|
data = resp.json()
|
||||||
|
if "checkout_session_id" in data:
|
||||||
|
return TEAM_CHECKOUT_BASE_URL + data["checkout_session_id"]
|
||||||
|
raise ValueError(data.get("detail", "API 未返回 checkout_session_id"))
|
||||||
|
|
||||||
|
|
||||||
|
def open_url_incognito(url: str, cookies_str: Optional[str] = None) -> bool:
|
||||||
|
"""用 Playwright 以无痕模式打开 URL,可注入 cookie"""
|
||||||
|
import threading
|
||||||
|
try:
|
||||||
|
from playwright.sync_api import sync_playwright
|
||||||
|
except ImportError:
|
||||||
|
logger.warning("playwright 未安装,回退到系统浏览器")
|
||||||
|
return _open_url_system_browser(url)
|
||||||
|
|
||||||
|
def _launch():
|
||||||
|
try:
|
||||||
|
with sync_playwright() as p:
|
||||||
|
browser = p.chromium.launch(headless=False, args=["--incognito"])
|
||||||
|
ctx = browser.new_context()
|
||||||
|
if cookies_str:
|
||||||
|
ctx.add_cookies(_parse_cookie_str(cookies_str, "chatgpt.com"))
|
||||||
|
page = ctx.new_page()
|
||||||
|
page.goto(url)
|
||||||
|
# 保持窗口打开直到用户关闭
|
||||||
|
page.wait_for_timeout(300_000) # 最多等待 5 分钟
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Playwright 无痕打开失败: {e}")
|
||||||
|
|
||||||
|
threading.Thread(target=_launch, daemon=True).start()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def check_subscription_status(account: Account, proxy: Optional[str] = None) -> str:
|
||||||
|
"""
|
||||||
|
检测账号当前订阅状态。
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
'free' / 'plus' / 'team'
|
||||||
|
"""
|
||||||
|
if not account.access_token:
|
||||||
|
raise ValueError("账号缺少 access_token")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {account.access_token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = cffi_requests.get(
|
||||||
|
"https://chatgpt.com/backend-api/me",
|
||||||
|
headers=headers,
|
||||||
|
proxies=_build_proxies(proxy),
|
||||||
|
timeout=20,
|
||||||
|
impersonate="chrome110",
|
||||||
|
)
|
||||||
|
resp.raise_for_status()
|
||||||
|
data = resp.json()
|
||||||
|
|
||||||
|
# 解析订阅类型
|
||||||
|
plan = data.get("plan_type") or ""
|
||||||
|
if "team" in plan.lower():
|
||||||
|
return "team"
|
||||||
|
if "plus" in plan.lower():
|
||||||
|
return "plus"
|
||||||
|
|
||||||
|
# 尝试从 orgs 或 workspace 信息判断
|
||||||
|
orgs = data.get("orgs", {}).get("data", [])
|
||||||
|
for org in orgs:
|
||||||
|
settings_ = org.get("settings", {})
|
||||||
|
if settings_.get("workspace_plan_type") in ("team", "enterprise"):
|
||||||
|
return "team"
|
||||||
|
|
||||||
|
return "free"
|
||||||
158
src/core/team_manager.py
Normal file
158
src/core/team_manager.py
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
"""
|
||||||
|
Team Manager 上传功能
|
||||||
|
参照 CPA 上传模式,直连不走代理
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import List, Tuple
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from curl_cffi import requests as cffi_requests
|
||||||
|
|
||||||
|
from ..database.session import get_db
|
||||||
|
from ..database.models import Account
|
||||||
|
from ..config.settings import get_settings
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def upload_to_team_manager(
|
||||||
|
account: Account,
|
||||||
|
api_url: str,
|
||||||
|
api_key: str,
|
||||||
|
) -> Tuple[bool, str]:
|
||||||
|
"""
|
||||||
|
上传单账号到 Team Manager(直连,不走代理)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(成功标志, 消息)
|
||||||
|
"""
|
||||||
|
if not api_url:
|
||||||
|
return False, "Team Manager API URL 未配置"
|
||||||
|
if not api_key:
|
||||||
|
return False, "Team Manager API Key 未配置"
|
||||||
|
if not account.access_token:
|
||||||
|
return False, "账号缺少 access_token"
|
||||||
|
|
||||||
|
url = api_url.rstrip("/") + "/api/accounts/import"
|
||||||
|
headers = {
|
||||||
|
"X-API-Key": api_key,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
payload = {
|
||||||
|
"import_type": "single",
|
||||||
|
"email": account.email,
|
||||||
|
"access_token": account.access_token or "",
|
||||||
|
"session_token": account.session_token or "",
|
||||||
|
"refresh_token": account.refresh_token or "",
|
||||||
|
"client_id": account.client_id or "",
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = cffi_requests.post(
|
||||||
|
url,
|
||||||
|
headers=headers,
|
||||||
|
json=payload,
|
||||||
|
proxies=None,
|
||||||
|
timeout=30,
|
||||||
|
impersonate="chrome110",
|
||||||
|
)
|
||||||
|
if resp.status_code in (200, 201):
|
||||||
|
return True, "上传成功"
|
||||||
|
error_msg = f"上传失败: HTTP {resp.status_code}"
|
||||||
|
try:
|
||||||
|
detail = resp.json()
|
||||||
|
if isinstance(detail, dict):
|
||||||
|
error_msg = detail.get("message", error_msg)
|
||||||
|
except Exception:
|
||||||
|
error_msg = f"{error_msg} - {resp.text[:200]}"
|
||||||
|
return False, error_msg
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Team Manager 上传异常: {e}")
|
||||||
|
return False, f"上传异常: {str(e)}"
|
||||||
|
|
||||||
|
|
||||||
|
def batch_upload_to_team_manager(
|
||||||
|
account_ids: List[int],
|
||||||
|
api_url: str,
|
||||||
|
api_key: str,
|
||||||
|
) -> dict:
|
||||||
|
"""
|
||||||
|
批量上传账号到 Team Manager
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
包含成功/失败统计和详情的字典
|
||||||
|
"""
|
||||||
|
results = {
|
||||||
|
"success_count": 0,
|
||||||
|
"failed_count": 0,
|
||||||
|
"skipped_count": 0,
|
||||||
|
"details": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
with get_db() as db:
|
||||||
|
for account_id in account_ids:
|
||||||
|
account = db.query(Account).filter(Account.id == account_id).first()
|
||||||
|
if not account:
|
||||||
|
results["failed_count"] += 1
|
||||||
|
results["details"].append(
|
||||||
|
{"id": account_id, "email": None, "success": False, "error": "账号不存在"}
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not account.access_token:
|
||||||
|
results["skipped_count"] += 1
|
||||||
|
results["details"].append(
|
||||||
|
{"id": account_id, "email": account.email, "success": False, "error": "缺少 Token"}
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
success, message = upload_to_team_manager(account, api_url, api_key)
|
||||||
|
if success:
|
||||||
|
results["success_count"] += 1
|
||||||
|
results["details"].append(
|
||||||
|
{"id": account_id, "email": account.email, "success": True, "message": message}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
results["failed_count"] += 1
|
||||||
|
results["details"].append(
|
||||||
|
{"id": account_id, "email": account.email, "success": False, "error": message}
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def test_team_manager_connection(api_url: str, api_key: str) -> Tuple[bool, str]:
|
||||||
|
"""
|
||||||
|
测试 Team Manager 连接(直连)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(成功标志, 消息)
|
||||||
|
"""
|
||||||
|
if not api_url:
|
||||||
|
return False, "API URL 不能为空"
|
||||||
|
if not api_key:
|
||||||
|
return False, "API Key 不能为空"
|
||||||
|
|
||||||
|
url = api_url.rstrip("/") + "/api/accounts/import"
|
||||||
|
headers = {"X-API-Key": api_key}
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = cffi_requests.options(
|
||||||
|
url,
|
||||||
|
headers=headers,
|
||||||
|
proxies=None,
|
||||||
|
timeout=10,
|
||||||
|
impersonate="chrome110",
|
||||||
|
)
|
||||||
|
if resp.status_code in (200, 204, 401, 403, 405):
|
||||||
|
if resp.status_code == 401:
|
||||||
|
return False, "连接成功,但 API Key 无效"
|
||||||
|
return True, "Team Manager 连接测试成功"
|
||||||
|
return False, f"服务器返回异常状态码: {resp.status_code}"
|
||||||
|
except cffi_requests.exceptions.ConnectionError as e:
|
||||||
|
return False, f"无法连接到服务器: {str(e)}"
|
||||||
|
except cffi_requests.exceptions.Timeout:
|
||||||
|
return False, "连接超时,请检查网络配置"
|
||||||
|
except Exception as e:
|
||||||
|
return False, f"连接测试失败: {str(e)}"
|
||||||
@@ -53,6 +53,9 @@ class Account(Base):
|
|||||||
cpa_uploaded = Column(Boolean, default=False) # 是否已上传到 CPA
|
cpa_uploaded = Column(Boolean, default=False) # 是否已上传到 CPA
|
||||||
cpa_uploaded_at = Column(DateTime) # 上传时间
|
cpa_uploaded_at = Column(DateTime) # 上传时间
|
||||||
source = Column(String(20), default='register') # 'register' 或 'login',区分账号来源
|
source = Column(String(20), default='register') # 'register' 或 'login',区分账号来源
|
||||||
|
subscription_type = Column(String(20)) # None / 'plus' / 'team'
|
||||||
|
subscription_at = Column(DateTime) # 订阅开通时间
|
||||||
|
cookies = Column(Text) # 完整 cookie 字符串,用于支付请求
|
||||||
created_at = Column(DateTime, default=datetime.utcnow)
|
created_at = Column(DateTime, default=datetime.utcnow)
|
||||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||||
|
|
||||||
@@ -74,6 +77,8 @@ class Account(Base):
|
|||||||
'cpa_uploaded': self.cpa_uploaded,
|
'cpa_uploaded': self.cpa_uploaded,
|
||||||
'cpa_uploaded_at': self.cpa_uploaded_at.isoformat() if self.cpa_uploaded_at else None,
|
'cpa_uploaded_at': self.cpa_uploaded_at.isoformat() if self.cpa_uploaded_at else None,
|
||||||
'source': self.source,
|
'source': self.source,
|
||||||
|
'subscription_type': self.subscription_type,
|
||||||
|
'subscription_at': self.subscription_at.isoformat() if self.subscription_at else None,
|
||||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||||
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ class DatabaseSessionManager:
|
|||||||
("accounts", "cpa_uploaded", "BOOLEAN DEFAULT 0"),
|
("accounts", "cpa_uploaded", "BOOLEAN DEFAULT 0"),
|
||||||
("accounts", "cpa_uploaded_at", "DATETIME"),
|
("accounts", "cpa_uploaded_at", "DATETIME"),
|
||||||
("accounts", "source", "VARCHAR(20) DEFAULT 'register'"),
|
("accounts", "source", "VARCHAR(20) DEFAULT 'register'"),
|
||||||
|
("accounts", "subscription_type", "VARCHAR(20)"),
|
||||||
|
("accounts", "subscription_at", "DATETIME"),
|
||||||
|
("accounts", "cookies", "TEXT"),
|
||||||
]
|
]
|
||||||
|
|
||||||
with self.engine.connect() as conn:
|
with self.engine.connect() as conn:
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ from .base import (
|
|||||||
from .tempmail import TempmailService
|
from .tempmail import TempmailService
|
||||||
from .outlook import OutlookService
|
from .outlook import OutlookService
|
||||||
from .custom_domain import CustomDomainEmailService
|
from .custom_domain import CustomDomainEmailService
|
||||||
|
from .temp_mail import TempMailService
|
||||||
|
|
||||||
# 注册服务
|
# 注册服务
|
||||||
EmailServiceFactory.register(EmailServiceType.TEMPMAIL, TempmailService)
|
EmailServiceFactory.register(EmailServiceType.TEMPMAIL, TempmailService)
|
||||||
EmailServiceFactory.register(EmailServiceType.OUTLOOK, OutlookService)
|
EmailServiceFactory.register(EmailServiceType.OUTLOOK, OutlookService)
|
||||||
EmailServiceFactory.register(EmailServiceType.CUSTOM_DOMAIN, CustomDomainEmailService)
|
EmailServiceFactory.register(EmailServiceType.CUSTOM_DOMAIN, CustomDomainEmailService)
|
||||||
|
EmailServiceFactory.register(EmailServiceType.TEMP_MAIL, TempMailService)
|
||||||
|
|
||||||
# 导出 Outlook 模块的额外内容
|
# 导出 Outlook 模块的额外内容
|
||||||
from .outlook.base import (
|
from .outlook.base import (
|
||||||
@@ -47,6 +49,7 @@ __all__ = [
|
|||||||
'TempmailService',
|
'TempmailService',
|
||||||
'OutlookService',
|
'OutlookService',
|
||||||
'CustomDomainEmailService',
|
'CustomDomainEmailService',
|
||||||
|
'TempMailService',
|
||||||
# Outlook 模块
|
# Outlook 模块
|
||||||
'ProviderType',
|
'ProviderType',
|
||||||
'EmailMessage',
|
'EmailMessage',
|
||||||
|
|||||||
@@ -326,8 +326,9 @@ class CustomDomainEmailService(BaseEmailService):
|
|||||||
if "openai" not in sender and "openai" not in content.lower():
|
if "openai" not in sender and "openai" not in content.lower():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 提取验证码
|
# 提取验证码 过滤掉邮箱
|
||||||
match = re.search(pattern, content)
|
email_pattern = r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"
|
||||||
|
match = re.search(pattern, re.sub(email_pattern, "", content))
|
||||||
if match:
|
if match:
|
||||||
code = match.group(1)
|
code = match.group(1)
|
||||||
logger.info(f"从自定义域名邮箱 {email} 找到验证码: {code}")
|
logger.info(f"从自定义域名邮箱 {email} 找到验证码: {code}")
|
||||||
|
|||||||
268
src/services/temp_mail.py
Normal file
268
src/services/temp_mail.py
Normal file
@@ -0,0 +1,268 @@
|
|||||||
|
"""
|
||||||
|
Temp-Mail 邮箱服务实现
|
||||||
|
基于自部署 Cloudflare Worker 临时邮箱服务
|
||||||
|
接口文档参见 plan/temp-mail.md
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
from typing import Optional, Dict, Any
|
||||||
|
|
||||||
|
from .base import BaseEmailService, EmailServiceError, EmailServiceType
|
||||||
|
from ..core.http_client import HTTPClient, RequestConfig
|
||||||
|
from ..config.constants import OTP_CODE_PATTERN
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class TempMailService(BaseEmailService):
|
||||||
|
"""
|
||||||
|
Temp-Mail 邮箱服务
|
||||||
|
基于自部署 Cloudflare Worker 的临时邮箱,admin 模式管理邮箱
|
||||||
|
不走代理,不使用 requests 库
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, config: Dict[str, Any] = None, name: str = None):
|
||||||
|
"""
|
||||||
|
初始化 TempMail 服务
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config: 配置字典,支持以下键:
|
||||||
|
- base_url: Worker 域名地址,如 https://mail.example.com (必需)
|
||||||
|
- admin_password: Admin 密码,对应 x-admin-auth header (必需)
|
||||||
|
- domain: 邮箱域名,如 example.com (必需)
|
||||||
|
- enable_prefix: 是否启用前缀,默认 True
|
||||||
|
- timeout: 请求超时时间,默认 30
|
||||||
|
- max_retries: 最大重试次数,默认 3
|
||||||
|
name: 服务名称
|
||||||
|
"""
|
||||||
|
super().__init__(EmailServiceType.TEMP_MAIL, name)
|
||||||
|
|
||||||
|
required_keys = ["base_url", "admin_password", "domain"]
|
||||||
|
missing_keys = [key for key in required_keys if not (config or {}).get(key)]
|
||||||
|
if missing_keys:
|
||||||
|
raise ValueError(f"缺少必需配置: {missing_keys}")
|
||||||
|
|
||||||
|
default_config = {
|
||||||
|
"enable_prefix": True,
|
||||||
|
"timeout": 30,
|
||||||
|
"max_retries": 3,
|
||||||
|
}
|
||||||
|
self.config = {**default_config, **(config or {})}
|
||||||
|
|
||||||
|
# 不走代理,proxy_url=None
|
||||||
|
http_config = RequestConfig(
|
||||||
|
timeout=self.config["timeout"],
|
||||||
|
max_retries=self.config["max_retries"],
|
||||||
|
)
|
||||||
|
self.http_client = HTTPClient(proxy_url=None, config=http_config)
|
||||||
|
|
||||||
|
# 邮箱缓存:email -> {jwt, address}
|
||||||
|
self._email_cache: Dict[str, Dict[str, Any]] = {}
|
||||||
|
|
||||||
|
def _admin_headers(self) -> Dict[str, str]:
|
||||||
|
"""构造 admin 请求头"""
|
||||||
|
return {
|
||||||
|
"x-admin-auth": self.config["admin_password"],
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
def _make_request(self, method: str, path: str, **kwargs) -> Any:
|
||||||
|
"""
|
||||||
|
发送请求并返回 JSON 数据
|
||||||
|
|
||||||
|
Args:
|
||||||
|
method: HTTP 方法
|
||||||
|
path: 请求路径(以 / 开头)
|
||||||
|
**kwargs: 传递给 http_client.request 的额外参数
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
响应 JSON 数据
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
EmailServiceError: 请求失败
|
||||||
|
"""
|
||||||
|
base_url = self.config["base_url"].rstrip("/")
|
||||||
|
url = f"{base_url}{path}"
|
||||||
|
|
||||||
|
# 合并默认 admin headers
|
||||||
|
kwargs.setdefault("headers", {})
|
||||||
|
for k, v in self._admin_headers().items():
|
||||||
|
kwargs["headers"].setdefault(k, v)
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = self.http_client.request(method, url, **kwargs)
|
||||||
|
|
||||||
|
if response.status_code >= 400:
|
||||||
|
error_msg = f"请求失败: {response.status_code}"
|
||||||
|
try:
|
||||||
|
error_data = response.json()
|
||||||
|
error_msg = f"{error_msg} - {error_data}"
|
||||||
|
except Exception:
|
||||||
|
error_msg = f"{error_msg} - {response.text[:200]}"
|
||||||
|
self.update_status(False, EmailServiceError(error_msg))
|
||||||
|
raise EmailServiceError(error_msg)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return response.json()
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
return {"raw_response": response.text}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.update_status(False, e)
|
||||||
|
if isinstance(e, EmailServiceError):
|
||||||
|
raise
|
||||||
|
raise EmailServiceError(f"请求失败: {method} {path} - {e}")
|
||||||
|
|
||||||
|
def create_email(self, config: Dict[str, Any] = None) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
通过 admin API 创建临时邮箱
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
包含邮箱信息的字典:
|
||||||
|
- email: 邮箱地址
|
||||||
|
- jwt: 用户级 JWT token
|
||||||
|
- service_id: 同 email(用作标识)
|
||||||
|
"""
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
# 生成随机邮箱名
|
||||||
|
letters = ''.join(random.choices(string.ascii_lowercase, k=5))
|
||||||
|
digits = ''.join(random.choices(string.digits, k=random.randint(1, 3)))
|
||||||
|
suffix = ''.join(random.choices(string.ascii_lowercase, k=random.randint(1, 3)))
|
||||||
|
name = letters + digits + suffix
|
||||||
|
|
||||||
|
domain = self.config["domain"]
|
||||||
|
enable_prefix = self.config.get("enable_prefix", True)
|
||||||
|
|
||||||
|
body = {
|
||||||
|
"enablePrefix": enable_prefix,
|
||||||
|
"name": name,
|
||||||
|
"domain": domain,
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = self._make_request("POST", "/admin/new_address", json=body)
|
||||||
|
|
||||||
|
address = response.get("address", "").strip()
|
||||||
|
jwt = response.get("jwt", "").strip()
|
||||||
|
|
||||||
|
if not address:
|
||||||
|
raise EmailServiceError(f"API 返回数据不完整: {response}")
|
||||||
|
|
||||||
|
email_info = {
|
||||||
|
"email": address,
|
||||||
|
"jwt": jwt,
|
||||||
|
"service_id": address,
|
||||||
|
"id": address,
|
||||||
|
"created_at": time.time(),
|
||||||
|
}
|
||||||
|
|
||||||
|
# 缓存 jwt,供获取验证码时使用
|
||||||
|
self._email_cache[address] = email_info
|
||||||
|
|
||||||
|
logger.info(f"成功创建 TempMail 邮箱: {address}")
|
||||||
|
self.update_status(True)
|
||||||
|
return email_info
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.update_status(False, e)
|
||||||
|
if isinstance(e, EmailServiceError):
|
||||||
|
raise
|
||||||
|
raise EmailServiceError(f"创建邮箱失败: {e}")
|
||||||
|
|
||||||
|
def get_verification_code(
|
||||||
|
self,
|
||||||
|
email: str,
|
||||||
|
email_id: str = None,
|
||||||
|
timeout: int = 120,
|
||||||
|
pattern: str = OTP_CODE_PATTERN,
|
||||||
|
otp_sent_at: Optional[float] = None,
|
||||||
|
) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
从 TempMail 邮箱获取验证码
|
||||||
|
|
||||||
|
Args:
|
||||||
|
email: 邮箱地址
|
||||||
|
email_id: 未使用,保留接口兼容
|
||||||
|
timeout: 超时时间(秒)
|
||||||
|
pattern: 验证码正则
|
||||||
|
otp_sent_at: OTP 发送时间戳(暂未使用)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
验证码字符串,超时返回 None
|
||||||
|
"""
|
||||||
|
logger.info(f"正在从 TempMail 邮箱 {email} 获取验证码...")
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
seen_mail_ids: set = set()
|
||||||
|
|
||||||
|
while time.time() - start_time < timeout:
|
||||||
|
try:
|
||||||
|
# 使用 admin API 查询邮件,通过 address 参数过滤
|
||||||
|
response = self._make_request(
|
||||||
|
"GET",
|
||||||
|
"/admin/mails",
|
||||||
|
params={"limit": 20, "offset": 0, "address": email},
|
||||||
|
)
|
||||||
|
|
||||||
|
# admin/mails 返回格式: {"results": [...], "total": N}
|
||||||
|
mails = response.get("results", [])
|
||||||
|
if not isinstance(mails, list):
|
||||||
|
time.sleep(3)
|
||||||
|
continue
|
||||||
|
|
||||||
|
for mail in mails:
|
||||||
|
mail_id = mail.get("id")
|
||||||
|
if not mail_id or mail_id in seen_mail_ids:
|
||||||
|
continue
|
||||||
|
|
||||||
|
seen_mail_ids.add(mail_id)
|
||||||
|
|
||||||
|
sender = str(mail.get("source", "")).lower()
|
||||||
|
subject = str(mail.get("subject", ""))
|
||||||
|
body_text = str(mail.get("text", "") or mail.get("html", "") or "")
|
||||||
|
|
||||||
|
# 去除简单 HTML 标签
|
||||||
|
body_clean = re.sub(r"<[^>]+>", " ", body_text)
|
||||||
|
|
||||||
|
content = f"{sender} {subject} {body_clean}"
|
||||||
|
|
||||||
|
# 只处理 OpenAI 邮件
|
||||||
|
if "openai" not in sender and "openai" not in content.lower():
|
||||||
|
continue
|
||||||
|
|
||||||
|
match = re.search(pattern, content)
|
||||||
|
if match:
|
||||||
|
code = match.group(1)
|
||||||
|
logger.info(f"从 TempMail 邮箱 {email} 找到验证码: {code}")
|
||||||
|
self.update_status(True)
|
||||||
|
return code
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"检查 TempMail 邮件时出错: {e}")
|
||||||
|
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
logger.warning(f"等待 TempMail 验证码超时: {email}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def check_health(self) -> bool:
|
||||||
|
"""检查服务健康状态"""
|
||||||
|
try:
|
||||||
|
self._make_request(
|
||||||
|
"GET",
|
||||||
|
"/admin/mails",
|
||||||
|
params={"limit": 1, "offset": 0},
|
||||||
|
)
|
||||||
|
self.update_status(True)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"TempMail 健康检查失败: {e}")
|
||||||
|
self.update_status(False, e)
|
||||||
|
return False
|
||||||
@@ -151,6 +151,11 @@ def create_app() -> FastAPI:
|
|||||||
return _redirect_to_login(request)
|
return _redirect_to_login(request)
|
||||||
return templates.TemplateResponse("settings.html", {"request": request})
|
return templates.TemplateResponse("settings.html", {"request": request})
|
||||||
|
|
||||||
|
@app.get("/payment", response_class=HTMLResponse)
|
||||||
|
async def payment_page(request: Request):
|
||||||
|
"""支付页面"""
|
||||||
|
return templates.TemplateResponse("payment.html", {"request": request})
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
async def startup_event():
|
async def startup_event():
|
||||||
"""应用启动事件"""
|
"""应用启动事件"""
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from .accounts import router as accounts_router
|
|||||||
from .registration import router as registration_router
|
from .registration import router as registration_router
|
||||||
from .settings import router as settings_router
|
from .settings import router as settings_router
|
||||||
from .email_services import router as email_services_router
|
from .email_services import router as email_services_router
|
||||||
|
from .payment import router as payment_router
|
||||||
|
|
||||||
api_router = APIRouter()
|
api_router = APIRouter()
|
||||||
|
|
||||||
@@ -16,3 +17,4 @@ api_router.include_router(accounts_router, prefix="/accounts", tags=["accounts"]
|
|||||||
api_router.include_router(registration_router, prefix="/registration", tags=["registration"])
|
api_router.include_router(registration_router, prefix="/registration", tags=["registration"])
|
||||||
api_router.include_router(settings_router, prefix="/settings", tags=["settings"])
|
api_router.include_router(settings_router, prefix="/settings", tags=["settings"])
|
||||||
api_router.include_router(email_services_router, prefix="/email-services", tags=["email-services"])
|
api_router.include_router(email_services_router, prefix="/email-services", tags=["email-services"])
|
||||||
|
api_router.include_router(payment_router, prefix="/payment", tags=["payment"])
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class AccountResponse(BaseModel):
|
|||||||
proxy_used: Optional[str] = None
|
proxy_used: Optional[str] = None
|
||||||
cpa_uploaded: bool = False
|
cpa_uploaded: bool = False
|
||||||
cpa_uploaded_at: Optional[str] = None
|
cpa_uploaded_at: Optional[str] = None
|
||||||
|
cookies: Optional[str] = None
|
||||||
created_at: Optional[str] = None
|
created_at: Optional[str] = None
|
||||||
updated_at: Optional[str] = None
|
updated_at: Optional[str] = None
|
||||||
|
|
||||||
@@ -56,11 +57,16 @@ class AccountUpdateRequest(BaseModel):
|
|||||||
"""账号更新请求"""
|
"""账号更新请求"""
|
||||||
status: Optional[str] = None
|
status: Optional[str] = None
|
||||||
metadata: Optional[dict] = None
|
metadata: Optional[dict] = None
|
||||||
|
cookies: Optional[str] = None # 完整 cookie 字符串,用于支付请求
|
||||||
|
|
||||||
|
|
||||||
class BatchDeleteRequest(BaseModel):
|
class BatchDeleteRequest(BaseModel):
|
||||||
"""批量删除请求"""
|
"""批量删除请求"""
|
||||||
ids: List[int]
|
ids: List[int] = []
|
||||||
|
select_all: bool = False
|
||||||
|
status_filter: Optional[str] = None
|
||||||
|
email_service_filter: Optional[str] = None
|
||||||
|
search_filter: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class BatchUpdateRequest(BaseModel):
|
class BatchUpdateRequest(BaseModel):
|
||||||
@@ -71,6 +77,30 @@ class BatchUpdateRequest(BaseModel):
|
|||||||
|
|
||||||
# ============== Helper Functions ==============
|
# ============== Helper Functions ==============
|
||||||
|
|
||||||
|
def resolve_account_ids(
|
||||||
|
db,
|
||||||
|
ids: List[int],
|
||||||
|
select_all: bool = False,
|
||||||
|
status_filter: Optional[str] = None,
|
||||||
|
email_service_filter: Optional[str] = None,
|
||||||
|
search_filter: Optional[str] = None,
|
||||||
|
) -> List[int]:
|
||||||
|
"""当 select_all=True 时查询全部符合条件的 ID,否则直接返回传入的 ids"""
|
||||||
|
if not select_all:
|
||||||
|
return ids
|
||||||
|
query = db.query(Account.id)
|
||||||
|
if status_filter:
|
||||||
|
query = query.filter(Account.status == status_filter)
|
||||||
|
if email_service_filter:
|
||||||
|
query = query.filter(Account.email_service == email_service_filter)
|
||||||
|
if search_filter:
|
||||||
|
pattern = f"%{search_filter}%"
|
||||||
|
query = query.filter(
|
||||||
|
(Account.email.ilike(pattern)) | (Account.account_id.ilike(pattern))
|
||||||
|
)
|
||||||
|
return [row[0] for row in query.all()]
|
||||||
|
|
||||||
|
|
||||||
def account_to_response(account: Account) -> AccountResponse:
|
def account_to_response(account: Account) -> AccountResponse:
|
||||||
"""转换 Account 模型为响应模型"""
|
"""转换 Account 模型为响应模型"""
|
||||||
return AccountResponse(
|
return AccountResponse(
|
||||||
@@ -88,6 +118,7 @@ def account_to_response(account: Account) -> AccountResponse:
|
|||||||
proxy_used=account.proxy_used,
|
proxy_used=account.proxy_used,
|
||||||
cpa_uploaded=account.cpa_uploaded or False,
|
cpa_uploaded=account.cpa_uploaded or False,
|
||||||
cpa_uploaded_at=account.cpa_uploaded_at.isoformat() if account.cpa_uploaded_at else None,
|
cpa_uploaded_at=account.cpa_uploaded_at.isoformat() if account.cpa_uploaded_at else None,
|
||||||
|
cookies=account.cookies,
|
||||||
created_at=account.created_at.isoformat() if account.created_at else None,
|
created_at=account.created_at.isoformat() if account.created_at else None,
|
||||||
updated_at=account.updated_at.isoformat() if account.updated_at else None,
|
updated_at=account.updated_at.isoformat() if account.updated_at else None,
|
||||||
)
|
)
|
||||||
@@ -162,9 +193,9 @@ async def get_account_tokens(account_id: int):
|
|||||||
return {
|
return {
|
||||||
"id": account.id,
|
"id": account.id,
|
||||||
"email": account.email,
|
"email": account.email,
|
||||||
"access_token": account.access_token[:50] + "..." if account.access_token else None,
|
"access_token": account.access_token,
|
||||||
"refresh_token": account.refresh_token[:50] + "..." if account.refresh_token else None,
|
"refresh_token": account.refresh_token,
|
||||||
"id_token": account.id_token[:50] + "..." if account.id_token else None,
|
"id_token": account.id_token,
|
||||||
"has_tokens": bool(account.access_token and account.refresh_token),
|
"has_tokens": bool(account.access_token and account.refresh_token),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,10 +219,24 @@ async def update_account(account_id: int, request: AccountUpdateRequest):
|
|||||||
current_metadata.update(request.metadata)
|
current_metadata.update(request.metadata)
|
||||||
update_data["metadata"] = current_metadata
|
update_data["metadata"] = current_metadata
|
||||||
|
|
||||||
|
if request.cookies is not None:
|
||||||
|
# 留空则清空,非空则更新
|
||||||
|
update_data["cookies"] = request.cookies or None
|
||||||
|
|
||||||
account = crud.update_account(db, account_id, **update_data)
|
account = crud.update_account(db, account_id, **update_data)
|
||||||
return account_to_response(account)
|
return account_to_response(account)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{account_id}/cookies")
|
||||||
|
async def get_account_cookies(account_id: int):
|
||||||
|
"""获取账号的 cookie 字符串(仅供支付使用)"""
|
||||||
|
with get_db() as db:
|
||||||
|
account = crud.get_account_by_id(db, account_id)
|
||||||
|
if not account:
|
||||||
|
raise HTTPException(status_code=404, detail="账号不存在")
|
||||||
|
return {"account_id": account_id, "cookies": account.cookies or ""}
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{account_id}")
|
@router.delete("/{account_id}")
|
||||||
async def delete_account(account_id: int):
|
async def delete_account(account_id: int):
|
||||||
"""删除单个账号"""
|
"""删除单个账号"""
|
||||||
@@ -208,10 +253,14 @@ async def delete_account(account_id: int):
|
|||||||
async def batch_delete_accounts(request: BatchDeleteRequest):
|
async def batch_delete_accounts(request: BatchDeleteRequest):
|
||||||
"""批量删除账号"""
|
"""批量删除账号"""
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
deleted_count = 0
|
deleted_count = 0
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
for account_id in request.ids:
|
for account_id in ids:
|
||||||
try:
|
try:
|
||||||
account = crud.get_account_by_id(db, account_id)
|
account = crud.get_account_by_id(db, account_id)
|
||||||
if account:
|
if account:
|
||||||
@@ -255,14 +304,22 @@ async def batch_update_accounts(request: BatchUpdateRequest):
|
|||||||
|
|
||||||
class BatchExportRequest(BaseModel):
|
class BatchExportRequest(BaseModel):
|
||||||
"""批量导出请求"""
|
"""批量导出请求"""
|
||||||
ids: List[int]
|
ids: List[int] = []
|
||||||
|
select_all: bool = False
|
||||||
|
status_filter: Optional[str] = None
|
||||||
|
email_service_filter: Optional[str] = None
|
||||||
|
search_filter: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@router.post("/export/json")
|
@router.post("/export/json")
|
||||||
async def export_accounts_json(request: BatchExportRequest):
|
async def export_accounts_json(request: BatchExportRequest):
|
||||||
"""导出账号为 JSON 格式"""
|
"""导出账号为 JSON 格式"""
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
accounts = db.query(Account).filter(Account.id.in_(request.ids)).all()
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
accounts = db.query(Account).filter(Account.id.in_(ids)).all()
|
||||||
|
|
||||||
export_data = []
|
export_data = []
|
||||||
for acc in accounts:
|
for acc in accounts:
|
||||||
@@ -304,7 +361,11 @@ async def export_accounts_csv(request: BatchExportRequest):
|
|||||||
import io
|
import io
|
||||||
|
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
accounts = db.query(Account).filter(Account.id.in_(request.ids)).all()
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
accounts = db.query(Account).filter(Account.id.in_(ids)).all()
|
||||||
|
|
||||||
# 创建 CSV 内容
|
# 创建 CSV 内容
|
||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
@@ -349,6 +410,82 @@ async def export_accounts_csv(request: BatchExportRequest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/export/sub2api")
|
||||||
|
async def export_accounts_sub2api(request: BatchExportRequest):
|
||||||
|
"""导出账号为 Sub2Api 格式(每个账号单独一个 JSON 文件,多个打包为 ZIP)"""
|
||||||
|
import io
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
def make_sub2api_json(acc) -> dict:
|
||||||
|
expires_at = int(acc.expires_at.timestamp()) if acc.expires_at else 0
|
||||||
|
return {
|
||||||
|
"proxies": [],
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"name": acc.email,
|
||||||
|
"platform": "openai",
|
||||||
|
"type": "oauth",
|
||||||
|
"credentials": {
|
||||||
|
"access_token": acc.access_token or "",
|
||||||
|
"chatgpt_account_id": acc.account_id or "",
|
||||||
|
"chatgpt_user_id": "",
|
||||||
|
"client_id": acc.client_id or "",
|
||||||
|
"expires_at": expires_at,
|
||||||
|
"expires_in": 863999,
|
||||||
|
"model_mapping": {
|
||||||
|
"gpt-5.1": "gpt-5.1",
|
||||||
|
"gpt-5.1-codex": "gpt-5.1-codex",
|
||||||
|
"gpt-5.1-codex-max": "gpt-5.1-codex-max",
|
||||||
|
"gpt-5.1-codex-mini": "gpt-5.1-codex-mini",
|
||||||
|
"gpt-5.2": "gpt-5.2",
|
||||||
|
"gpt-5.2-codex": "gpt-5.2-codex"
|
||||||
|
},
|
||||||
|
"organization_id": acc.workspace_id or "",
|
||||||
|
"refresh_token": acc.refresh_token or ""
|
||||||
|
},
|
||||||
|
"extra": {},
|
||||||
|
"concurrency": 10,
|
||||||
|
"priority": 1,
|
||||||
|
"rate_multiplier": 1,
|
||||||
|
"auto_pause_on_expired": True
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
with get_db() as db:
|
||||||
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
accounts = db.query(Account).filter(Account.id.in_(ids)).all()
|
||||||
|
|
||||||
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
|
||||||
|
if len(accounts) == 1:
|
||||||
|
acc = accounts[0]
|
||||||
|
content = json.dumps(make_sub2api_json(acc), ensure_ascii=False, indent=2)
|
||||||
|
filename = f"{acc.email}_sub2api.json"
|
||||||
|
return StreamingResponse(
|
||||||
|
iter([content]),
|
||||||
|
media_type="application/json",
|
||||||
|
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||||
|
)
|
||||||
|
|
||||||
|
zip_buffer = io.BytesIO()
|
||||||
|
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||||
|
for acc in accounts:
|
||||||
|
content = json.dumps(make_sub2api_json(acc), ensure_ascii=False, indent=2)
|
||||||
|
zf.writestr(f"{acc.email}_sub2api.json", content)
|
||||||
|
|
||||||
|
zip_buffer.seek(0)
|
||||||
|
zip_filename = f"sub2api_tokens_{timestamp}.zip"
|
||||||
|
return StreamingResponse(
|
||||||
|
zip_buffer,
|
||||||
|
media_type="application/zip",
|
||||||
|
headers={"Content-Disposition": f"attachment; filename={zip_filename}"}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/export/cpa")
|
@router.post("/export/cpa")
|
||||||
async def export_accounts_cpa(request: BatchExportRequest):
|
async def export_accounts_cpa(request: BatchExportRequest):
|
||||||
"""导出账号为 CPA Token JSON 格式(每个账号单独一个 JSON 文件,打包为 ZIP)"""
|
"""导出账号为 CPA Token JSON 格式(每个账号单独一个 JSON 文件,打包为 ZIP)"""
|
||||||
@@ -357,7 +494,11 @@ async def export_accounts_cpa(request: BatchExportRequest):
|
|||||||
from ...core.cpa_upload import generate_token_json
|
from ...core.cpa_upload import generate_token_json
|
||||||
|
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
accounts = db.query(Account).filter(Account.id.in_(request.ids)).all()
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
accounts = db.query(Account).filter(Account.id.in_(ids)).all()
|
||||||
|
|
||||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
|
||||||
@@ -427,8 +568,12 @@ class TokenRefreshRequest(BaseModel):
|
|||||||
|
|
||||||
class BatchRefreshRequest(BaseModel):
|
class BatchRefreshRequest(BaseModel):
|
||||||
"""批量刷新请求"""
|
"""批量刷新请求"""
|
||||||
ids: List[int]
|
ids: List[int] = []
|
||||||
proxy: Optional[str] = None
|
proxy: Optional[str] = None
|
||||||
|
select_all: bool = False
|
||||||
|
status_filter: Optional[str] = None
|
||||||
|
email_service_filter: Optional[str] = None
|
||||||
|
search_filter: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class TokenValidateRequest(BaseModel):
|
class TokenValidateRequest(BaseModel):
|
||||||
@@ -438,8 +583,12 @@ class TokenValidateRequest(BaseModel):
|
|||||||
|
|
||||||
class BatchValidateRequest(BaseModel):
|
class BatchValidateRequest(BaseModel):
|
||||||
"""批量验证请求"""
|
"""批量验证请求"""
|
||||||
ids: List[int]
|
ids: List[int] = []
|
||||||
proxy: Optional[str] = None
|
proxy: Optional[str] = None
|
||||||
|
select_all: bool = False
|
||||||
|
status_filter: Optional[str] = None
|
||||||
|
email_service_filter: Optional[str] = None
|
||||||
|
search_filter: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{account_id}/refresh")
|
@router.post("/{account_id}/refresh")
|
||||||
@@ -478,7 +627,13 @@ async def batch_refresh_tokens(request: BatchRefreshRequest, background_tasks: B
|
|||||||
"errors": []
|
"errors": []
|
||||||
}
|
}
|
||||||
|
|
||||||
for account_id in request.ids:
|
with get_db() as db:
|
||||||
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
|
||||||
|
for account_id in ids:
|
||||||
try:
|
try:
|
||||||
result = do_refresh(account_id, proxy)
|
result = do_refresh(account_id, proxy)
|
||||||
if result.success:
|
if result.success:
|
||||||
@@ -523,7 +678,13 @@ async def batch_validate_tokens(request: BatchValidateRequest):
|
|||||||
"details": []
|
"details": []
|
||||||
}
|
}
|
||||||
|
|
||||||
for account_id in request.ids:
|
with get_db() as db:
|
||||||
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
|
||||||
|
for account_id in ids:
|
||||||
try:
|
try:
|
||||||
is_valid, error = do_validate(account_id, proxy)
|
is_valid, error = do_validate(account_id, proxy)
|
||||||
results["details"].append({
|
results["details"].append({
|
||||||
@@ -555,8 +716,12 @@ class CPAUploadRequest(BaseModel):
|
|||||||
|
|
||||||
class BatchCPAUploadRequest(BaseModel):
|
class BatchCPAUploadRequest(BaseModel):
|
||||||
"""批量 CPA 上传请求"""
|
"""批量 CPA 上传请求"""
|
||||||
ids: List[int]
|
ids: List[int] = []
|
||||||
proxy: Optional[str] = None
|
proxy: Optional[str] = None
|
||||||
|
select_all: bool = False
|
||||||
|
status_filter: Optional[str] = None
|
||||||
|
email_service_filter: Optional[str] = None
|
||||||
|
search_filter: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{account_id}/upload-cpa")
|
@router.post("/{account_id}/upload-cpa")
|
||||||
@@ -609,6 +774,12 @@ async def batch_upload_accounts_to_cpa(request: BatchCPAUploadRequest):
|
|||||||
# 使用传入的代理或全局代理配置
|
# 使用传入的代理或全局代理配置
|
||||||
proxy = request.proxy if request.proxy else get_settings().proxy_url
|
proxy = request.proxy if request.proxy else get_settings().proxy_url
|
||||||
|
|
||||||
results = batch_upload_to_cpa(request.ids, proxy)
|
with get_db() as db:
|
||||||
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
|
||||||
|
results = batch_upload_to_cpa(ids, proxy)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ async def get_email_services_stats():
|
|||||||
stats = {
|
stats = {
|
||||||
'outlook_count': 0,
|
'outlook_count': 0,
|
||||||
'custom_count': 0,
|
'custom_count': 0,
|
||||||
|
'temp_mail_count': 0,
|
||||||
'tempmail_available': True, # 临时邮箱始终可用
|
'tempmail_available': True, # 临时邮箱始终可用
|
||||||
'enabled_count': enabled_count
|
'enabled_count': enabled_count
|
||||||
}
|
}
|
||||||
@@ -152,6 +153,8 @@ async def get_email_services_stats():
|
|||||||
stats['outlook_count'] = count
|
stats['outlook_count'] = count
|
||||||
elif service_type == 'custom_domain':
|
elif service_type == 'custom_domain':
|
||||||
stats['custom_count'] = count
|
stats['custom_count'] = count
|
||||||
|
elif service_type == 'temp_mail':
|
||||||
|
stats['temp_mail_count'] = count
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
@@ -190,6 +193,17 @@ async def get_service_types():
|
|||||||
{"name": "api_key", "label": "API Key", "required": True},
|
{"name": "api_key", "label": "API Key", "required": True},
|
||||||
{"name": "default_domain", "label": "默认域名", "required": False},
|
{"name": "default_domain", "label": "默认域名", "required": False},
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "temp_mail",
|
||||||
|
"label": "Temp-Mail(自部署)",
|
||||||
|
"description": "自部署 Cloudflare Worker 临时邮箱,admin 模式管理",
|
||||||
|
"config_fields": [
|
||||||
|
{"name": "base_url", "label": "Worker 地址", "required": True, "placeholder": "https://mail.example.com"},
|
||||||
|
{"name": "admin_password", "label": "Admin 密码", "required": True, "secret": True},
|
||||||
|
{"name": "domain", "label": "邮箱域名", "required": True, "placeholder": "example.com"},
|
||||||
|
{"name": "enable_prefix", "label": "启用前缀", "required": False, "default": True},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
236
src/web/routes/payment.py
Normal file
236
src/web/routes/payment.py
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
"""
|
||||||
|
支付相关 API 路由
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import Optional, List
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from ...database.session import get_db
|
||||||
|
from ...database.models import Account
|
||||||
|
from ...config.settings import get_settings
|
||||||
|
from .accounts import resolve_account_ids
|
||||||
|
from ...core.payment import (
|
||||||
|
generate_plus_link,
|
||||||
|
generate_team_link,
|
||||||
|
open_url_incognito,
|
||||||
|
check_subscription_status,
|
||||||
|
)
|
||||||
|
from ...core.team_manager import (
|
||||||
|
upload_to_team_manager,
|
||||||
|
batch_upload_to_team_manager,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
# ============== Pydantic Models ==============
|
||||||
|
|
||||||
|
class GenerateLinkRequest(BaseModel):
|
||||||
|
account_id: int
|
||||||
|
plan_type: str # 'plus' or 'team'
|
||||||
|
workspace_name: str = "MyTeam"
|
||||||
|
price_interval: str = "month"
|
||||||
|
seat_quantity: int = 5
|
||||||
|
proxy: Optional[str] = None
|
||||||
|
auto_open: bool = False # 生成后是否自动无痕打开
|
||||||
|
country: str = "SG" # 计费国家,决定货币 # 生成后是否自动无痕打开
|
||||||
|
|
||||||
|
|
||||||
|
class OpenIncognitoRequest(BaseModel):
|
||||||
|
url: str
|
||||||
|
account_id: Optional[int] = None # 可选,用于注入账号 cookie
|
||||||
|
|
||||||
|
|
||||||
|
class MarkSubscriptionRequest(BaseModel):
|
||||||
|
subscription_type: str # 'free' / 'plus' / 'team'
|
||||||
|
|
||||||
|
|
||||||
|
class BatchCheckSubscriptionRequest(BaseModel):
|
||||||
|
ids: List[int] = []
|
||||||
|
proxy: Optional[str] = None
|
||||||
|
select_all: bool = False
|
||||||
|
status_filter: Optional[str] = None
|
||||||
|
email_service_filter: Optional[str] = None
|
||||||
|
search_filter: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class UploadTMRequest(BaseModel):
|
||||||
|
proxy: Optional[str] = None # 保留,TM 上传不走代理
|
||||||
|
|
||||||
|
|
||||||
|
class BatchUploadTMRequest(BaseModel):
|
||||||
|
ids: List[int] = []
|
||||||
|
select_all: bool = False
|
||||||
|
status_filter: Optional[str] = None
|
||||||
|
email_service_filter: Optional[str] = None
|
||||||
|
search_filter: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
# ============== 支付链接生成 ==============
|
||||||
|
|
||||||
|
@router.post("/generate-link")
|
||||||
|
def generate_payment_link(request: GenerateLinkRequest):
|
||||||
|
"""生成 Plus 或 Team 支付链接,可选自动无痕打开"""
|
||||||
|
with get_db() as db:
|
||||||
|
account = db.query(Account).filter(Account.id == request.account_id).first()
|
||||||
|
if not account:
|
||||||
|
raise HTTPException(status_code=404, detail="账号不存在")
|
||||||
|
|
||||||
|
proxy = request.proxy or get_settings().proxy_url
|
||||||
|
|
||||||
|
try:
|
||||||
|
if request.plan_type == "plus":
|
||||||
|
link = generate_plus_link(account, proxy, country=request.country)
|
||||||
|
elif request.plan_type == "team":
|
||||||
|
link = generate_team_link(
|
||||||
|
account,
|
||||||
|
workspace_name=request.workspace_name,
|
||||||
|
price_interval=request.price_interval,
|
||||||
|
seat_quantity=request.seat_quantity,
|
||||||
|
proxy=proxy,
|
||||||
|
country=request.country,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=400, detail="plan_type 必须为 plus 或 team")
|
||||||
|
except ValueError as e:
|
||||||
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"生成支付链接失败: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=f"生成链接失败: {str(e)}")
|
||||||
|
|
||||||
|
opened = False
|
||||||
|
if request.auto_open and link:
|
||||||
|
cookies_str = account.cookies if account else None
|
||||||
|
opened = open_url_incognito(link, cookies_str)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"link": link,
|
||||||
|
"plan_type": request.plan_type,
|
||||||
|
"auto_opened": opened,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/open-incognito")
|
||||||
|
def open_browser_incognito(request: OpenIncognitoRequest):
|
||||||
|
"""后端以无痕模式打开指定 URL,可注入账号 cookie"""
|
||||||
|
if not request.url:
|
||||||
|
raise HTTPException(status_code=400, detail="URL 不能为空")
|
||||||
|
|
||||||
|
cookies_str = None
|
||||||
|
if request.account_id:
|
||||||
|
with get_db() as db:
|
||||||
|
account = db.query(Account).filter(Account.id == request.account_id).first()
|
||||||
|
if account:
|
||||||
|
cookies_str = account.cookies
|
||||||
|
|
||||||
|
success = open_url_incognito(request.url, cookies_str)
|
||||||
|
if success:
|
||||||
|
return {"success": True, "message": "已在无痕模式打开浏览器"}
|
||||||
|
return {"success": False, "message": "未找到可用的浏览器,请手动复制链接"}
|
||||||
|
|
||||||
|
|
||||||
|
# ============== 订阅状态 ==============
|
||||||
|
|
||||||
|
@router.post("/accounts/{account_id}/mark-subscription")
|
||||||
|
def mark_subscription(account_id: int, request: MarkSubscriptionRequest):
|
||||||
|
"""手动标记账号订阅类型"""
|
||||||
|
allowed = ("free", "plus", "team")
|
||||||
|
if request.subscription_type not in allowed:
|
||||||
|
raise HTTPException(status_code=400, detail=f"subscription_type 必须为 {allowed}")
|
||||||
|
|
||||||
|
with get_db() as db:
|
||||||
|
account = db.query(Account).filter(Account.id == account_id).first()
|
||||||
|
if not account:
|
||||||
|
raise HTTPException(status_code=404, detail="账号不存在")
|
||||||
|
|
||||||
|
account.subscription_type = None if request.subscription_type == "free" else request.subscription_type
|
||||||
|
account.subscription_at = datetime.utcnow() if request.subscription_type != "free" else None
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
return {"success": True, "subscription_type": request.subscription_type}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/accounts/batch-check-subscription")
|
||||||
|
def batch_check_subscription(request: BatchCheckSubscriptionRequest):
|
||||||
|
"""批量检测账号订阅状态"""
|
||||||
|
proxy = request.proxy or get_settings().proxy_url
|
||||||
|
|
||||||
|
results = {"success_count": 0, "failed_count": 0, "details": []}
|
||||||
|
|
||||||
|
with get_db() as db:
|
||||||
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
for account_id in ids:
|
||||||
|
account = db.query(Account).filter(Account.id == account_id).first()
|
||||||
|
if not account:
|
||||||
|
results["failed_count"] += 1
|
||||||
|
results["details"].append(
|
||||||
|
{"id": account_id, "email": None, "success": False, "error": "账号不存在"}
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
status = check_subscription_status(account, proxy)
|
||||||
|
account.subscription_type = None if status == "free" else status
|
||||||
|
account.subscription_at = datetime.utcnow() if status != "free" else account.subscription_at
|
||||||
|
db.commit()
|
||||||
|
results["success_count"] += 1
|
||||||
|
results["details"].append(
|
||||||
|
{"id": account_id, "email": account.email, "success": True, "subscription_type": status}
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
results["failed_count"] += 1
|
||||||
|
results["details"].append(
|
||||||
|
{"id": account_id, "email": account.email, "success": False, "error": str(e)}
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
# ============== Team Manager 上传 ==============
|
||||||
|
|
||||||
|
@router.post("/accounts/{account_id}/upload-tm")
|
||||||
|
def upload_account_tm(account_id: int, request: UploadTMRequest = None):
|
||||||
|
"""上传单账号到 Team Manager"""
|
||||||
|
settings = get_settings()
|
||||||
|
if not settings.tm_enabled:
|
||||||
|
raise HTTPException(status_code=400, detail="Team Manager 上传未启用")
|
||||||
|
|
||||||
|
api_url = settings.tm_api_url
|
||||||
|
api_key = settings.tm_api_key.get_secret_value() if settings.tm_api_key else ""
|
||||||
|
|
||||||
|
with get_db() as db:
|
||||||
|
account = db.query(Account).filter(Account.id == account_id).first()
|
||||||
|
if not account:
|
||||||
|
raise HTTPException(status_code=404, detail="账号不存在")
|
||||||
|
success, message = upload_to_team_manager(account, api_url, api_key)
|
||||||
|
|
||||||
|
return {"success": success, "message": message}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/accounts/batch-upload-tm")
|
||||||
|
def batch_upload_tm(request: BatchUploadTMRequest):
|
||||||
|
"""批量上传账号到 Team Manager"""
|
||||||
|
settings = get_settings()
|
||||||
|
if not settings.tm_enabled:
|
||||||
|
raise HTTPException(status_code=400, detail="Team Manager 上传未启用")
|
||||||
|
|
||||||
|
api_url = settings.tm_api_url
|
||||||
|
api_key = settings.tm_api_key.get_secret_value() if settings.tm_api_key else ""
|
||||||
|
|
||||||
|
with get_db() as db:
|
||||||
|
ids = resolve_account_ids(
|
||||||
|
db, request.ids, request.select_all,
|
||||||
|
request.status_filter, request.email_service_filter, request.search_filter
|
||||||
|
)
|
||||||
|
|
||||||
|
results = batch_upload_to_team_manager(ids, api_url, api_key)
|
||||||
|
return results
|
||||||
@@ -71,6 +71,7 @@ class RegistrationTaskCreate(BaseModel):
|
|||||||
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 # 使用数据库中已配置的邮箱服务 ID
|
||||||
|
auto_upload_cpa: bool = False # 注册成功后自动上传到 CPA
|
||||||
|
|
||||||
|
|
||||||
class BatchRegistrationRequest(BaseModel):
|
class BatchRegistrationRequest(BaseModel):
|
||||||
@@ -84,6 +85,7 @@ class BatchRegistrationRequest(BaseModel):
|
|||||||
interval_max: int = 30 # 最大间隔秒数
|
interval_max: int = 30 # 最大间隔秒数
|
||||||
concurrency: int = 1 # 并发线程数 (1-50)
|
concurrency: int = 1 # 并发线程数 (1-50)
|
||||||
mode: str = "pipeline" # 执行模式: "parallel" 或 "pipeline"
|
mode: str = "pipeline" # 执行模式: "parallel" 或 "pipeline"
|
||||||
|
auto_upload_cpa: bool = False # 注册成功后自动上传到 CPA
|
||||||
|
|
||||||
|
|
||||||
class RegistrationTaskResponse(BaseModel):
|
class RegistrationTaskResponse(BaseModel):
|
||||||
@@ -146,6 +148,7 @@ class OutlookBatchRegistrationRequest(BaseModel):
|
|||||||
interval_max: int = 30
|
interval_max: int = 30
|
||||||
concurrency: int = 1 # 并发线程数 (1-50)
|
concurrency: int = 1 # 并发线程数 (1-50)
|
||||||
mode: str = "pipeline" # 执行模式: "parallel" 或 "pipeline"
|
mode: str = "pipeline" # 执行模式: "parallel" 或 "pipeline"
|
||||||
|
auto_upload_cpa: bool = False # 注册成功后自动上传到 CPA
|
||||||
|
|
||||||
|
|
||||||
class OutlookBatchRegistrationResponse(BaseModel):
|
class OutlookBatchRegistrationResponse(BaseModel):
|
||||||
@@ -176,7 +179,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 = ""):
|
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):
|
||||||
"""
|
"""
|
||||||
在线程池中执行的同步注册任务
|
在线程池中执行的同步注册任务
|
||||||
|
|
||||||
@@ -333,6 +336,25 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy:
|
|||||||
# 保存到数据库
|
# 保存到数据库
|
||||||
engine.save_to_database(result)
|
engine.save_to_database(result)
|
||||||
|
|
||||||
|
# 自动上传到 CPA
|
||||||
|
if auto_upload_cpa:
|
||||||
|
try:
|
||||||
|
from ...core.cpa_upload import upload_to_cpa, generate_token_json
|
||||||
|
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:
|
||||||
|
token_data = generate_token_json(saved_account)
|
||||||
|
cpa_success, cpa_msg = upload_to_cpa(token_data)
|
||||||
|
if cpa_success:
|
||||||
|
saved_account.cpa_uploaded = True
|
||||||
|
saved_account.cpa_uploaded_at = datetime.utcnow()
|
||||||
|
db.commit()
|
||||||
|
log_callback(f"[CPA] 已自动上传到 CPA: {result.email}")
|
||||||
|
else:
|
||||||
|
log_callback(f"[CPA] 上传失败: {cpa_msg}")
|
||||||
|
except Exception as cpa_err:
|
||||||
|
log_callback(f"[CPA] 上传异常: {cpa_err}")
|
||||||
|
|
||||||
# 更新任务状态
|
# 更新任务状态
|
||||||
crud.update_registration_task(
|
crud.update_registration_task(
|
||||||
db, task_uuid,
|
db, task_uuid,
|
||||||
@@ -377,7 +399,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 = ""):
|
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):
|
||||||
"""
|
"""
|
||||||
异步执行注册任务
|
异步执行注册任务
|
||||||
|
|
||||||
@@ -403,7 +425,8 @@ async def run_registration_task(task_uuid: str, email_service_type: str, proxy:
|
|||||||
email_service_config,
|
email_service_config,
|
||||||
email_service_id,
|
email_service_id,
|
||||||
log_prefix,
|
log_prefix,
|
||||||
batch_id
|
batch_id,
|
||||||
|
auto_upload_cpa
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"线程池执行异常: {task_uuid}, 错误: {e}")
|
logger.error(f"线程池执行异常: {task_uuid}, 错误: {e}")
|
||||||
@@ -449,7 +472,8 @@ async def run_batch_parallel(
|
|||||||
proxy: Optional[str],
|
proxy: Optional[str],
|
||||||
email_service_config: Optional[dict],
|
email_service_config: Optional[dict],
|
||||||
email_service_id: Optional[int],
|
email_service_id: Optional[int],
|
||||||
concurrency: int
|
concurrency: int,
|
||||||
|
auto_upload_cpa: bool = False
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
并行模式:所有任务同时提交,Semaphore 控制最大并发数
|
并行模式:所有任务同时提交,Semaphore 控制最大并发数
|
||||||
@@ -465,7 +489,7 @@ 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
|
log_prefix=prefix, batch_id=batch_id, auto_upload_cpa=auto_upload_cpa
|
||||||
)
|
)
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
t = crud.get_registration_task(db, uuid)
|
t = crud.get_registration_task(db, uuid)
|
||||||
@@ -506,7 +530,8 @@ async def run_batch_pipeline(
|
|||||||
email_service_id: Optional[int],
|
email_service_id: Optional[int],
|
||||||
interval_min: int,
|
interval_min: int,
|
||||||
interval_max: int,
|
interval_max: int,
|
||||||
concurrency: int
|
concurrency: int,
|
||||||
|
auto_upload_cpa: bool = False
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
流水线模式:每隔 interval 秒启动一个新任务,Semaphore 限制最大并发数
|
流水线模式:每隔 interval 秒启动一个新任务,Semaphore 限制最大并发数
|
||||||
@@ -522,7 +547,7 @@ 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
|
log_prefix=pfx, batch_id=batch_id, auto_upload_cpa=auto_upload_cpa
|
||||||
)
|
)
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
t = crud.get_registration_task(db, uuid)
|
t = crud.get_registration_task(db, uuid)
|
||||||
@@ -587,19 +612,22 @@ async def run_batch_registration(
|
|||||||
interval_min: int,
|
interval_min: int,
|
||||||
interval_max: int,
|
interval_max: int,
|
||||||
concurrency: int = 1,
|
concurrency: int = 1,
|
||||||
mode: str = "pipeline"
|
mode: str = "pipeline",
|
||||||
|
auto_upload_cpa: bool = False
|
||||||
):
|
):
|
||||||
"""根据 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
|
||||||
)
|
)
|
||||||
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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -643,7 +671,10 @@ async def start_registration(
|
|||||||
request.email_service_type,
|
request.email_service_type,
|
||||||
request.proxy,
|
request.proxy,
|
||||||
request.email_service_config,
|
request.email_service_config,
|
||||||
request.email_service_id
|
request.email_service_id,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
request.auto_upload_cpa
|
||||||
)
|
)
|
||||||
|
|
||||||
return task_to_response(task)
|
return task_to_response(task)
|
||||||
@@ -714,7 +745,8 @@ async def start_batch_registration(
|
|||||||
request.interval_min,
|
request.interval_min,
|
||||||
request.interval_max,
|
request.interval_max,
|
||||||
request.concurrency,
|
request.concurrency,
|
||||||
request.mode
|
request.mode,
|
||||||
|
request.auto_upload_cpa
|
||||||
)
|
)
|
||||||
|
|
||||||
return BatchRegistrationResponse(
|
return BatchRegistrationResponse(
|
||||||
@@ -898,6 +930,11 @@ async def get_available_email_services():
|
|||||||
"available": False,
|
"available": False,
|
||||||
"count": 0,
|
"count": 0,
|
||||||
"services": []
|
"services": []
|
||||||
|
},
|
||||||
|
"temp_mail": {
|
||||||
|
"available": False,
|
||||||
|
"count": 0,
|
||||||
|
"services": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -952,6 +989,25 @@ async def get_available_email_services():
|
|||||||
"from_settings": True
|
"from_settings": True
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# 获取 TempMail 服务(自部署 Cloudflare Worker 临时邮箱)
|
||||||
|
temp_mail_services = db.query(EmailServiceModel).filter(
|
||||||
|
EmailServiceModel.service_type == "temp_mail",
|
||||||
|
EmailServiceModel.enabled == True
|
||||||
|
).order_by(EmailServiceModel.priority.asc()).all()
|
||||||
|
|
||||||
|
for service in temp_mail_services:
|
||||||
|
config = service.config or {}
|
||||||
|
result["temp_mail"]["services"].append({
|
||||||
|
"id": service.id,
|
||||||
|
"name": service.name,
|
||||||
|
"type": "temp_mail",
|
||||||
|
"domain": config.get("domain"),
|
||||||
|
"priority": service.priority
|
||||||
|
})
|
||||||
|
|
||||||
|
result["temp_mail"]["count"] = len(temp_mail_services)
|
||||||
|
result["temp_mail"]["available"] = len(temp_mail_services) > 0
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@@ -1018,7 +1074,8 @@ async def run_outlook_batch_registration(
|
|||||||
interval_min: int,
|
interval_min: int,
|
||||||
interval_max: int,
|
interval_max: int,
|
||||||
concurrency: int = 1,
|
concurrency: int = 1,
|
||||||
mode: str = "pipeline"
|
mode: str = "pipeline",
|
||||||
|
auto_upload_cpa: bool = False
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
异步执行 Outlook 批量注册任务,复用通用并发逻辑
|
异步执行 Outlook 批量注册任务,复用通用并发逻辑
|
||||||
@@ -1055,7 +1112,8 @@ async def run_outlook_batch_registration(
|
|||||||
interval_min=interval_min,
|
interval_min=interval_min,
|
||||||
interval_max=interval_max,
|
interval_max=interval_max,
|
||||||
concurrency=concurrency,
|
concurrency=concurrency,
|
||||||
mode=mode
|
mode=mode,
|
||||||
|
auto_upload_cpa=auto_upload_cpa
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1153,7 +1211,8 @@ async def start_outlook_batch_registration(
|
|||||||
request.interval_min,
|
request.interval_min,
|
||||||
request.interval_max,
|
request.interval_max,
|
||||||
request.concurrency,
|
request.concurrency,
|
||||||
request.mode
|
request.mode,
|
||||||
|
request.auto_upload_cpa
|
||||||
)
|
)
|
||||||
|
|
||||||
return OutlookBatchRegistrationResponse(
|
return OutlookBatchRegistrationResponse(
|
||||||
|
|||||||
@@ -877,3 +877,59 @@ async def update_outlook_settings(request: OutlookSettings):
|
|||||||
update_settings(**update_dict)
|
update_settings(**update_dict)
|
||||||
|
|
||||||
return {"success": True, "message": "Outlook 设置已更新"}
|
return {"success": True, "message": "Outlook 设置已更新"}
|
||||||
|
|
||||||
|
|
||||||
|
# ============== Team Manager 设置 ==============
|
||||||
|
|
||||||
|
class TeamManagerSettings(BaseModel):
|
||||||
|
"""Team Manager 设置"""
|
||||||
|
enabled: bool = False
|
||||||
|
api_url: str = ""
|
||||||
|
api_key: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
class TeamManagerTestRequest(BaseModel):
|
||||||
|
"""Team Manager 测试请求"""
|
||||||
|
api_url: str
|
||||||
|
api_key: str
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/team-manager")
|
||||||
|
async def get_team_manager_settings():
|
||||||
|
"""获取 Team Manager 设置"""
|
||||||
|
settings = get_settings()
|
||||||
|
return {
|
||||||
|
"enabled": settings.tm_enabled,
|
||||||
|
"api_url": settings.tm_api_url,
|
||||||
|
"has_api_key": bool(settings.tm_api_key and settings.tm_api_key.get_secret_value()),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/team-manager")
|
||||||
|
async def update_team_manager_settings(request: TeamManagerSettings):
|
||||||
|
"""更新 Team Manager 设置"""
|
||||||
|
update_dict = {
|
||||||
|
"tm_enabled": request.enabled,
|
||||||
|
"tm_api_url": request.api_url,
|
||||||
|
}
|
||||||
|
if request.api_key:
|
||||||
|
update_dict["tm_api_key"] = request.api_key
|
||||||
|
update_settings(**update_dict)
|
||||||
|
return {"success": True, "message": "Team Manager 设置已更新"}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/team-manager/test")
|
||||||
|
async def test_team_manager_connection(request: TeamManagerTestRequest):
|
||||||
|
"""测试 Team Manager 连接"""
|
||||||
|
from ...core.team_manager import test_team_manager_connection as do_test
|
||||||
|
|
||||||
|
settings = get_settings()
|
||||||
|
api_key = request.api_key
|
||||||
|
if api_key == 'use_saved_key' or not api_key:
|
||||||
|
if settings.tm_api_key:
|
||||||
|
api_key = settings.tm_api_key.get_secret_value()
|
||||||
|
else:
|
||||||
|
return {"success": False, "message": "未配置 API Key"}
|
||||||
|
|
||||||
|
success, message = do_test(request.api_url, api_key)
|
||||||
|
return {"success": success, "message": message}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ let pageSize = 20;
|
|||||||
let totalAccounts = 0;
|
let totalAccounts = 0;
|
||||||
let selectedAccounts = new Set();
|
let selectedAccounts = new Set();
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
let selectAllPages = false; // 是否选中了全部页
|
||||||
|
let currentFilters = { status: '', email_service: '', search: '' }; // 当前筛选条件
|
||||||
|
|
||||||
// DOM 元素
|
// DOM 元素
|
||||||
const elements = {
|
const elements = {
|
||||||
@@ -24,6 +26,8 @@ const elements = {
|
|||||||
batchRefreshBtn: document.getElementById('batch-refresh-btn'),
|
batchRefreshBtn: document.getElementById('batch-refresh-btn'),
|
||||||
batchValidateBtn: document.getElementById('batch-validate-btn'),
|
batchValidateBtn: document.getElementById('batch-validate-btn'),
|
||||||
batchUploadCpaBtn: document.getElementById('batch-upload-cpa-btn'),
|
batchUploadCpaBtn: document.getElementById('batch-upload-cpa-btn'),
|
||||||
|
batchCheckSubBtn: document.getElementById('batch-check-sub-btn'),
|
||||||
|
batchUploadTmBtn: document.getElementById('batch-upload-tm-btn'),
|
||||||
batchDeleteBtn: document.getElementById('batch-delete-btn'),
|
batchDeleteBtn: document.getElementById('batch-delete-btn'),
|
||||||
exportBtn: document.getElementById('export-btn'),
|
exportBtn: document.getElementById('export-btn'),
|
||||||
exportMenu: document.getElementById('export-menu'),
|
exportMenu: document.getElementById('export-menu'),
|
||||||
@@ -42,6 +46,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
loadAccounts();
|
loadAccounts();
|
||||||
initEventListeners();
|
initEventListeners();
|
||||||
updateBatchButtons(); // 初始化按钮状态
|
updateBatchButtons(); // 初始化按钮状态
|
||||||
|
renderSelectAllBanner();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 事件监听
|
// 事件监听
|
||||||
@@ -49,17 +54,20 @@ function initEventListeners() {
|
|||||||
// 筛选
|
// 筛选
|
||||||
elements.filterStatus.addEventListener('change', () => {
|
elements.filterStatus.addEventListener('change', () => {
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
|
resetSelectAllPages();
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
});
|
});
|
||||||
|
|
||||||
elements.filterService.addEventListener('change', () => {
|
elements.filterService.addEventListener('change', () => {
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
|
resetSelectAllPages();
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 搜索(防抖)
|
// 搜索(防抖)
|
||||||
elements.searchInput.addEventListener('input', debounce(() => {
|
elements.searchInput.addEventListener('input', debounce(() => {
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
|
resetSelectAllPages();
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
}, 300));
|
}, 300));
|
||||||
|
|
||||||
@@ -68,6 +76,7 @@ function initEventListeners() {
|
|||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
elements.searchInput.blur();
|
elements.searchInput.blur();
|
||||||
elements.searchInput.value = '';
|
elements.searchInput.value = '';
|
||||||
|
resetSelectAllPages();
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -88,10 +97,16 @@ function initEventListeners() {
|
|||||||
// 批量上传CPA
|
// 批量上传CPA
|
||||||
elements.batchUploadCpaBtn.addEventListener('click', handleBatchUploadCpa);
|
elements.batchUploadCpaBtn.addEventListener('click', handleBatchUploadCpa);
|
||||||
|
|
||||||
|
// 批量检测订阅
|
||||||
|
elements.batchCheckSubBtn.addEventListener('click', handleBatchCheckSubscription);
|
||||||
|
|
||||||
|
// 批量上传TM
|
||||||
|
elements.batchUploadTmBtn.addEventListener('click', handleBatchUploadTm);
|
||||||
|
|
||||||
// 批量删除
|
// 批量删除
|
||||||
elements.batchDeleteBtn.addEventListener('click', handleBatchDelete);
|
elements.batchDeleteBtn.addEventListener('click', handleBatchDelete);
|
||||||
|
|
||||||
// 全选
|
// 全选(当前页)
|
||||||
elements.selectAll.addEventListener('change', (e) => {
|
elements.selectAll.addEventListener('change', (e) => {
|
||||||
const checkboxes = elements.table.querySelectorAll('input[type="checkbox"][data-id]');
|
const checkboxes = elements.table.querySelectorAll('input[type="checkbox"][data-id]');
|
||||||
checkboxes.forEach(cb => {
|
checkboxes.forEach(cb => {
|
||||||
@@ -103,7 +118,11 @@ function initEventListeners() {
|
|||||||
selectedAccounts.delete(id);
|
selectedAccounts.delete(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!e.target.checked) {
|
||||||
|
selectAllPages = false;
|
||||||
|
}
|
||||||
updateBatchButtons();
|
updateBatchButtons();
|
||||||
|
renderSelectAllBanner();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 分页
|
// 分页
|
||||||
@@ -196,21 +215,26 @@ async function loadAccounts() {
|
|||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// 记录当前筛选条件
|
||||||
|
currentFilters.status = elements.filterStatus.value;
|
||||||
|
currentFilters.email_service = elements.filterService.value;
|
||||||
|
currentFilters.search = elements.searchInput.value.trim();
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
page: currentPage,
|
page: currentPage,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (elements.filterStatus.value) {
|
if (currentFilters.status) {
|
||||||
params.append('status', elements.filterStatus.value);
|
params.append('status', currentFilters.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elements.filterService.value) {
|
if (currentFilters.email_service) {
|
||||||
params.append('email_service', elements.filterService.value);
|
params.append('email_service', currentFilters.email_service);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elements.searchInput.value.trim()) {
|
if (currentFilters.search) {
|
||||||
params.append('search', elements.searchInput.value.trim());
|
params.append('search', currentFilters.search);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -283,6 +307,13 @@ function renderAccounts(accounts) {
|
|||||||
: `<span class="badge pending">-</span>`}
|
: `<span class="badge pending">-</span>`}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="cpa-status">
|
||||||
|
${account.subscription_type
|
||||||
|
? `<span class="badge uploaded" title="${account.subscription_type}">${account.subscription_type}</span>`
|
||||||
|
: `<span class="badge pending">-</span>`}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<td>${format.date(account.last_refresh) || '-'}</td>
|
<td>${format.date(account.last_refresh) || '-'}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
@@ -292,6 +323,12 @@ function renderAccounts(accounts) {
|
|||||||
<button class="btn btn-ghost btn-sm" onclick="uploadToCpa(${account.id})" title="上传到CPA">
|
<button class="btn btn-ghost btn-sm" onclick="uploadToCpa(${account.id})" title="上传到CPA">
|
||||||
☁️
|
☁️
|
||||||
</button>
|
</button>
|
||||||
|
<button class="btn btn-ghost btn-sm" onclick="markSubscription(${account.id})" title="标记订阅">
|
||||||
|
🏷️
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-ghost btn-sm" onclick="uploadToTm(${account.id})" title="上传到Team Manager">
|
||||||
|
🚀
|
||||||
|
</button>
|
||||||
<button class="btn btn-ghost btn-sm" onclick="viewAccount(${account.id})" title="查看详情">
|
<button class="btn btn-ghost btn-sm" onclick="viewAccount(${account.id})" title="查看详情">
|
||||||
👁️
|
👁️
|
||||||
</button>
|
</button>
|
||||||
@@ -315,10 +352,24 @@ function renderAccounts(accounts) {
|
|||||||
selectedAccounts.add(id);
|
selectedAccounts.add(id);
|
||||||
} else {
|
} else {
|
||||||
selectedAccounts.delete(id);
|
selectedAccounts.delete(id);
|
||||||
|
selectAllPages = false;
|
||||||
}
|
}
|
||||||
|
// 同步全选框状态
|
||||||
|
const allChecked = elements.table.querySelectorAll('input[type="checkbox"][data-id]');
|
||||||
|
const checkedCount = elements.table.querySelectorAll('input[type="checkbox"][data-id]:checked').length;
|
||||||
|
elements.selectAll.checked = allChecked.length > 0 && checkedCount === allChecked.length;
|
||||||
|
elements.selectAll.indeterminate = checkedCount > 0 && checkedCount < allChecked.length;
|
||||||
updateBatchButtons();
|
updateBatchButtons();
|
||||||
|
renderSelectAllBanner();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 渲染后同步全选框状态
|
||||||
|
const allCbs = elements.table.querySelectorAll('input[type="checkbox"][data-id]');
|
||||||
|
const checkedCbs = elements.table.querySelectorAll('input[type="checkbox"][data-id]:checked');
|
||||||
|
elements.selectAll.checked = allCbs.length > 0 && checkedCbs.length === allCbs.length;
|
||||||
|
elements.selectAll.indeterminate = checkedCbs.length > 0 && checkedCbs.length < allCbs.length;
|
||||||
|
renderSelectAllBanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换密码显示
|
// 切换密码显示
|
||||||
@@ -344,19 +395,87 @@ function updatePagination() {
|
|||||||
elements.pageInfo.textContent = `第 ${currentPage} 页 / 共 ${totalPages} 页`;
|
elements.pageInfo.textContent = `第 ${currentPage} 页 / 共 ${totalPages} 页`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重置全选所有页状态
|
||||||
|
function resetSelectAllPages() {
|
||||||
|
selectAllPages = false;
|
||||||
|
selectedAccounts.clear();
|
||||||
|
updateBatchButtons();
|
||||||
|
renderSelectAllBanner();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建批量请求体(含 select_all 和筛选参数)
|
||||||
|
function buildBatchPayload(extraFields = {}) {
|
||||||
|
if (selectAllPages) {
|
||||||
|
return {
|
||||||
|
ids: [],
|
||||||
|
select_all: true,
|
||||||
|
status_filter: currentFilters.status || null,
|
||||||
|
email_service_filter: currentFilters.email_service || null,
|
||||||
|
search_filter: currentFilters.search || null,
|
||||||
|
...extraFields
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { ids: Array.from(selectedAccounts), ...extraFields };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取有效选中数量(select_all 时用总数)
|
||||||
|
function getEffectiveCount() {
|
||||||
|
return selectAllPages ? totalAccounts : selectedAccounts.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染全选横幅
|
||||||
|
function renderSelectAllBanner() {
|
||||||
|
let banner = document.getElementById('select-all-banner');
|
||||||
|
const totalPages = Math.ceil(totalAccounts / pageSize);
|
||||||
|
const currentPageSize = elements.table.querySelectorAll('input[type="checkbox"][data-id]').length;
|
||||||
|
const checkedOnPage = elements.table.querySelectorAll('input[type="checkbox"][data-id]:checked').length;
|
||||||
|
const allPageSelected = currentPageSize > 0 && checkedOnPage === currentPageSize;
|
||||||
|
|
||||||
|
// 只在全选了当前页且有多页时显示横幅
|
||||||
|
if (!allPageSelected || totalPages <= 1 || totalAccounts <= pageSize) {
|
||||||
|
if (banner) banner.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!banner) {
|
||||||
|
banner = document.createElement('div');
|
||||||
|
banner.id = 'select-all-banner';
|
||||||
|
banner.style.cssText = 'background:var(--primary-light,#e8f0fe);color:var(--primary-color,#1a73e8);padding:8px 16px;text-align:center;font-size:0.875rem;border-bottom:1px solid var(--border-color);';
|
||||||
|
const tableContainer = document.querySelector('.table-container');
|
||||||
|
if (tableContainer) tableContainer.insertAdjacentElement('beforebegin', banner);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectAllPages) {
|
||||||
|
banner.innerHTML = `已选中全部 <strong>${totalAccounts}</strong> 条记录。<button onclick="resetSelectAllPages()" style="margin-left:8px;color:var(--primary-color,#1a73e8);background:none;border:none;cursor:pointer;text-decoration:underline;">取消全选</button>`;
|
||||||
|
} else {
|
||||||
|
banner.innerHTML = `当前页已全选 <strong>${checkedOnPage}</strong> 条。<button onclick="selectAllPagesAction()" style="margin-left:8px;color:var(--primary-color,#1a73e8);background:none;border:none;cursor:pointer;text-decoration:underline;">选择全部 ${totalAccounts} 条</button>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选中所有页
|
||||||
|
function selectAllPagesAction() {
|
||||||
|
selectAllPages = true;
|
||||||
|
updateBatchButtons();
|
||||||
|
renderSelectAllBanner();
|
||||||
|
}
|
||||||
|
|
||||||
// 更新批量操作按钮
|
// 更新批量操作按钮
|
||||||
function updateBatchButtons() {
|
function updateBatchButtons() {
|
||||||
const count = selectedAccounts.size;
|
const count = getEffectiveCount();
|
||||||
elements.batchDeleteBtn.disabled = count === 0;
|
elements.batchDeleteBtn.disabled = count === 0;
|
||||||
elements.batchRefreshBtn.disabled = count === 0;
|
elements.batchRefreshBtn.disabled = count === 0;
|
||||||
elements.batchValidateBtn.disabled = count === 0;
|
elements.batchValidateBtn.disabled = count === 0;
|
||||||
elements.batchUploadCpaBtn.disabled = count === 0;
|
elements.batchUploadCpaBtn.disabled = count === 0;
|
||||||
|
elements.batchCheckSubBtn.disabled = count === 0;
|
||||||
|
elements.batchUploadTmBtn.disabled = count === 0;
|
||||||
elements.exportBtn.disabled = count === 0;
|
elements.exportBtn.disabled = count === 0;
|
||||||
|
|
||||||
elements.batchDeleteBtn.textContent = count > 0 ? `🗑️ 删除 (${count})` : '🗑️ 批量删除';
|
elements.batchDeleteBtn.textContent = count > 0 ? `🗑️ 删除 (${count})` : '🗑️ 批量删除';
|
||||||
elements.batchRefreshBtn.textContent = count > 0 ? `🔄 刷新 (${count})` : '🔄 刷新Token';
|
elements.batchRefreshBtn.textContent = count > 0 ? `🔄 刷新 (${count})` : '🔄 刷新Token';
|
||||||
elements.batchValidateBtn.textContent = count > 0 ? `✅ 验证 (${count})` : '✅ 验证Token';
|
elements.batchValidateBtn.textContent = count > 0 ? `✅ 验证 (${count})` : '✅ 验证Token';
|
||||||
elements.batchUploadCpaBtn.textContent = count > 0 ? `☁️ 上传 (${count})` : '☁️ 上传CPA';
|
elements.batchUploadCpaBtn.textContent = count > 0 ? `☁️ 上传 (${count})` : '☁️ 上传CPA';
|
||||||
|
elements.batchCheckSubBtn.textContent = count > 0 ? `🔍 检测 (${count})` : '🔍 检测订阅';
|
||||||
|
elements.batchUploadTmBtn.textContent = count > 0 ? `🚀 上传TM (${count})` : '🚀 上传TM';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新单个账号Token
|
// 刷新单个账号Token
|
||||||
@@ -378,19 +497,17 @@ async function refreshToken(id) {
|
|||||||
|
|
||||||
// 批量刷新Token
|
// 批量刷新Token
|
||||||
async function handleBatchRefresh() {
|
async function handleBatchRefresh() {
|
||||||
if (selectedAccounts.size === 0) return;
|
const count = getEffectiveCount();
|
||||||
|
if (count === 0) return;
|
||||||
|
|
||||||
const confirmed = await confirm(`确定要刷新选中的 ${selectedAccounts.size} 个账号的Token吗?`);
|
const confirmed = await confirm(`确定要刷新选中的 ${count} 个账号的Token吗?`);
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
|
|
||||||
elements.batchRefreshBtn.disabled = true;
|
elements.batchRefreshBtn.disabled = true;
|
||||||
elements.batchRefreshBtn.textContent = '刷新中...';
|
elements.batchRefreshBtn.textContent = '刷新中...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await api.post('/accounts/batch-refresh', {
|
const result = await api.post('/accounts/batch-refresh', buildBatchPayload());
|
||||||
ids: Array.from(selectedAccounts)
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success(`成功刷新 ${result.success_count} 个,失败 ${result.failed_count} 个`);
|
toast.success(`成功刷新 ${result.success_count} 个,失败 ${result.failed_count} 个`);
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -402,16 +519,13 @@ async function handleBatchRefresh() {
|
|||||||
|
|
||||||
// 批量验证Token
|
// 批量验证Token
|
||||||
async function handleBatchValidate() {
|
async function handleBatchValidate() {
|
||||||
if (selectedAccounts.size === 0) return;
|
if (getEffectiveCount() === 0) return;
|
||||||
|
|
||||||
elements.batchValidateBtn.disabled = true;
|
elements.batchValidateBtn.disabled = true;
|
||||||
elements.batchValidateBtn.textContent = '验证中...';
|
elements.batchValidateBtn.textContent = '验证中...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await api.post('/accounts/batch-validate', {
|
const result = await api.post('/accounts/batch-validate', buildBatchPayload());
|
||||||
ids: Array.from(selectedAccounts)
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.info(`有效: ${result.valid_count},无效: ${result.invalid_count}`);
|
toast.info(`有效: ${result.valid_count},无效: ${result.invalid_count}`);
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -499,6 +613,17 @@ async function viewAccount(id) {
|
|||||||
${tokens.refresh_token ? `<button class="btn btn-ghost btn-sm" onclick="copyToClipboard('${escapeHtml(tokens.refresh_token)}')" style="margin-left: 8px;">📋</button>` : ''}
|
${tokens.refresh_token ? `<button class="btn btn-ghost btn-sm" onclick="copyToClipboard('${escapeHtml(tokens.refresh_token)}')" style="margin-left: 8px;">📋</button>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="info-item" style="grid-column: span 2;">
|
||||||
|
<span class="label">Cookies(支付用)</span>
|
||||||
|
<div class="value">
|
||||||
|
<textarea id="cookies-input-${id}" rows="3"
|
||||||
|
style="width:100%;font-size:0.7rem;font-family:var(--font-mono);background:var(--surface-hover);border:1px solid var(--border);border-radius:4px;padding:6px;color:var(--text-primary);resize:vertical;"
|
||||||
|
placeholder="粘贴完整 cookie 字符串,留空则清除">${escapeHtml(account.cookies || '')}</textarea>
|
||||||
|
<button class="btn btn-secondary btn-sm" style="margin-top:4px" onclick="saveCookies(${id})">
|
||||||
|
保存 Cookies
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-top: var(--spacing-lg); display: flex; gap: var(--spacing-sm);">
|
<div style="margin-top: var(--spacing-lg); display: flex; gap: var(--spacing-sm);">
|
||||||
<button class="btn btn-primary" onclick="refreshToken(${id}); elements.detailModal.classList.remove('active');">
|
<button class="btn btn-primary" onclick="refreshToken(${id}); elements.detailModal.classList.remove('active');">
|
||||||
@@ -536,18 +661,17 @@ async function deleteAccount(id, email) {
|
|||||||
|
|
||||||
// 批量删除
|
// 批量删除
|
||||||
async function handleBatchDelete() {
|
async function handleBatchDelete() {
|
||||||
if (selectedAccounts.size === 0) return;
|
const count = getEffectiveCount();
|
||||||
|
if (count === 0) return;
|
||||||
|
|
||||||
const confirmed = await confirm(`确定要删除选中的 ${selectedAccounts.size} 个账号吗?此操作不可恢复。`);
|
const confirmed = await confirm(`确定要删除选中的 ${count} 个账号吗?此操作不可恢复。`);
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await api.post('/accounts/batch-delete', {
|
const result = await api.post('/accounts/batch-delete', buildBatchPayload());
|
||||||
ids: Array.from(selectedAccounts)
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success(`成功删除 ${result.deleted_count} 个账号`);
|
toast.success(`成功删除 ${result.deleted_count} 个账号`);
|
||||||
selectedAccounts.clear();
|
selectedAccounts.clear();
|
||||||
|
selectAllPages = false;
|
||||||
loadStats();
|
loadStats();
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -557,12 +681,13 @@ async function handleBatchDelete() {
|
|||||||
|
|
||||||
// 导出账号
|
// 导出账号
|
||||||
async function exportAccounts(format) {
|
async function exportAccounts(format) {
|
||||||
if (selectedAccounts.size === 0) {
|
const count = getEffectiveCount();
|
||||||
|
if (count === 0) {
|
||||||
toast.warning('请先选择要导出的账号');
|
toast.warning('请先选择要导出的账号');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.info(`正在导出 ${selectedAccounts.size} 个账号...`);
|
toast.info(`正在导出 ${count} 个账号...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/accounts/export/' + format, {
|
const response = await fetch('/api/accounts/export/' + format, {
|
||||||
@@ -570,9 +695,7 @@ async function exportAccounts(format) {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(buildBatchPayload())
|
||||||
ids: Array.from(selectedAccounts)
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -584,7 +707,7 @@ async function exportAccounts(format) {
|
|||||||
|
|
||||||
// 从 Content-Disposition 获取文件名
|
// 从 Content-Disposition 获取文件名
|
||||||
const disposition = response.headers.get('Content-Disposition');
|
const disposition = response.headers.get('Content-Disposition');
|
||||||
let filename = `accounts_${Date.now()}.${format === 'cpa' ? 'json' : format}`;
|
let filename = `accounts_${Date.now()}.${(format === 'cpa' || format === 'sub2api') ? 'json' : format}`;
|
||||||
if (disposition) {
|
if (disposition) {
|
||||||
const match = disposition.match(/filename=(.+)/);
|
const match = disposition.match(/filename=(.+)/);
|
||||||
if (match) {
|
if (match) {
|
||||||
@@ -636,18 +759,17 @@ async function uploadToCpa(id) {
|
|||||||
|
|
||||||
// 批量上传到CPA
|
// 批量上传到CPA
|
||||||
async function handleBatchUploadCpa() {
|
async function handleBatchUploadCpa() {
|
||||||
if (selectedAccounts.size === 0) return;
|
const count = getEffectiveCount();
|
||||||
|
if (count === 0) return;
|
||||||
|
|
||||||
const confirmed = await confirm(`确定要将选中的 ${selectedAccounts.size} 个账号上传到CPA吗?`);
|
const confirmed = await confirm(`确定要将选中的 ${count} 个账号上传到CPA吗?`);
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
|
|
||||||
elements.batchUploadCpaBtn.disabled = true;
|
elements.batchUploadCpaBtn.disabled = true;
|
||||||
elements.batchUploadCpaBtn.textContent = '上传中...';
|
elements.batchUploadCpaBtn.textContent = '上传中...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await api.post('/accounts/batch-upload-cpa', {
|
const result = await api.post('/accounts/batch-upload-cpa', buildBatchPayload());
|
||||||
ids: Array.from(selectedAccounts)
|
|
||||||
});
|
|
||||||
|
|
||||||
let message = `成功: ${result.success_count}`;
|
let message = `成功: ${result.success_count}`;
|
||||||
if (result.failed_count > 0) {
|
if (result.failed_count > 0) {
|
||||||
@@ -665,3 +787,101 @@ async function handleBatchUploadCpa() {
|
|||||||
updateBatchButtons();
|
updateBatchButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============== 订阅状态 ==============
|
||||||
|
|
||||||
|
// 手动标记订阅类型
|
||||||
|
async function markSubscription(id) {
|
||||||
|
const type = prompt('请输入订阅类型 (plus / team / free):', 'plus');
|
||||||
|
if (!type) return;
|
||||||
|
if (!['plus', 'team', 'free'].includes(type.trim().toLowerCase())) {
|
||||||
|
toast.error('无效的订阅类型,请输入 plus、team 或 free');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await api.post(`/payment/accounts/${id}/mark-subscription`, {
|
||||||
|
subscription_type: type.trim().toLowerCase()
|
||||||
|
});
|
||||||
|
toast.success('订阅状态已更新');
|
||||||
|
loadAccounts();
|
||||||
|
} catch (e) {
|
||||||
|
toast.error('标记失败: ' + e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量检测订阅状态
|
||||||
|
async function handleBatchCheckSubscription() {
|
||||||
|
const count = getEffectiveCount();
|
||||||
|
if (count === 0) return;
|
||||||
|
const confirmed = await confirm(`确定要检测选中的 ${count} 个账号的订阅状态吗?`);
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
|
elements.batchCheckSubBtn.disabled = true;
|
||||||
|
elements.batchCheckSubBtn.textContent = '检测中...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await api.post('/payment/accounts/batch-check-subscription', buildBatchPayload());
|
||||||
|
let message = `成功: ${result.success_count}`;
|
||||||
|
if (result.failed_count > 0) message += `, 失败: ${result.failed_count}`;
|
||||||
|
toast.success(message);
|
||||||
|
loadAccounts();
|
||||||
|
} catch (e) {
|
||||||
|
toast.error('批量检测失败: ' + e.message);
|
||||||
|
} finally {
|
||||||
|
updateBatchButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============== Team Manager 上传 ==============
|
||||||
|
|
||||||
|
// 上传单账号到 Team Manager
|
||||||
|
async function uploadToTm(id) {
|
||||||
|
try {
|
||||||
|
toast.info('正在上传到 Team Manager...');
|
||||||
|
const result = await api.post(`/payment/accounts/${id}/upload-tm`);
|
||||||
|
if (result.success) {
|
||||||
|
toast.success('上传成功');
|
||||||
|
} else {
|
||||||
|
toast.error('上传失败: ' + (result.message || '未知错误'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toast.error('上传失败: ' + e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量上传到 Team Manager
|
||||||
|
async function handleBatchUploadTm() {
|
||||||
|
const count = getEffectiveCount();
|
||||||
|
if (count === 0) return;
|
||||||
|
const confirmed = await confirm(`确定要将选中的 ${count} 个账号上传到 Team Manager 吗?`);
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
|
elements.batchUploadTmBtn.disabled = true;
|
||||||
|
elements.batchUploadTmBtn.textContent = '上传中...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await api.post('/payment/accounts/batch-upload-tm', buildBatchPayload());
|
||||||
|
let message = `成功: ${result.success_count}`;
|
||||||
|
if (result.failed_count > 0) message += `, 失败: ${result.failed_count}`;
|
||||||
|
if (result.skipped_count > 0) message += `, 跳过: ${result.skipped_count}`;
|
||||||
|
toast.success(message);
|
||||||
|
loadAccounts();
|
||||||
|
} catch (e) {
|
||||||
|
toast.error('批量上传失败: ' + e.message);
|
||||||
|
} finally {
|
||||||
|
updateBatchButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存账号 Cookies
|
||||||
|
async function saveCookies(id) {
|
||||||
|
const textarea = document.getElementById(`cookies-input-${id}`);
|
||||||
|
if (!textarea) return;
|
||||||
|
const cookiesValue = textarea.value.trim();
|
||||||
|
try {
|
||||||
|
await api.patch(`/accounts/${id}`, { cookies: cookiesValue });
|
||||||
|
toast.success('Cookies 已保存');
|
||||||
|
} catch (e) {
|
||||||
|
toast.error('保存 Cookies 失败: ' + e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ let toastShown = false; // 标记是否已显示过 toast
|
|||||||
let availableServices = {
|
let availableServices = {
|
||||||
tempmail: { available: true, services: [] },
|
tempmail: { available: true, services: [] },
|
||||||
outlook: { available: false, services: [] },
|
outlook: { available: false, services: [] },
|
||||||
custom_domain: { available: false, services: [] }
|
custom_domain: { available: false, services: [] },
|
||||||
|
temp_mail: { available: false, services: [] }
|
||||||
};
|
};
|
||||||
|
|
||||||
// WebSocket 相关变量
|
// WebSocket 相关变量
|
||||||
@@ -80,7 +81,9 @@ const elements = {
|
|||||||
concurrencyMode: document.getElementById('concurrency-mode'),
|
concurrencyMode: document.getElementById('concurrency-mode'),
|
||||||
concurrencyCount: document.getElementById('concurrency-count'),
|
concurrencyCount: document.getElementById('concurrency-count'),
|
||||||
concurrencyHint: document.getElementById('concurrency-hint'),
|
concurrencyHint: document.getElementById('concurrency-hint'),
|
||||||
intervalGroup: document.getElementById('interval-group')
|
intervalGroup: document.getElementById('interval-group'),
|
||||||
|
// 注册后自动操作
|
||||||
|
autoUploadCpa: document.getElementById('auto-upload-cpa')
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
@@ -91,8 +94,25 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
startAccountsPolling();
|
startAccountsPolling();
|
||||||
initVisibilityReconnect();
|
initVisibilityReconnect();
|
||||||
restoreActiveTask();
|
restoreActiveTask();
|
||||||
|
checkCpaEnabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 检查 CPA 是否启用,未启用则禁用复选框
|
||||||
|
async function checkCpaEnabled() {
|
||||||
|
if (!elements.autoUploadCpa) return;
|
||||||
|
try {
|
||||||
|
const data = await api.get('/settings/cpa');
|
||||||
|
if (!data.enabled) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 事件监听
|
// 事件监听
|
||||||
function initEventListeners() {
|
function initEventListeners() {
|
||||||
// 注册表单提交
|
// 注册表单提交
|
||||||
@@ -229,6 +249,23 @@ function updateEmailServiceOptions() {
|
|||||||
|
|
||||||
select.appendChild(optgroup);
|
select.appendChild(optgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Temp-Mail(自部署)
|
||||||
|
if (availableServices.temp_mail && availableServices.temp_mail.available) {
|
||||||
|
const optgroup = document.createElement('optgroup');
|
||||||
|
optgroup.label = `📮 Temp-Mail 自部署 (${availableServices.temp_mail.count} 个服务)`;
|
||||||
|
|
||||||
|
availableServices.temp_mail.services.forEach(service => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = `temp_mail:${service.id}`;
|
||||||
|
option.textContent = service.name + (service.domain ? ` (@${service.domain})` : '');
|
||||||
|
option.dataset.type = 'temp_mail';
|
||||||
|
option.dataset.serviceId = service.id;
|
||||||
|
optgroup.appendChild(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
select.appendChild(optgroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理邮箱服务切换
|
// 处理邮箱服务切换
|
||||||
@@ -317,7 +354,8 @@ 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
|
||||||
};
|
};
|
||||||
|
|
||||||
// 如果选择了数据库中的服务,传递 service_id
|
// 如果选择了数据库中的服务,传递 service_id
|
||||||
@@ -1015,7 +1053,8 @@ async function handleOutlookBatchRegistration() {
|
|||||||
interval_min: intervalMin,
|
interval_min: intervalMin,
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
||||||
addLog('info', `[系统] 正在启动 Outlook 批量注册 (${selectedIds.length} 个账户)...`);
|
addLog('info', `[系统] 正在启动 Outlook 批量注册 (${selectedIds.length} 个账户)...`);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
// 状态
|
// 状态
|
||||||
let outlookServices = [];
|
let outlookServices = [];
|
||||||
let customServices = [];
|
let customServices = []; // 合并 custom_domain + temp_mail
|
||||||
let selectedOutlook = new Set();
|
let selectedOutlook = new Set();
|
||||||
let selectedCustom = new Set();
|
let selectedCustom = new Set();
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ const elements = {
|
|||||||
selectAllOutlook: document.getElementById('select-all-outlook'),
|
selectAllOutlook: document.getElementById('select-all-outlook'),
|
||||||
batchDeleteOutlookBtn: document.getElementById('batch-delete-outlook-btn'),
|
batchDeleteOutlookBtn: document.getElementById('batch-delete-outlook-btn'),
|
||||||
|
|
||||||
// 自定义域名
|
// 自定义域名(合并)
|
||||||
customTable: document.getElementById('custom-services-table'),
|
customTable: document.getElementById('custom-services-table'),
|
||||||
addCustomBtn: document.getElementById('add-custom-btn'),
|
addCustomBtn: document.getElementById('add-custom-btn'),
|
||||||
selectAllCustom: document.getElementById('select-all-custom'),
|
selectAllCustom: document.getElementById('select-all-custom'),
|
||||||
@@ -47,18 +47,25 @@ const elements = {
|
|||||||
addCustomForm: document.getElementById('add-custom-form'),
|
addCustomForm: document.getElementById('add-custom-form'),
|
||||||
closeCustomModal: document.getElementById('close-custom-modal'),
|
closeCustomModal: document.getElementById('close-custom-modal'),
|
||||||
cancelAddCustom: document.getElementById('cancel-add-custom'),
|
cancelAddCustom: document.getElementById('cancel-add-custom'),
|
||||||
|
customSubType: document.getElementById('custom-sub-type'),
|
||||||
|
addMoemailFields: document.getElementById('add-moemail-fields'),
|
||||||
|
addTempmailFields: document.getElementById('add-tempmail-fields'),
|
||||||
|
|
||||||
// 编辑自定义域名模态框
|
// 编辑自定义域名模态框
|
||||||
editCustomModal: document.getElementById('edit-custom-modal'),
|
editCustomModal: document.getElementById('edit-custom-modal'),
|
||||||
editCustomForm: document.getElementById('edit-custom-form'),
|
editCustomForm: document.getElementById('edit-custom-form'),
|
||||||
closeEditCustomModal: document.getElementById('close-edit-custom-modal'),
|
closeEditCustomModal: document.getElementById('close-edit-custom-modal'),
|
||||||
cancelEditCustom: document.getElementById('cancel-edit-custom'),
|
cancelEditCustom: document.getElementById('cancel-edit-custom'),
|
||||||
|
editMoemailFields: document.getElementById('edit-moemail-fields'),
|
||||||
|
editTempmailFields: document.getElementById('edit-tempmail-fields'),
|
||||||
|
editCustomTypeBadge: document.getElementById('edit-custom-type-badge'),
|
||||||
|
editCustomSubTypeHidden: document.getElementById('edit-custom-sub-type-hidden'),
|
||||||
|
|
||||||
// 编辑 Outlook 模态框
|
// 编辑 Outlook 模态框
|
||||||
editOutlookModal: document.getElementById('edit-outlook-modal'),
|
editOutlookModal: document.getElementById('edit-outlook-modal'),
|
||||||
editOutlookForm: document.getElementById('edit-outlook-form'),
|
editOutlookForm: document.getElementById('edit-outlook-form'),
|
||||||
closeEditOutlookModal: document.getElementById('close-edit-outlook-modal'),
|
closeEditOutlookModal: document.getElementById('close-edit-outlook-modal'),
|
||||||
cancelEditOutlook: document.getElementById('cancel-edit-outlook')
|
cancelEditOutlook: document.getElementById('cancel-edit-outlook'),
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
@@ -92,11 +99,8 @@ function initEventListeners() {
|
|||||||
checkboxes.forEach(cb => {
|
checkboxes.forEach(cb => {
|
||||||
cb.checked = e.target.checked;
|
cb.checked = e.target.checked;
|
||||||
const id = parseInt(cb.dataset.id);
|
const id = parseInt(cb.dataset.id);
|
||||||
if (e.target.checked) {
|
if (e.target.checked) selectedOutlook.add(id);
|
||||||
selectedOutlook.add(id);
|
else selectedOutlook.delete(id);
|
||||||
} else {
|
|
||||||
selectedOutlook.delete(id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
updateBatchButtons();
|
updateBatchButtons();
|
||||||
});
|
});
|
||||||
@@ -104,68 +108,72 @@ function initEventListeners() {
|
|||||||
// Outlook 批量删除
|
// Outlook 批量删除
|
||||||
elements.batchDeleteOutlookBtn.addEventListener('click', handleBatchDeleteOutlook);
|
elements.batchDeleteOutlookBtn.addEventListener('click', handleBatchDeleteOutlook);
|
||||||
|
|
||||||
// 添加自定义域名
|
|
||||||
elements.addCustomBtn.addEventListener('click', () => {
|
|
||||||
elements.addCustomModal.classList.add('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.closeCustomModal.addEventListener('click', () => {
|
|
||||||
elements.addCustomModal.classList.remove('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.cancelAddCustom.addEventListener('click', () => {
|
|
||||||
elements.addCustomModal.classList.remove('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.addCustomForm.addEventListener('submit', handleAddCustom);
|
|
||||||
|
|
||||||
// 编辑自定义域名模态框
|
|
||||||
elements.closeEditCustomModal.addEventListener('click', () => {
|
|
||||||
elements.editCustomModal.classList.remove('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.cancelEditCustom.addEventListener('click', () => {
|
|
||||||
elements.editCustomModal.classList.remove('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.editCustomForm.addEventListener('submit', handleEditCustom);
|
|
||||||
|
|
||||||
// 编辑 Outlook 模态框
|
|
||||||
elements.closeEditOutlookModal.addEventListener('click', () => {
|
|
||||||
elements.editOutlookModal.classList.remove('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.cancelEditOutlook.addEventListener('click', () => {
|
|
||||||
elements.editOutlookModal.classList.remove('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.editOutlookForm.addEventListener('submit', handleEditOutlook);
|
|
||||||
|
|
||||||
// 自定义域名全选
|
// 自定义域名全选
|
||||||
elements.selectAllCustom.addEventListener('change', (e) => {
|
elements.selectAllCustom.addEventListener('change', (e) => {
|
||||||
const checkboxes = elements.customTable.querySelectorAll('input[type="checkbox"][data-id]');
|
const checkboxes = elements.customTable.querySelectorAll('input[type="checkbox"][data-id]');
|
||||||
checkboxes.forEach(cb => {
|
checkboxes.forEach(cb => {
|
||||||
cb.checked = e.target.checked;
|
cb.checked = e.target.checked;
|
||||||
const id = parseInt(cb.dataset.id);
|
const id = parseInt(cb.dataset.id);
|
||||||
if (e.target.checked) {
|
if (e.target.checked) selectedCustom.add(id);
|
||||||
selectedCustom.add(id);
|
else selectedCustom.delete(id);
|
||||||
} else {
|
|
||||||
selectedCustom.delete(id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 添加自定义域名
|
||||||
|
elements.addCustomBtn.addEventListener('click', () => {
|
||||||
|
elements.addCustomForm.reset();
|
||||||
|
switchAddSubType('moemail');
|
||||||
|
elements.addCustomModal.classList.add('active');
|
||||||
|
});
|
||||||
|
elements.closeCustomModal.addEventListener('click', () => elements.addCustomModal.classList.remove('active'));
|
||||||
|
elements.cancelAddCustom.addEventListener('click', () => elements.addCustomModal.classList.remove('active'));
|
||||||
|
elements.addCustomForm.addEventListener('submit', handleAddCustom);
|
||||||
|
|
||||||
|
// 类型切换(添加表单)
|
||||||
|
elements.customSubType.addEventListener('change', (e) => switchAddSubType(e.target.value));
|
||||||
|
|
||||||
|
// 编辑自定义域名
|
||||||
|
elements.closeEditCustomModal.addEventListener('click', () => elements.editCustomModal.classList.remove('active'));
|
||||||
|
elements.cancelEditCustom.addEventListener('click', () => elements.editCustomModal.classList.remove('active'));
|
||||||
|
elements.editCustomForm.addEventListener('submit', handleEditCustom);
|
||||||
|
|
||||||
|
// 编辑 Outlook
|
||||||
|
elements.closeEditOutlookModal.addEventListener('click', () => elements.editOutlookModal.classList.remove('active'));
|
||||||
|
elements.cancelEditOutlook.addEventListener('click', () => elements.editOutlookModal.classList.remove('active'));
|
||||||
|
elements.editOutlookForm.addEventListener('submit', handleEditOutlook);
|
||||||
|
|
||||||
// 临时邮箱配置
|
// 临时邮箱配置
|
||||||
elements.tempmailForm.addEventListener('submit', handleSaveTempmail);
|
elements.tempmailForm.addEventListener('submit', handleSaveTempmail);
|
||||||
elements.testTempmailBtn.addEventListener('click', handleTestTempmail);
|
elements.testTempmailBtn.addEventListener('click', handleTestTempmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 切换添加表单子类型
|
||||||
|
function switchAddSubType(subType) {
|
||||||
|
elements.customSubType.value = subType;
|
||||||
|
if (subType === 'moemail') {
|
||||||
|
elements.addMoemailFields.style.display = '';
|
||||||
|
elements.addTempmailFields.style.display = 'none';
|
||||||
|
} else {
|
||||||
|
elements.addMoemailFields.style.display = 'none';
|
||||||
|
elements.addTempmailFields.style.display = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 切换编辑表单子类型显示
|
||||||
|
function switchEditSubType(subType) {
|
||||||
|
elements.editCustomSubTypeHidden.value = subType;
|
||||||
|
const isMoe = subType === 'moemail';
|
||||||
|
elements.editMoemailFields.style.display = isMoe ? '' : 'none';
|
||||||
|
elements.editTempmailFields.style.display = isMoe ? 'none' : '';
|
||||||
|
elements.editCustomTypeBadge.textContent = isMoe ? '🔗 MoeMail(自定义域名 API)' : '📮 TempMail(自部署 Cloudflare Worker)';
|
||||||
|
}
|
||||||
|
|
||||||
// 加载统计信息
|
// 加载统计信息
|
||||||
async function loadStats() {
|
async function loadStats() {
|
||||||
try {
|
try {
|
||||||
const data = await api.get('/email-services/stats');
|
const data = await api.get('/email-services/stats');
|
||||||
elements.outlookCount.textContent = data.outlook_count || 0;
|
elements.outlookCount.textContent = data.outlook_count || 0;
|
||||||
elements.customCount.textContent = data.custom_count || 0;
|
elements.customCount.textContent = (data.custom_count || 0) + (data.temp_mail_count || 0);
|
||||||
elements.tempmailStatus.textContent = data.tempmail_available ? '可用' : '不可用';
|
elements.tempmailStatus.textContent = data.tempmail_available ? '可用' : '不可用';
|
||||||
elements.totalEnabled.textContent = data.enabled_count || 0;
|
elements.totalEnabled.textContent = data.enabled_count || 0;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -196,10 +204,7 @@ async function loadOutlookServices() {
|
|||||||
|
|
||||||
elements.outlookTable.innerHTML = outlookServices.map(service => `
|
elements.outlookTable.innerHTML = outlookServices.map(service => `
|
||||||
<tr data-id="${service.id}">
|
<tr data-id="${service.id}">
|
||||||
<td>
|
<td><input type="checkbox" data-id="${service.id}" ${selectedOutlook.has(service.id) ? 'checked' : ''}></td>
|
||||||
<input type="checkbox" data-id="${service.id}"
|
|
||||||
${selectedOutlook.has(service.id) ? 'checked' : ''}>
|
|
||||||
</td>
|
|
||||||
<td>${escapeHtml(service.config?.email || service.name)}</td>
|
<td>${escapeHtml(service.config?.email || service.name)}</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="status-badge ${service.config?.has_oauth ? 'active' : 'pending'}">
|
<span class="status-badge ${service.config?.has_oauth ? 'active' : 'pending'}">
|
||||||
@@ -215,65 +220,50 @@ async function loadOutlookServices() {
|
|||||||
<td>${format.date(service.last_used)}</td>
|
<td>${format.date(service.last_used)}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
<button class="btn btn-ghost btn-sm" onclick="editOutlookService(${service.id})" title="编辑">
|
<button class="btn btn-ghost btn-sm" onclick="editOutlookService(${service.id})" title="编辑">✏️</button>
|
||||||
✏️
|
<button class="btn btn-ghost btn-sm" onclick="toggleService(${service.id}, ${!service.enabled})" title="${service.enabled ? '禁用' : '启用'}">${service.enabled ? '🔇' : '🔊'}</button>
|
||||||
</button>
|
<button class="btn btn-ghost btn-sm" onclick="testService(${service.id})" title="测试">🔌</button>
|
||||||
<button class="btn btn-ghost btn-sm" onclick="toggleService(${service.id}, ${!service.enabled})" title="${service.enabled ? '禁用' : '启用'}">
|
<button class="btn btn-ghost btn-sm" onclick="deleteService(${service.id}, '${escapeHtml(service.name)}')" title="删除">🗑️</button>
|
||||||
${service.enabled ? '🔇' : '🔊'}
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ghost btn-sm" onclick="testService(${service.id})" title="测试">
|
|
||||||
🔌
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ghost btn-sm" onclick="deleteService(${service.id}, '${escapeHtml(service.name)}')" title="删除">
|
|
||||||
🗑️
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`).join('');
|
`).join('');
|
||||||
|
|
||||||
// 绑定复选框事件
|
|
||||||
elements.outlookTable.querySelectorAll('input[type="checkbox"][data-id]').forEach(cb => {
|
elements.outlookTable.querySelectorAll('input[type="checkbox"][data-id]').forEach(cb => {
|
||||||
cb.addEventListener('change', (e) => {
|
cb.addEventListener('change', (e) => {
|
||||||
const id = parseInt(e.target.dataset.id);
|
const id = parseInt(e.target.dataset.id);
|
||||||
if (e.target.checked) {
|
if (e.target.checked) selectedOutlook.add(id);
|
||||||
selectedOutlook.add(id);
|
else selectedOutlook.delete(id);
|
||||||
} else {
|
|
||||||
selectedOutlook.delete(id);
|
|
||||||
}
|
|
||||||
updateBatchButtons();
|
updateBatchButtons();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载 Outlook 服务失败:', error);
|
console.error('加载 Outlook 服务失败:', error);
|
||||||
elements.outlookTable.innerHTML = `
|
elements.outlookTable.innerHTML = `<tr><td colspan="7"><div class="empty-state"><div class="empty-state-icon">❌</div><div class="empty-state-title">加载失败</div></div></td></tr>`;
|
||||||
<tr>
|
|
||||||
<td colspan="7">
|
|
||||||
<div class="empty-state">
|
|
||||||
<div class="empty-state-icon">❌</div>
|
|
||||||
<div class="empty-state-title">加载失败</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载自定义域名服务
|
// 加载自定义域名服务(custom_domain + temp_mail 合并)
|
||||||
async function loadCustomServices() {
|
async function loadCustomServices() {
|
||||||
try {
|
try {
|
||||||
const data = await api.get('/email-services?service_type=custom_domain');
|
const [r1, r2] = await Promise.all([
|
||||||
customServices = data.services || [];
|
api.get('/email-services?service_type=custom_domain'),
|
||||||
|
api.get('/email-services?service_type=temp_mail')
|
||||||
|
]);
|
||||||
|
customServices = [
|
||||||
|
...(r1.services || []).map(s => ({ ...s, _subType: 'moemail' })),
|
||||||
|
...(r2.services || []).map(s => ({ ...s, _subType: 'tempmail' }))
|
||||||
|
];
|
||||||
|
|
||||||
if (customServices.length === 0) {
|
if (customServices.length === 0) {
|
||||||
elements.customTable.innerHTML = `
|
elements.customTable.innerHTML = `
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7">
|
<td colspan="8">
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<div class="empty-state-icon">📭</div>
|
<div class="empty-state-icon">📭</div>
|
||||||
<div class="empty-state-title">暂无自定义域名服务</div>
|
<div class="empty-state-title">暂无自定义域名服务</div>
|
||||||
<div class="empty-state-description">点击"添加服务"按钮创建新服务</div>
|
<div class="empty-state-description">点击「添加服务」按钮创建新服务</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -281,49 +271,35 @@ async function loadCustomServices() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.customTable.innerHTML = customServices.map(service => `
|
elements.customTable.innerHTML = customServices.map(service => {
|
||||||
|
const isMoe = service._subType === 'moemail';
|
||||||
|
const typeLabel = isMoe ? '<span class="status-badge info">MoeMail</span>' : '<span class="status-badge warning">TempMail</span>';
|
||||||
|
const addr = isMoe ? (service.config?.base_url || '-') : (service.config?.base_url || '-');
|
||||||
|
return `
|
||||||
<tr data-id="${service.id}">
|
<tr data-id="${service.id}">
|
||||||
<td>
|
<td><input type="checkbox" data-id="${service.id}" ${selectedCustom.has(service.id) ? 'checked' : ''}></td>
|
||||||
<input type="checkbox" data-id="${service.id}"
|
|
||||||
${selectedCustom.has(service.id) ? 'checked' : ''}>
|
|
||||||
</td>
|
|
||||||
<td>${escapeHtml(service.name)}</td>
|
<td>${escapeHtml(service.name)}</td>
|
||||||
<td style="font-size: 0.75rem;">${escapeHtml(service.config?.base_url || '-')}</td>
|
<td>${typeLabel}</td>
|
||||||
<td>
|
<td style="font-size: 0.75rem;">${escapeHtml(addr)}</td>
|
||||||
<span class="status-badge ${service.enabled ? 'active' : 'disabled'}">
|
<td><span class="status-badge ${service.enabled ? 'active' : 'disabled'}">${service.enabled ? '启用' : '禁用'}</span></td>
|
||||||
${service.enabled ? '启用' : '禁用'}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>${service.priority}</td>
|
<td>${service.priority}</td>
|
||||||
<td>${format.date(service.last_used)}</td>
|
<td>${format.date(service.last_used)}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
<button class="btn btn-ghost btn-sm" onclick="editCustomService(${service.id})" title="编辑">
|
<button class="btn btn-ghost btn-sm" onclick="editCustomService(${service.id}, '${service._subType}')" title="编辑">✏️</button>
|
||||||
✏️
|
<button class="btn btn-ghost btn-sm" onclick="toggleService(${service.id}, ${!service.enabled})" title="${service.enabled ? '禁用' : '启用'}">${service.enabled ? '🔇' : '🔊'}</button>
|
||||||
</button>
|
<button class="btn btn-ghost btn-sm" onclick="testService(${service.id})" title="测试">🔌</button>
|
||||||
<button class="btn btn-ghost btn-sm" onclick="toggleService(${service.id}, ${!service.enabled})" title="${service.enabled ? '禁用' : '启用'}">
|
<button class="btn btn-ghost btn-sm" onclick="deleteService(${service.id}, '${escapeHtml(service.name)}')" title="删除">🗑️</button>
|
||||||
${service.enabled ? '🔇' : '🔊'}
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ghost btn-sm" onclick="testService(${service.id})" title="测试">
|
|
||||||
🔌
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ghost btn-sm" onclick="deleteService(${service.id}, '${escapeHtml(service.name)}')" title="删除">
|
|
||||||
🗑️
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>`;
|
||||||
`).join('');
|
}).join('');
|
||||||
|
|
||||||
// 绑定复选框事件
|
|
||||||
elements.customTable.querySelectorAll('input[type="checkbox"][data-id]').forEach(cb => {
|
elements.customTable.querySelectorAll('input[type="checkbox"][data-id]').forEach(cb => {
|
||||||
cb.addEventListener('change', (e) => {
|
cb.addEventListener('change', (e) => {
|
||||||
const id = parseInt(e.target.dataset.id);
|
const id = parseInt(e.target.dataset.id);
|
||||||
if (e.target.checked) {
|
if (e.target.checked) selectedCustom.add(id);
|
||||||
selectedCustom.add(id);
|
else selectedCustom.delete(id);
|
||||||
} else {
|
|
||||||
selectedCustom.delete(id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -348,10 +324,7 @@ async function loadTempmailConfig() {
|
|||||||
// Outlook 导入
|
// Outlook 导入
|
||||||
async function handleOutlookImport() {
|
async function handleOutlookImport() {
|
||||||
const data = elements.outlookImportData.value.trim();
|
const data = elements.outlookImportData.value.trim();
|
||||||
if (!data) {
|
if (!data) { toast.error('请输入导入数据'); return; }
|
||||||
toast.error('请输入导入数据');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
elements.outlookImportBtn.disabled = true;
|
elements.outlookImportBtn.disabled = true;
|
||||||
elements.outlookImportBtn.textContent = '导入中...';
|
elements.outlookImportBtn.textContent = '导入中...';
|
||||||
@@ -366,26 +339,18 @@ async function handleOutlookImport() {
|
|||||||
elements.importResult.style.display = 'block';
|
elements.importResult.style.display = 'block';
|
||||||
elements.importResult.innerHTML = `
|
elements.importResult.innerHTML = `
|
||||||
<div class="import-stats">
|
<div class="import-stats">
|
||||||
<span>✅ 成功导入: <strong>${result.success_count || 0}</strong></span>
|
<span>✅ 成功导入: <strong>${result.success || 0}</strong></span>
|
||||||
<span>❌ 失败: <strong>${result.failed_count || 0}</strong></span>
|
<span>❌ 失败: <strong>${result.failed || 0}</strong></span>
|
||||||
</div>
|
</div>
|
||||||
${result.errors?.length ? `
|
${result.errors?.length ? `<div class="import-errors" style="margin-top: var(--spacing-sm);"><strong>错误详情:</strong><ul>${result.errors.map(e => `<li>${escapeHtml(e)}</li>`).join('')}</ul></div>` : ''}
|
||||||
<div class="import-errors" style="margin-top: var(--spacing-sm);">
|
|
||||||
<strong>错误详情:</strong>
|
|
||||||
<ul>
|
|
||||||
${result.errors.map(e => `<li>${escapeHtml(e)}</li>`).join('')}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
` : ''}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (result.success_count > 0) {
|
if (result.success > 0) {
|
||||||
toast.success(`成功导入 ${result.success_count} 个账户`);
|
toast.success(`成功导入 ${result.success} 个账户`);
|
||||||
loadOutlookServices();
|
loadOutlookServices();
|
||||||
loadStats();
|
loadStats();
|
||||||
elements.outlookImportData.value = '';
|
elements.outlookImportData.value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('导入失败: ' + error.message);
|
toast.error('导入失败: ' + error.message);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -394,19 +359,34 @@ async function handleOutlookImport() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加自定义域名服务
|
// 添加自定义域名服务(根据子类型区分)
|
||||||
async function handleAddCustom(e) {
|
async function handleAddCustom(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const formData = new FormData(e.target);
|
const formData = new FormData(e.target);
|
||||||
const data = {
|
const subType = formData.get('sub_type');
|
||||||
service_type: 'custom_domain',
|
|
||||||
name: formData.get('name'),
|
let serviceType, config;
|
||||||
config: {
|
if (subType === 'moemail') {
|
||||||
|
serviceType = 'custom_domain';
|
||||||
|
config = {
|
||||||
base_url: formData.get('api_url'),
|
base_url: formData.get('api_url'),
|
||||||
api_key: formData.get('api_key'),
|
api_key: formData.get('api_key'),
|
||||||
default_domain: formData.get('domain')
|
default_domain: formData.get('domain')
|
||||||
},
|
};
|
||||||
|
} else {
|
||||||
|
serviceType = 'temp_mail';
|
||||||
|
config = {
|
||||||
|
base_url: formData.get('tm_base_url'),
|
||||||
|
admin_password: formData.get('tm_admin_password'),
|
||||||
|
domain: formData.get('tm_domain'),
|
||||||
|
enable_prefix: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
service_type: serviceType,
|
||||||
|
name: formData.get('name'),
|
||||||
|
config,
|
||||||
enabled: formData.get('enabled') === 'on',
|
enabled: formData.get('enabled') === 'on',
|
||||||
priority: parseInt(formData.get('priority')) || 0
|
priority: parseInt(formData.get('priority')) || 0
|
||||||
};
|
};
|
||||||
@@ -440,11 +420,8 @@ async function toggleService(id, enabled) {
|
|||||||
async function testService(id) {
|
async function testService(id) {
|
||||||
try {
|
try {
|
||||||
const result = await api.post(`/email-services/${id}/test`);
|
const result = await api.post(`/email-services/${id}/test`);
|
||||||
if (result.success) {
|
if (result.success) toast.success('测试成功');
|
||||||
toast.success('测试成功');
|
else toast.error('测试失败: ' + (result.error || '未知错误'));
|
||||||
} else {
|
|
||||||
toast.error('测试失败: ' + (result.error || '未知错误'));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('测试失败: ' + error.message);
|
toast.error('测试失败: ' + error.message);
|
||||||
}
|
}
|
||||||
@@ -454,7 +431,6 @@ async function testService(id) {
|
|||||||
async function deleteService(id, name) {
|
async function deleteService(id, name) {
|
||||||
const confirmed = await confirm(`确定要删除 "${name}" 吗?`);
|
const confirmed = await confirm(`确定要删除 "${name}" 吗?`);
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.delete(`/email-services/${id}`);
|
await api.delete(`/email-services/${id}`);
|
||||||
toast.success('已删除');
|
toast.success('已删除');
|
||||||
@@ -471,10 +447,8 @@ async function deleteService(id, name) {
|
|||||||
// 批量删除 Outlook
|
// 批量删除 Outlook
|
||||||
async function handleBatchDeleteOutlook() {
|
async function handleBatchDeleteOutlook() {
|
||||||
if (selectedOutlook.size === 0) return;
|
if (selectedOutlook.size === 0) return;
|
||||||
|
|
||||||
const confirmed = await confirm(`确定要删除选中的 ${selectedOutlook.size} 个账户吗?`);
|
const confirmed = await confirm(`确定要删除选中的 ${selectedOutlook.size} 个账户吗?`);
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await api.request('/email-services/outlook/batch', {
|
const result = await api.request('/email-services/outlook/batch', {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
@@ -492,7 +466,6 @@ async function handleBatchDeleteOutlook() {
|
|||||||
// 保存临时邮箱配置
|
// 保存临时邮箱配置
|
||||||
async function handleSaveTempmail(e) {
|
async function handleSaveTempmail(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.post('/settings/tempmail', {
|
await api.post('/settings/tempmail', {
|
||||||
api_url: elements.tempmailApi.value,
|
api_url: elements.tempmailApi.value,
|
||||||
@@ -508,17 +481,12 @@ async function handleSaveTempmail(e) {
|
|||||||
async function handleTestTempmail() {
|
async function handleTestTempmail() {
|
||||||
elements.testTempmailBtn.disabled = true;
|
elements.testTempmailBtn.disabled = true;
|
||||||
elements.testTempmailBtn.textContent = '测试中...';
|
elements.testTempmailBtn.textContent = '测试中...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await api.post('/email-services/test-tempmail', {
|
const result = await api.post('/email-services/test-tempmail', {
|
||||||
api_url: elements.tempmailApi.value
|
api_url: elements.tempmailApi.value
|
||||||
});
|
});
|
||||||
|
if (result.success) toast.success('临时邮箱连接正常');
|
||||||
if (result.success) {
|
else toast.error('连接失败: ' + (result.error || '未知错误'));
|
||||||
toast.success('临时邮箱连接正常');
|
|
||||||
} else {
|
|
||||||
toast.error('连接失败: ' + (result.error || '未知错误'));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('测试失败: ' + error.message);
|
toast.error('测试失败: ' + error.message);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -544,27 +512,32 @@ function escapeHtml(text) {
|
|||||||
|
|
||||||
// ============== 编辑功能 ==============
|
// ============== 编辑功能 ==============
|
||||||
|
|
||||||
// 编辑自定义域名服务
|
// 编辑自定义域名服务(支持 moemail / tempmail)
|
||||||
async function editCustomService(id) {
|
async function editCustomService(id, subType) {
|
||||||
try {
|
try {
|
||||||
// 获取完整的服务详情
|
|
||||||
const service = await api.get(`/email-services/${id}/full`);
|
const service = await api.get(`/email-services/${id}/full`);
|
||||||
|
const resolvedSubType = subType || (service.service_type === 'temp_mail' ? 'tempmail' : 'moemail');
|
||||||
|
|
||||||
// 填充表单
|
|
||||||
document.getElementById('edit-custom-id').value = service.id;
|
document.getElementById('edit-custom-id').value = service.id;
|
||||||
document.getElementById('edit-custom-name').value = service.name || '';
|
document.getElementById('edit-custom-name').value = service.name || '';
|
||||||
document.getElementById('edit-custom-api-url').value = service.config?.base_url || '';
|
|
||||||
document.getElementById('edit-custom-api-key').value = service.config?.api_key || '';
|
|
||||||
document.getElementById('edit-custom-domain').value = service.config?.domain || '';
|
|
||||||
document.getElementById('edit-custom-priority').value = service.priority || 0;
|
document.getElementById('edit-custom-priority').value = service.priority || 0;
|
||||||
document.getElementById('edit-custom-enabled').checked = service.enabled;
|
document.getElementById('edit-custom-enabled').checked = service.enabled;
|
||||||
|
|
||||||
// 清空密码提示
|
switchEditSubType(resolvedSubType);
|
||||||
document.getElementById('edit-custom-api-key').placeholder = service.config?.has_api_key ? '已设置,留空保持不变' : 'API Key';
|
|
||||||
|
if (resolvedSubType === 'moemail') {
|
||||||
|
document.getElementById('edit-custom-api-url').value = service.config?.base_url || '';
|
||||||
|
document.getElementById('edit-custom-api-key').value = '';
|
||||||
|
document.getElementById('edit-custom-api-key').placeholder = service.config?.has_api_key ? '已设置,留空保持不变' : 'API Key';
|
||||||
|
document.getElementById('edit-custom-domain').value = service.config?.default_domain || service.config?.domain || '';
|
||||||
|
} else {
|
||||||
|
document.getElementById('edit-tm-base-url').value = service.config?.base_url || '';
|
||||||
|
document.getElementById('edit-tm-admin-password').value = '';
|
||||||
|
document.getElementById('edit-tm-admin-password').placeholder = service.config?.admin_password ? '已设置,留空保持不变' : '请输入 Admin 密码';
|
||||||
|
document.getElementById('edit-tm-domain').value = service.config?.domain || '';
|
||||||
|
}
|
||||||
|
|
||||||
// 显示模态框
|
|
||||||
elements.editCustomModal.classList.add('active');
|
elements.editCustomModal.classList.add('active');
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('获取服务信息失败: ' + error.message);
|
toast.error('获取服务信息失败: ' + error.message);
|
||||||
}
|
}
|
||||||
@@ -573,31 +546,35 @@ async function editCustomService(id) {
|
|||||||
// 保存编辑自定义域名服务
|
// 保存编辑自定义域名服务
|
||||||
async function handleEditCustom(e) {
|
async function handleEditCustom(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const id = document.getElementById('edit-custom-id').value;
|
const id = document.getElementById('edit-custom-id').value;
|
||||||
const formData = new FormData(e.target);
|
const formData = new FormData(e.target);
|
||||||
|
const subType = formData.get('sub_type');
|
||||||
|
|
||||||
|
let config;
|
||||||
|
if (subType === 'moemail') {
|
||||||
|
config = {
|
||||||
|
base_url: formData.get('api_url'),
|
||||||
|
default_domain: formData.get('domain')
|
||||||
|
};
|
||||||
|
const apiKey = formData.get('api_key');
|
||||||
|
if (apiKey && apiKey.trim()) config.api_key = apiKey.trim();
|
||||||
|
} else {
|
||||||
|
config = {
|
||||||
|
base_url: formData.get('tm_base_url'),
|
||||||
|
domain: formData.get('tm_domain'),
|
||||||
|
enable_prefix: true
|
||||||
|
};
|
||||||
|
const pwd = formData.get('tm_admin_password');
|
||||||
|
if (pwd && pwd.trim()) config.admin_password = pwd.trim();
|
||||||
|
}
|
||||||
|
|
||||||
// 构建更新数据
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
name: formData.get('name'),
|
name: formData.get('name'),
|
||||||
priority: parseInt(formData.get('priority')) || 0,
|
priority: parseInt(formData.get('priority')) || 0,
|
||||||
enabled: formData.get('enabled') === 'on'
|
enabled: formData.get('enabled') === 'on',
|
||||||
|
config
|
||||||
};
|
};
|
||||||
|
|
||||||
// 构建配置
|
|
||||||
const config = {
|
|
||||||
base_url: formData.get('api_url'),
|
|
||||||
default_domain: formData.get('domain')
|
|
||||||
};
|
|
||||||
|
|
||||||
// 只有在填写了 API Key 时才更新
|
|
||||||
const apiKey = formData.get('api_key');
|
|
||||||
if (apiKey && apiKey.trim()) {
|
|
||||||
config.api_key = apiKey.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateData.config = config;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.patch(`/email-services/${id}`, updateData);
|
await api.patch(`/email-services/${id}`, updateData);
|
||||||
toast.success('服务更新成功');
|
toast.success('服务更新成功');
|
||||||
@@ -612,10 +589,7 @@ async function handleEditCustom(e) {
|
|||||||
// 编辑 Outlook 服务
|
// 编辑 Outlook 服务
|
||||||
async function editOutlookService(id) {
|
async function editOutlookService(id) {
|
||||||
try {
|
try {
|
||||||
// 获取完整的服务详情
|
|
||||||
const service = await api.get(`/email-services/${id}/full`);
|
const service = await api.get(`/email-services/${id}/full`);
|
||||||
|
|
||||||
// 填充表单
|
|
||||||
document.getElementById('edit-outlook-id').value = service.id;
|
document.getElementById('edit-outlook-id').value = service.id;
|
||||||
document.getElementById('edit-outlook-email').value = service.config?.email || service.name || '';
|
document.getElementById('edit-outlook-email').value = service.config?.email || service.name || '';
|
||||||
document.getElementById('edit-outlook-password').value = '';
|
document.getElementById('edit-outlook-password').value = '';
|
||||||
@@ -625,10 +599,7 @@ async function editOutlookService(id) {
|
|||||||
document.getElementById('edit-outlook-refresh-token').placeholder = service.config?.refresh_token ? '已设置,留空保持不变' : 'OAuth Refresh Token';
|
document.getElementById('edit-outlook-refresh-token').placeholder = service.config?.refresh_token ? '已设置,留空保持不变' : 'OAuth Refresh Token';
|
||||||
document.getElementById('edit-outlook-priority').value = service.priority || 0;
|
document.getElementById('edit-outlook-priority').value = service.priority || 0;
|
||||||
document.getElementById('edit-outlook-enabled').checked = service.enabled;
|
document.getElementById('edit-outlook-enabled').checked = service.enabled;
|
||||||
|
|
||||||
// 显示模态框
|
|
||||||
elements.editOutlookModal.classList.add('active');
|
elements.editOutlookModal.classList.add('active');
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('获取服务信息失败: ' + error.message);
|
toast.error('获取服务信息失败: ' + error.message);
|
||||||
}
|
}
|
||||||
@@ -637,11 +608,9 @@ async function editOutlookService(id) {
|
|||||||
// 保存编辑 Outlook 服务
|
// 保存编辑 Outlook 服务
|
||||||
async function handleEditOutlook(e) {
|
async function handleEditOutlook(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const id = document.getElementById('edit-outlook-id').value;
|
const id = document.getElementById('edit-outlook-id').value;
|
||||||
const formData = new FormData(e.target);
|
const formData = new FormData(e.target);
|
||||||
|
|
||||||
// 获取当前服务信息以保留未修改的敏感字段
|
|
||||||
let currentService;
|
let currentService;
|
||||||
try {
|
try {
|
||||||
currentService = await api.get(`/email-services/${id}/full`);
|
currentService = await api.get(`/email-services/${id}/full`);
|
||||||
@@ -650,23 +619,18 @@ async function handleEditOutlook(e) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建更新数据
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
name: formData.get('email'), // 使用邮箱作为名称
|
name: formData.get('email'),
|
||||||
priority: parseInt(formData.get('priority')) || 0,
|
priority: parseInt(formData.get('priority')) || 0,
|
||||||
enabled: formData.get('enabled') === 'on'
|
enabled: formData.get('enabled') === 'on',
|
||||||
|
config: {
|
||||||
|
email: formData.get('email'),
|
||||||
|
password: formData.get('password')?.trim() || currentService.config?.password || '',
|
||||||
|
client_id: formData.get('client_id')?.trim() || currentService.config?.client_id || '',
|
||||||
|
refresh_token: formData.get('refresh_token')?.trim() || currentService.config?.refresh_token || ''
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 构建配置,保留未修改的敏感字段
|
|
||||||
const config = {
|
|
||||||
email: formData.get('email'),
|
|
||||||
password: formData.get('password')?.trim() || currentService.config?.password || '',
|
|
||||||
client_id: formData.get('client_id')?.trim() || currentService.config?.client_id || '',
|
|
||||||
refresh_token: formData.get('refresh_token')?.trim() || currentService.config?.refresh_token || ''
|
|
||||||
};
|
|
||||||
|
|
||||||
updateData.config = config;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.patch(`/email-services/${id}`, updateData);
|
await api.patch(`/email-services/${id}`, updateData);
|
||||||
toast.success('账户更新成功');
|
toast.success('账户更新成功');
|
||||||
|
|||||||
146
static/js/payment.js
Normal file
146
static/js/payment.js
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
/**
|
||||||
|
* 支付页面 JavaScript
|
||||||
|
*/
|
||||||
|
|
||||||
|
const COUNTRY_CURRENCY_MAP = {
|
||||||
|
SG: 'SGD', US: 'USD', TR: 'TRY', JP: 'JPY',
|
||||||
|
HK: 'HKD', GB: 'GBP', EU: 'EUR', AU: 'AUD',
|
||||||
|
CA: 'CAD', IN: 'INR', BR: 'BRL', MX: 'MXN',
|
||||||
|
};
|
||||||
|
|
||||||
|
let selectedPlan = 'plus';
|
||||||
|
let generatedLink = '';
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
loadAccounts();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 加载账号列表
|
||||||
|
async function loadAccounts() {
|
||||||
|
try {
|
||||||
|
const resp = await fetch('/api/accounts?page=1&page_size=100&status=active');
|
||||||
|
const data = await resp.json();
|
||||||
|
const sel = document.getElementById('account-select');
|
||||||
|
sel.innerHTML = '<option value="">-- 请选择账号 --</option>';
|
||||||
|
(data.accounts || []).forEach(acc => {
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = acc.id;
|
||||||
|
opt.textContent = acc.email;
|
||||||
|
sel.appendChild(opt);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('加载账号失败:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 国家切换
|
||||||
|
function onCountryChange() {
|
||||||
|
const country = document.getElementById('country-select').value;
|
||||||
|
const currency = COUNTRY_CURRENCY_MAP[country] || 'USD';
|
||||||
|
document.getElementById('currency-display').value = currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择套餐
|
||||||
|
function selectPlan(plan) {
|
||||||
|
selectedPlan = plan;
|
||||||
|
document.getElementById('plan-plus').classList.toggle('selected', plan === 'plus');
|
||||||
|
document.getElementById('plan-team').classList.toggle('selected', plan === 'team');
|
||||||
|
document.getElementById('team-options').classList.toggle('show', plan === 'team');
|
||||||
|
// 隐藏已生成的链接
|
||||||
|
document.getElementById('link-box').classList.remove('show');
|
||||||
|
generatedLink = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成支付链接
|
||||||
|
async function generateLink() {
|
||||||
|
const accountId = document.getElementById('account-select').value;
|
||||||
|
if (!accountId) {
|
||||||
|
ui.showToast('请先选择账号', 'warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const country = document.getElementById('country-select').value || 'SG';
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
account_id: parseInt(accountId),
|
||||||
|
plan_type: selectedPlan,
|
||||||
|
country: country,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (selectedPlan === 'team') {
|
||||||
|
body.workspace_name = document.getElementById('workspace-name').value || 'MyTeam';
|
||||||
|
body.seat_quantity = parseInt(document.getElementById('seat-quantity').value) || 5;
|
||||||
|
body.price_interval = document.getElementById('price-interval').value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const btn = document.querySelector('.form-actions .btn-primary');
|
||||||
|
if (btn) { btn.disabled = true; btn.textContent = '生成中...'; }
|
||||||
|
|
||||||
|
try {
|
||||||
|
const resp = await fetch('/api/payment/generate-link', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
const data = await resp.json();
|
||||||
|
if (data.success && data.link) {
|
||||||
|
generatedLink = data.link;
|
||||||
|
document.getElementById('link-text').value = data.link;
|
||||||
|
document.getElementById('link-box').classList.add('show');
|
||||||
|
document.getElementById('open-status').textContent = '';
|
||||||
|
ui.showToast('支付链接生成成功', 'success');
|
||||||
|
} else {
|
||||||
|
ui.showToast(data.detail || '生成链接失败', 'error');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
ui.showToast('请求失败: ' + e.message, 'error');
|
||||||
|
} finally {
|
||||||
|
if (btn) { btn.disabled = false; btn.textContent = '生成支付链接'; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 复制链接
|
||||||
|
function copyLink() {
|
||||||
|
if (!generatedLink) return;
|
||||||
|
navigator.clipboard.writeText(generatedLink).then(() => {
|
||||||
|
ui.showToast('已复制到剪贴板', 'success');
|
||||||
|
}).catch(() => {
|
||||||
|
const ta = document.getElementById('link-text');
|
||||||
|
ta.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
ui.showToast('已复制到剪贴板', 'success');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 无痕打开浏览器(携带账号 cookie)
|
||||||
|
async function openIncognito() {
|
||||||
|
if (!generatedLink) {
|
||||||
|
ui.showToast('请先生成链接', 'warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const accountId = document.getElementById('account-select').value;
|
||||||
|
const statusEl = document.getElementById('open-status');
|
||||||
|
statusEl.textContent = '正在打开...';
|
||||||
|
try {
|
||||||
|
const body = { url: generatedLink };
|
||||||
|
if (accountId) body.account_id = parseInt(accountId);
|
||||||
|
|
||||||
|
const resp = await fetch('/api/payment/open-incognito', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
const data = await resp.json();
|
||||||
|
if (data.success) {
|
||||||
|
statusEl.textContent = '已在无痕模式打开浏览器';
|
||||||
|
ui.showToast('无痕浏览器已打开', 'success');
|
||||||
|
} else {
|
||||||
|
statusEl.textContent = data.message || '未找到可用浏览器,请手动复制链接';
|
||||||
|
ui.showToast(data.message || '未找到浏览器', 'warning');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
statusEl.textContent = '请求失败: ' + e.message;
|
||||||
|
ui.showToast('请求失败', 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,6 +44,9 @@ const elements = {
|
|||||||
// CPA 设置
|
// CPA 设置
|
||||||
cpaForm: document.getElementById('cpa-form'),
|
cpaForm: document.getElementById('cpa-form'),
|
||||||
testCpaBtn: document.getElementById('test-cpa-btn'),
|
testCpaBtn: document.getElementById('test-cpa-btn'),
|
||||||
|
// Team Manager 设置
|
||||||
|
tmForm: document.getElementById('tm-form'),
|
||||||
|
testTmBtn: document.getElementById('test-tm-btn'),
|
||||||
// 验证码设置
|
// 验证码设置
|
||||||
emailCodeForm: document.getElementById('email-code-form'),
|
emailCodeForm: document.getElementById('email-code-form'),
|
||||||
// Outlook 设置
|
// Outlook 设置
|
||||||
@@ -236,6 +239,12 @@ function initEventListeners() {
|
|||||||
|
|
||||||
if (elements.webuiSettingsForm) {
|
if (elements.webuiSettingsForm) {
|
||||||
elements.webuiSettingsForm.addEventListener('submit', handleSaveWebuiSettings);
|
elements.webuiSettingsForm.addEventListener('submit', handleSaveWebuiSettings);
|
||||||
|
// Team Manager 设置
|
||||||
|
if (elements.tmForm) {
|
||||||
|
elements.tmForm.addEventListener('submit', handleSaveTm);
|
||||||
|
}
|
||||||
|
if (elements.testTmBtn) {
|
||||||
|
elements.testTmBtn.addEventListener('click', handleTestTm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,6 +283,8 @@ async function loadSettings() {
|
|||||||
loadCpaSettings();
|
loadCpaSettings();
|
||||||
// 加载 Outlook 设置
|
// 加载 Outlook 设置
|
||||||
loadOutlookSettings();
|
loadOutlookSettings();
|
||||||
|
// 加载 Team Manager 设置
|
||||||
|
loadTmSettings();
|
||||||
|
|
||||||
// Web UI 访问密码提示
|
// Web UI 访问密码提示
|
||||||
if (data.webui?.has_access_password) {
|
if (data.webui?.has_access_password) {
|
||||||
@@ -1100,3 +1111,73 @@ async function handleTestDynamicProxy() {
|
|||||||
btn.textContent = '🔌 测试动态代理';
|
btn.textContent = '🔌 测试动态代理';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============== Team Manager 设置 ==============
|
||||||
|
|
||||||
|
async function loadTmSettings() {
|
||||||
|
try {
|
||||||
|
const data = await api.get('/settings/team-manager');
|
||||||
|
document.getElementById('tm-enabled').checked = data.enabled || false;
|
||||||
|
document.getElementById('tm-api-url').value = data.api_url || '';
|
||||||
|
document.getElementById('tm-api-key').value = '';
|
||||||
|
document.getElementById('tm-api-key').placeholder = data.has_api_key ? '已配置,留空保持不变' : '请输入 API Key';
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载 Team Manager 设置失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSaveTm(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const data = {
|
||||||
|
enabled: document.getElementById('tm-enabled').checked,
|
||||||
|
api_url: document.getElementById('tm-api-url').value,
|
||||||
|
api_key: document.getElementById('tm-api-key').value || ''
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await api.post('/settings/team-manager', data);
|
||||||
|
toast.success('Team Manager 设置已保存');
|
||||||
|
loadTmSettings();
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('保存失败: ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleTestTm() {
|
||||||
|
const apiUrl = document.getElementById('tm-api-url').value;
|
||||||
|
const apiKey = document.getElementById('tm-api-key').value;
|
||||||
|
|
||||||
|
if (!apiUrl) {
|
||||||
|
toast.error('请先填写 API URL');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let keyToTest = apiKey;
|
||||||
|
if (!keyToTest) {
|
||||||
|
const saved = await api.get('/settings/team-manager');
|
||||||
|
if (!saved.has_api_key) {
|
||||||
|
toast.error('请先填写 API Key');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
keyToTest = 'use_saved_key';
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.testTmBtn.disabled = true;
|
||||||
|
elements.testTmBtn.innerHTML = '<span class="loading-spinner"></span> 测试中...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await api.post('/settings/team-manager/test', {
|
||||||
|
api_url: apiUrl,
|
||||||
|
api_key: keyToTest
|
||||||
|
});
|
||||||
|
if (result.success) {
|
||||||
|
toast.success(result.message);
|
||||||
|
} else {
|
||||||
|
toast.error(result.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('测试失败: ' + error.message);
|
||||||
|
} finally {
|
||||||
|
elements.testTmBtn.disabled = false;
|
||||||
|
elements.testTmBtn.textContent = '🔌 测试连接';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -351,7 +351,8 @@ const statusMap = {
|
|||||||
service: {
|
service: {
|
||||||
tempmail: 'Tempmail.lol',
|
tempmail: 'Tempmail.lol',
|
||||||
outlook: 'Outlook',
|
outlook: 'Outlook',
|
||||||
custom_domain: '自定义域名'
|
custom_domain: '自定义域名',
|
||||||
|
temp_mail: 'Temp-Mail(自部署)'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
<a href="/" class="nav-link">注册</a>
|
<a href="/" class="nav-link">注册</a>
|
||||||
<a href="/accounts" class="nav-link active">账号管理</a>
|
<a href="/accounts" class="nav-link active">账号管理</a>
|
||||||
<a href="/email-services" class="nav-link">邮箱服务</a>
|
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||||
|
<a href="/payment" class="nav-link">支付</a>
|
||||||
<a href="/settings" class="nav-link">设置</a>
|
<a href="/settings" class="nav-link">设置</a>
|
||||||
<a href="/logout" class="nav-link">退出</a>
|
<a href="/logout" class="nav-link">退出</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -127,6 +128,12 @@
|
|||||||
<button class="btn btn-success" id="batch-upload-cpa-btn" disabled title="批量上传到CPA">
|
<button class="btn btn-success" id="batch-upload-cpa-btn" disabled title="批量上传到CPA">
|
||||||
☁️ 上传CPA
|
☁️ 上传CPA
|
||||||
</button>
|
</button>
|
||||||
|
<button class="btn btn-info" id="batch-check-sub-btn" disabled title="批量检测订阅状态">
|
||||||
|
🔍 检测订阅
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-success" id="batch-upload-tm-btn" disabled title="批量上传到Team Manager">
|
||||||
|
🚀 上传TM
|
||||||
|
</button>
|
||||||
<button class="btn btn-danger" id="batch-delete-btn" disabled>
|
<button class="btn btn-danger" id="batch-delete-btn" disabled>
|
||||||
🗑️ 批量删除
|
🗑️ 批量删除
|
||||||
</button>
|
</button>
|
||||||
@@ -138,6 +145,7 @@
|
|||||||
<a href="#" class="dropdown-item" data-format="json">导出 JSON</a>
|
<a href="#" class="dropdown-item" data-format="json">导出 JSON</a>
|
||||||
<a href="#" class="dropdown-item" data-format="csv">导出 CSV</a>
|
<a href="#" class="dropdown-item" data-format="csv">导出 CSV</a>
|
||||||
<a href="#" class="dropdown-item" data-format="cpa">导出 CPA 格式</a>
|
<a href="#" class="dropdown-item" data-format="cpa">导出 CPA 格式</a>
|
||||||
|
<a href="#" class="dropdown-item" data-format="sub2api">导出 Sub2Api 格式</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -158,13 +166,14 @@
|
|||||||
<th style="width: 120px;">邮箱服务</th>
|
<th style="width: 120px;">邮箱服务</th>
|
||||||
<th style="width: 80px;">状态</th>
|
<th style="width: 80px;">状态</th>
|
||||||
<th style="width: 80px;">CPA</th>
|
<th style="width: 80px;">CPA</th>
|
||||||
|
<th style="width: 80px;">订阅</th>
|
||||||
<th style="width: 140px;">最后刷新</th>
|
<th style="width: 140px;">最后刷新</th>
|
||||||
<th style="width: 150px;">操作</th>
|
<th style="width: 170px;">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="accounts-table">
|
<tbody id="accounts-table">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="9">
|
<td colspan="11">
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<div class="skeleton skeleton-text" style="width: 60%;"></div>
|
<div class="skeleton skeleton-text" style="width: 60%;"></div>
|
||||||
<div class="skeleton skeleton-text" style="width: 80%;"></div>
|
<div class="skeleton skeleton-text" style="width: 80%;"></div>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<a href="/" class="nav-link">注册</a>
|
<a href="/" class="nav-link">注册</a>
|
||||||
<a href="/accounts" class="nav-link">账号管理</a>
|
<a href="/accounts" class="nav-link">账号管理</a>
|
||||||
<a href="/email-services" class="nav-link active">邮箱服务</a>
|
<a href="/email-services" class="nav-link active">邮箱服务</a>
|
||||||
|
<a href="/payment" class="nav-link">支付</a>
|
||||||
<a href="/settings" class="nav-link">设置</a>
|
<a href="/settings" class="nav-link">设置</a>
|
||||||
<a href="/logout" class="nav-link">退出</a>
|
<a href="/logout" class="nav-link">退出</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -92,7 +93,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 自定义域名管理 -->
|
<!-- 自定义域名管理(含 MoeMail / TempMail) -->
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h3>🔗 自定义域名服务</h3>
|
<h3>🔗 自定义域名服务</h3>
|
||||||
@@ -105,7 +106,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="width: 40px;"><input type="checkbox" id="select-all-custom"></th>
|
<th style="width: 40px;"><input type="checkbox" id="select-all-custom"></th>
|
||||||
<th>名称</th>
|
<th>名称</th>
|
||||||
<th style="width: 200px;">API 地址</th>
|
<th style="width: 90px;">类型</th>
|
||||||
|
<th style="width: 200px;">地址</th>
|
||||||
<th style="width: 100px;">状态</th>
|
<th style="width: 100px;">状态</th>
|
||||||
<th style="width: 80px;">优先级</th>
|
<th style="width: 80px;">优先级</th>
|
||||||
<th style="width: 160px;">最后使用</th>
|
<th style="width: 160px;">最后使用</th>
|
||||||
@@ -114,7 +116,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody id="custom-services-table">
|
<tbody id="custom-services-table">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7">
|
<td colspan="8">
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<div class="skeleton skeleton-text"></div>
|
<div class="skeleton skeleton-text"></div>
|
||||||
<div class="skeleton skeleton-text" style="width: 80%;"></div>
|
<div class="skeleton skeleton-text" style="width: 80%;"></div>
|
||||||
@@ -189,7 +191,7 @@
|
|||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 添加自定义域名模态框 -->
|
<!-- 添加自定义域名服务模态框(含类型选择) -->
|
||||||
<div class="modal" id="add-custom-modal">
|
<div class="modal" id="add-custom-modal">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@@ -203,16 +205,41 @@
|
|||||||
<input type="text" id="custom-name" name="name" required placeholder="例如:我的域名邮箱">
|
<input type="text" id="custom-name" name="name" required placeholder="例如:我的域名邮箱">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="custom-api-url">API 地址</label>
|
<label for="custom-sub-type">服务类型</label>
|
||||||
<input type="text" id="custom-api-url" name="api_url" required placeholder="https://api.example.com">
|
<select id="custom-sub-type" name="sub_type">
|
||||||
|
<option value="moemail">MoeMail(自定义域名 API)</option>
|
||||||
|
<option value="tempmail">TempMail(自部署 Cloudflare Worker)</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<!-- MoeMail 字段 -->
|
||||||
<label for="custom-api-key">API 密钥 (可选)</label>
|
<div id="add-moemail-fields">
|
||||||
<input type="text" id="custom-api-key" name="api_key" placeholder="API Key">
|
<div class="form-group">
|
||||||
|
<label for="custom-api-url">API 地址</label>
|
||||||
|
<input type="text" id="custom-api-url" name="api_url" placeholder="https://api.example.com">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="custom-api-key">API 密钥 (可选)</label>
|
||||||
|
<input type="text" id="custom-api-key" name="api_key" placeholder="API Key">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="custom-domain">邮箱域名</label>
|
||||||
|
<input type="text" id="custom-domain" name="domain" placeholder="example.com">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<!-- TempMail 字段 -->
|
||||||
<label for="custom-domain">邮箱域名</label>
|
<div id="add-tempmail-fields" style="display:none;">
|
||||||
<input type="text" id="custom-domain" name="domain" placeholder="example.com">
|
<div class="form-group">
|
||||||
|
<label for="custom-tm-base-url">Worker 地址</label>
|
||||||
|
<input type="text" id="custom-tm-base-url" name="tm_base_url" placeholder="https://mail.example.com">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="custom-tm-admin-password">Admin 密码</label>
|
||||||
|
<input type="password" id="custom-tm-admin-password" name="tm_admin_password" placeholder="x-admin-auth 密码">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="custom-tm-domain">邮箱域名</label>
|
||||||
|
<input type="text" id="custom-tm-domain" name="tm_domain" placeholder="example.com">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -235,7 +262,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 编辑自定义域名模态框 -->
|
|
||||||
|
<!-- 编辑自定义域名服务模态框(含类型选择) -->
|
||||||
<div class="modal" id="edit-custom-modal">
|
<div class="modal" id="edit-custom-modal">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@@ -245,22 +273,46 @@
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form id="edit-custom-form">
|
<form id="edit-custom-form">
|
||||||
<input type="hidden" id="edit-custom-id" name="id">
|
<input type="hidden" id="edit-custom-id" name="id">
|
||||||
|
<input type="hidden" id="edit-custom-sub-type-hidden" name="sub_type">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="edit-custom-name">服务名称</label>
|
<label for="edit-custom-name">服务名称</label>
|
||||||
<input type="text" id="edit-custom-name" name="name" required placeholder="例如:我的域名邮箱">
|
<input type="text" id="edit-custom-name" name="name" required placeholder="例如:我的域名邮箱">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="edit-custom-api-url">API 地址</label>
|
<label>服务类型</label>
|
||||||
<input type="text" id="edit-custom-api-url" name="api_url" required placeholder="https://api.example.com">
|
<div id="edit-custom-type-badge" style="padding: 6px 0; color: var(--text-muted); font-size: 0.875rem;"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<!-- MoeMail 字段 -->
|
||||||
<label for="edit-custom-api-key">API 密钥</label>
|
<div id="edit-moemail-fields">
|
||||||
<input type="text" id="edit-custom-api-key" name="api_key" placeholder="API Key">
|
<div class="form-group">
|
||||||
<small style="color: var(--text-muted);">留空则保持原值不变</small>
|
<label for="edit-custom-api-url">API 地址</label>
|
||||||
|
<input type="text" id="edit-custom-api-url" name="api_url" placeholder="https://api.example.com">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-custom-api-key">API 密钥</label>
|
||||||
|
<input type="text" id="edit-custom-api-key" name="api_key" placeholder="API Key">
|
||||||
|
<small style="color: var(--text-muted);">留空则保持原值不变</small>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-custom-domain">邮箱域名</label>
|
||||||
|
<input type="text" id="edit-custom-domain" name="domain" placeholder="example.com">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<!-- TempMail 字段 -->
|
||||||
<label for="edit-custom-domain">邮箱域名</label>
|
<div id="edit-tempmail-fields" style="display:none;">
|
||||||
<input type="text" id="edit-custom-domain" name="domain" placeholder="example.com">
|
<div class="form-group">
|
||||||
|
<label for="edit-tm-base-url">Worker 地址</label>
|
||||||
|
<input type="text" id="edit-tm-base-url" name="tm_base_url" placeholder="https://mail.example.com">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-tm-admin-password">Admin 密码</label>
|
||||||
|
<input type="password" id="edit-tm-admin-password" name="tm_admin_password" placeholder="留空则不修改">
|
||||||
|
<small style="color: var(--text-muted);">留空则保持原值不变</small>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-tm-domain">邮箱域名</label>
|
||||||
|
<input type="text" id="edit-tm-domain" name="tm_domain" placeholder="example.com">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -332,7 +384,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/utils.js"></script>
|
|
||||||
|
<script src="/static/js/utils.js"></script>
|
||||||
<script src="/static/js/email_services.js"></script>
|
<script src="/static/js/email_services.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -106,6 +106,7 @@
|
|||||||
<a href="/" class="nav-link active">注册</a>
|
<a href="/" class="nav-link active">注册</a>
|
||||||
<a href="/accounts" class="nav-link">账号管理</a>
|
<a href="/accounts" class="nav-link">账号管理</a>
|
||||||
<a href="/email-services" class="nav-link">邮箱服务</a>
|
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||||
|
<a href="/payment" class="nav-link">支付</a>
|
||||||
<a href="/settings" class="nav-link">设置</a>
|
<a href="/settings" class="nav-link">设置</a>
|
||||||
<a href="/logout" class="nav-link">退出</a>
|
<a href="/logout" class="nav-link">退出</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -221,6 +222,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="auto-upload-group">
|
||||||
|
<label style="font-weight: 500; margin-bottom: var(--spacing-xs); display: block;">注册后自动操作</label>
|
||||||
|
<label style="display: flex; align-items: center; gap: var(--spacing-sm); cursor: pointer;">
|
||||||
|
<input type="checkbox" id="auto-upload-cpa">
|
||||||
|
<span>上传到 CPA</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions" style="flex-direction: column;">
|
<div class="form-actions" style="flex-direction: column;">
|
||||||
<button type="submit" class="btn btn-primary btn-lg" id="start-btn" style="width: 100%;">
|
<button type="submit" class="btn btn-primary btn-lg" id="start-btn" style="width: 100%;">
|
||||||
🚀 开始注册
|
🚀 开始注册
|
||||||
|
|||||||
171
templates/payment.html
Normal file
171
templates/payment.html
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>支付升级 - OpenAI 注册系统</title>
|
||||||
|
<link rel="stylesheet" href="/static/css/style.css">
|
||||||
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>💳</text></svg>">
|
||||||
|
<style>
|
||||||
|
.plan-cards {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.plan-card {
|
||||||
|
border: 2px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.2s, box-shadow 0.2s;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.plan-card:hover {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
.plan-card.selected {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
|
||||||
|
}
|
||||||
|
.plan-card h3 { margin: 0 0 8px; font-size: 1.2rem; }
|
||||||
|
.plan-card p { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }
|
||||||
|
.team-options { display: none; }
|
||||||
|
.team-options.show { display: block; }
|
||||||
|
.link-box {
|
||||||
|
display: none;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
.link-box.show { display: block; }
|
||||||
|
.link-text {
|
||||||
|
width: 100%;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
color: var(--text-primary);
|
||||||
|
resize: vertical;
|
||||||
|
min-height: 80px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<!-- 导航栏 -->
|
||||||
|
<nav class="navbar">
|
||||||
|
<div class="nav-brand">
|
||||||
|
<h1>OpenAI 注册系统</h1>
|
||||||
|
</div>
|
||||||
|
<div class="nav-links">
|
||||||
|
<a href="/" class="nav-link">注册</a>
|
||||||
|
<a href="/accounts" class="nav-link">账号管理</a>
|
||||||
|
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||||
|
<a href="/payment" class="nav-link active">支付</a>
|
||||||
|
<a href="/settings" class="nav-link">设置</a>
|
||||||
|
</div>
|
||||||
|
<button class="theme-toggle" onclick="theme.toggle()" title="切换主题">🌙</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- 主内容区 -->
|
||||||
|
<main class="main-content">
|
||||||
|
<div class="page-header">
|
||||||
|
<h2>支付升级</h2>
|
||||||
|
<p class="subtitle">为账号生成 Plus 或 Team 订阅支付链接</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3>选择套餐</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<!-- 套餐选择 -->
|
||||||
|
<div class="plan-cards">
|
||||||
|
<div class="plan-card selected" id="plan-plus" onclick="selectPlan('plus')">
|
||||||
|
<h3>Plus</h3>
|
||||||
|
<p>个人订阅,$20/月</p>
|
||||||
|
</div>
|
||||||
|
<div class="plan-card" id="plan-team" onclick="selectPlan('team')">
|
||||||
|
<h3>Team</h3>
|
||||||
|
<p>团队订阅,按座位计费</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 账号选择 -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="account-select">选择账号</label>
|
||||||
|
<select id="account-select" style="width:100%">
|
||||||
|
<option value="">-- 加载中... --</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 国家选择 -->
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="country-select">计费国家</label>
|
||||||
|
<select id="country-select" onchange="onCountryChange()">
|
||||||
|
<option value="SG">新加坡 (SGD)</option>
|
||||||
|
<option value="US">美国 (USD)</option>
|
||||||
|
<option value="TR">土耳其 (TRY)</option>
|
||||||
|
<option value="JP">日本 (JPY)</option>
|
||||||
|
<option value="HK">香港 (HKD)</option>
|
||||||
|
<option value="GB">英国 (GBP)</option>
|
||||||
|
<option value="AU">澳大利亚 (AUD)</option>
|
||||||
|
<option value="CA">加拿大 (CAD)</option>
|
||||||
|
<option value="IN">印度 (INR)</option>
|
||||||
|
<option value="BR">巴西 (BRL)</option>
|
||||||
|
<option value="MX">墨西哥 (MXN)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>对应货币</label>
|
||||||
|
<input type="text" id="currency-display" value="SGD" readonly style="background:var(--surface-hover);cursor:default">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Team 额外参数 -->
|
||||||
|
<div class="team-options" id="team-options">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="workspace-name">工作区名称</label>
|
||||||
|
<input type="text" id="workspace-name" value="MyTeam" placeholder="MyTeam">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="seat-quantity">座位数量</label>
|
||||||
|
<input type="number" id="seat-quantity" value="5" min="1" max="100">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="price-interval">计费周期</label>
|
||||||
|
<select id="price-interval">
|
||||||
|
<option value="month">月付</option>
|
||||||
|
<option value="year">年付</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 操作区 -->
|
||||||
|
<div class="form-actions">
|
||||||
|
<button class="btn btn-primary" onclick="generateLink()">生成支付链接</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 链接结果 -->
|
||||||
|
<div class="link-box" id="link-box">
|
||||||
|
<label>支付链接</label>
|
||||||
|
<textarea class="link-text" id="link-text" readonly></textarea>
|
||||||
|
<div class="form-actions" style="margin-top:10px">
|
||||||
|
<button class="btn btn-secondary" onclick="copyLink()">复制链接</button>
|
||||||
|
<button class="btn btn-primary" onclick="openIncognito()">无痕打开浏览器</button>
|
||||||
|
</div>
|
||||||
|
<p class="hint" id="open-status"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/static/js/utils.js"></script>
|
||||||
|
<script src="/static/js/payment.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
<a href="/" class="nav-link">注册</a>
|
<a href="/" class="nav-link">注册</a>
|
||||||
<a href="/accounts" class="nav-link">账号管理</a>
|
<a href="/accounts" class="nav-link">账号管理</a>
|
||||||
<a href="/email-services" class="nav-link">邮箱服务</a>
|
<a href="/email-services" class="nav-link">邮箱服务</a>
|
||||||
|
<a href="/payment" class="nav-link">支付</a>
|
||||||
<a href="/settings" class="nav-link active">设置</a>
|
<a href="/settings" class="nav-link active">设置</a>
|
||||||
<a href="/logout" class="nav-link">退出</a>
|
<a href="/logout" class="nav-link">退出</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
<button class="tab-btn active" data-tab="proxy">🌐 代理设置</button>
|
<button class="tab-btn active" data-tab="proxy">🌐 代理设置</button>
|
||||||
<button class="tab-btn" data-tab="webui">🔒 访问控制</button>
|
<button class="tab-btn" data-tab="webui">🔒 访问控制</button>
|
||||||
<button class="tab-btn" data-tab="cpa">☁️ CPA上传</button>
|
<button class="tab-btn" data-tab="cpa">☁️ CPA上传</button>
|
||||||
|
<button class="tab-btn" data-tab="team-manager">🚀 Team Manager</button>
|
||||||
<button class="tab-btn" data-tab="outlook">📮 Outlook配置</button>
|
<button class="tab-btn" data-tab="outlook">📮 Outlook配置</button>
|
||||||
<button class="tab-btn" data-tab="registration">⚙️ 注册配置</button>
|
<button class="tab-btn" data-tab="registration">⚙️ 注册配置</button>
|
||||||
<button class="tab-btn" data-tab="email-code">📧 验证码配置</button>
|
<button class="tab-btn" data-tab="email-code">📧 验证码配置</button>
|
||||||
@@ -292,6 +294,44 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Team Manager 设置 -->
|
||||||
|
<div class="tab-content" id="team-manager-tab">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3>Team Manager 配置</h3>
|
||||||
|
<span class="hint">配置 Team Manager 账号导入功能</span>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form id="tm-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="tm-enabled" name="enabled">
|
||||||
|
启用 Team Manager 上传
|
||||||
|
</label>
|
||||||
|
<p class="hint">启用后可在账号管理页面将账号导入 Team Manager 平台</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="tm-api-url">API URL</label>
|
||||||
|
<input type="text" id="tm-api-url" name="api_url" placeholder="例如: https://tm.example.com">
|
||||||
|
<p class="hint">Team Manager 平台的 API 地址</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="tm-api-key">API Key</label>
|
||||||
|
<input type="password" id="tm-api-key" name="api_key" placeholder="留空则保持原值" autocomplete="new-password">
|
||||||
|
<p class="hint">Team Manager 平台的认证 Key</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn btn-primary">💾 保存设置</button>
|
||||||
|
<button type="button" class="btn btn-secondary" id="test-tm-btn">🔌 测试连接</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Outlook 配置 -->
|
<!-- Outlook 配置 -->
|
||||||
<div class="tab-content" id="outlook-tab">
|
<div class="tab-content" id="outlook-tab">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|||||||
Reference in New Issue
Block a user