feat: Add API endpoint for team registration execution.

This commit is contained in:
2026-02-01 07:18:38 +08:00
parent c8aa925205
commit 0c5beddebe

View File

@@ -415,6 +415,24 @@ func readOutput(reader io.Reader, workDir string, config TeamRegConfig) {
if trimmed != "" { if trimmed != "" {
addTeamRegLog(trimmed) addTeamRegLog(trimmed)
// 检测输出文件名(例如:结果已保存到: accounts-2-20260201-071558.json
if strings.Contains(trimmed, "结果已保存到") || strings.Contains(trimmed, "accounts-") && strings.Contains(trimmed, ".json") {
// 尝试提取文件名
if idx := strings.Index(trimmed, "accounts-"); idx >= 0 {
endIdx := strings.Index(trimmed[idx:], ".json")
if endIdx > 0 {
fileName := trimmed[idx : idx+endIdx+5] // 包含 .json
// 构建完整路径
fullPath := filepath.Join(workDir, fileName)
if _, err := os.Stat(fullPath); err == nil {
teamRegState.mu.Lock()
teamRegState.OutputFile = fullPath
teamRegState.mu.Unlock()
}
}
}
}
// 检测 403 错误 // 检测 403 错误
if strings.Contains(trimmed, "403") { if strings.Contains(trimmed, "403") {
if check403AndStop() { if check403AndStop() {
@@ -539,17 +557,47 @@ func findTeamRegExecutable() string {
} }
// findLatestOutputFile 查找最新的输出文件 // findLatestOutputFile 查找最新的输出文件
func findLatestOutputFile(dir string) string { func findLatestOutputFile(primaryDir string) string {
// 搜索多个可能的目录
cwd, _ := os.Getwd()
searchDirs := []string{
primaryDir,
cwd,
"/app",
"/app/data",
filepath.Join(cwd, "data"),
".",
}
var allMatches []string
for _, dir := range searchDirs {
pattern := filepath.Join(dir, "accounts-*.json") pattern := filepath.Join(dir, "accounts-*.json")
matches, err := filepath.Glob(pattern) matches, err := filepath.Glob(pattern)
if err != nil || len(matches) == 0 { if err == nil && len(matches) > 0 {
allMatches = append(allMatches, matches...)
}
}
if len(allMatches) == 0 {
addTeamRegLog(fmt.Sprintf("[调试] 未找到 accounts-*.json搜索目录: %v", searchDirs))
return "" return ""
} }
// 去重
uniqueMatches := make(map[string]bool)
var finalMatches []string
for _, m := range allMatches {
absPath, _ := filepath.Abs(m)
if !uniqueMatches[absPath] {
uniqueMatches[absPath] = true
finalMatches = append(finalMatches, absPath)
}
}
// 按修改时间排序,取最新的 // 按修改时间排序,取最新的
sort.Slice(matches, func(i, j int) bool { sort.Slice(finalMatches, func(i, j int) bool {
fi, _ := os.Stat(matches[i]) fi, _ := os.Stat(finalMatches[i])
fj, _ := os.Stat(matches[j]) fj, _ := os.Stat(finalMatches[j])
if fi == nil || fj == nil { if fi == nil || fj == nil {
return false return false
} }
@@ -557,15 +605,16 @@ func findLatestOutputFile(dir string) string {
}) })
// 确保是最近创建的文件5分钟内 // 确保是最近创建的文件5分钟内
fi, err := os.Stat(matches[0]) fi, err := os.Stat(finalMatches[0])
if err != nil { if err != nil {
return "" return ""
} }
if time.Since(fi.ModTime()) > 5*time.Minute { if time.Since(fi.ModTime()) > 5*time.Minute {
addTeamRegLog(fmt.Sprintf("[调试] 找到文件但太旧: %s (修改于 %v 前)", finalMatches[0], time.Since(fi.ModTime())))
return "" return ""
} }
return matches[0] return finalMatches[0]
} }
// TeamRegAccount team-reg 输出的账号格式 // TeamRegAccount team-reg 输出的账号格式