Major rewrite of the Go backend to support:
- Three API format imports: openai, anthropic, compatible
- Three protocol conversions: Chat Completions, Responses, Messages
- Hub-and-spoke architecture with Chat as intermediate format
Deleted:
- opencat.go (old entry)
- store/, team/, pkg/team/, pkg/store/ (old data layer)
- internal/model/, internal/consts/ (old types)
- internal/service/team/, internal/controller/team/ (old handlers)
- llm/ (removed LLM client library, pure proxy mode)
- dist/, assets/ (old build artifacts)
Added:
- internal/store/ — 9 GORM models + multi-DB support
- internal/pkg/ — crypto (AES-GCM), apikey, jwt, ratelimit, resp, tokenizer
- internal/channel/ — channel selection, weighted LB, health checks
- internal/proxy/convert/ — 6 protocol conversion functions + SSE streaming
- internal/proxy/ — gateway with request dispatch and upstream selection
- internal/usage/ — async usage recorder with batch writes
- internal/api/ — management API (auth, users, keys, channels, models)
- Makefile for build/test/deploy
Fixed API to match frontend expectations:
- Login response wraps token in { data: { token } }
- GET /api/profile route added
- Profile response wraps user in { code, data }
- Role returned as number (10=admin, 1=user)
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"opencatd-open/internal/store"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var LoadCmd = &cobra.Command{
|
|
Use: "load",
|
|
Short: "import user.json -> db",
|
|
Long: "\nimport user.json -> db",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
db := store.DB
|
|
var cont int64
|
|
if err := db.Model(&store.User{}).Count(&cont).Error; err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
if cont == 0 {
|
|
fmt.Println("创建管理员之后再操作")
|
|
return
|
|
}
|
|
if _, err := os.Stat("./db/user.json"); os.IsNotExist(err) {
|
|
log.Fatalln("404! user.json is not found.")
|
|
return
|
|
}
|
|
file, err := os.Open("./db/user.json")
|
|
if err != nil {
|
|
fmt.Println("Error opening file:", err)
|
|
return
|
|
}
|
|
defer file.Close()
|
|
|
|
var usermap []map[string]string
|
|
if err := json.NewDecoder(file).Decode(&usermap); err != nil {
|
|
fmt.Println("解析文件失败:", err)
|
|
return
|
|
}
|
|
for _, um := range usermap {
|
|
name := um["username"]
|
|
if name == "" {
|
|
name = um["name"]
|
|
}
|
|
if name == "" {
|
|
fmt.Println("获取不到数据")
|
|
continue
|
|
}
|
|
_ = "sk-ot-" + strings.ReplaceAll(uuid.New().String(), "-", "")
|
|
fmt.Printf("Import user: %s\n", name)
|
|
}
|
|
},
|
|
}
|
|
|
|
var SaveCmd = &cobra.Command{
|
|
Use: "save",
|
|
Short: "backup user info -> user.json",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
},
|
|
}
|