- Go 后端 handler 错误消息统一中文化(middleware/repos/generate/review/settings) - 前端 JS 加载和错误消息中文化(diff-viewer.js, graph.js) - 模板页面错误 fallback 和静态文本中文化(index/generate/review/base) - 消除中英文混杂,提升中文用户体验
This commit is contained in:
@@ -22,7 +22,7 @@ func NewGenerateHandler(db *sql.DB) *GenerateHandler {
|
||||
func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
var localPath string
|
||||
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -46,7 +46,7 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
Head string `json:"head" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "base and head are required"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请选择 Base 和 Head 分支"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
|
||||
flusher, ok := c.Writer.(http.Flusher)
|
||||
if !ok {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "streaming not supported"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "服务器不支持流式传输"})
|
||||
return
|
||||
}
|
||||
|
||||
sendEvent := func(event string, data interface{}) {
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
jsonData = []byte(`{"error":"failed to marshal event data"}`)
|
||||
jsonData = []byte(`{"error":"序列化事件数据失败"}`)
|
||||
}
|
||||
fmt.Fprintf(c.Writer, "event: %s\ndata: %s\n\n", event, jsonData)
|
||||
flusher.Flush()
|
||||
@@ -85,12 +85,12 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
// Save analysis to DB with user_id
|
||||
resultJSON, err := json.Marshal(pr)
|
||||
if err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "marshal result: " + err.Error()})
|
||||
sendEvent("error", map[string]interface{}{"message": "序列化结果失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if _, err := h.db.Exec(`INSERT INTO analyses (user_id, repo_id, type, base_ref, head_ref, result) VALUES (?, ?, 'pr_description', ?, ?, ?)`,
|
||||
user.ID, id, req.Base, req.Head, string(resultJSON)); err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "save analysis: " + err.Error()})
|
||||
sendEvent("error", map[string]interface{}{"message": "保存分析结果失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func AuthRequired(db *sql.DB) gin.HandlerFunc {
|
||||
if userID == nil {
|
||||
// Check if it's an API request
|
||||
if len(c.Request.URL.Path) > 4 && c.Request.URL.Path[:5] == "/api/" {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login")
|
||||
c.Abort()
|
||||
@@ -36,7 +36,7 @@ func AuthRequired(db *sql.DB) gin.HandlerFunc {
|
||||
session.Clear()
|
||||
session.Save()
|
||||
if len(c.Request.URL.Path) > 4 && c.Request.URL.Path[:5] == "/api/" {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login")
|
||||
c.Abort()
|
||||
|
||||
+20
-20
@@ -26,7 +26,7 @@ func NewReposHandler(db *sql.DB, reposDir string) *ReposHandler {
|
||||
func (h *ReposHandler) ListRepos(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (h *ReposHandler) ListRepos(c *gin.Context) {
|
||||
func (h *ReposHandler) DeleteRepo(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (h *ReposHandler) DeleteRepo(c *gin.Context) {
|
||||
var localPath string
|
||||
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -95,7 +95,7 @@ func (h *ReposHandler) DeleteRepo(c *gin.Context) {
|
||||
func (h *ReposHandler) CleanupRepos(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (h *ReposHandler) CleanupRepos(c *gin.Context) {
|
||||
func (h *ReposHandler) PullRepo(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (h *ReposHandler) PullRepo(c *gin.Context) {
|
||||
var credential sql.NullString
|
||||
err := h.db.QueryRow(`SELECT local_path, auth_type, credential FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath, &authType, &credential)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -192,7 +192,7 @@ func (h *ReposHandler) PullRepo(c *gin.Context) {
|
||||
func (h *ReposHandler) CloneRepo(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func (h *ReposHandler) CloneRepo(c *gin.Context) {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "url is required"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请输入仓库地址"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -215,14 +215,14 @@ func (h *ReposHandler) CloneRepo(c *gin.Context) {
|
||||
|
||||
flusher, ok := c.Writer.(http.Flusher)
|
||||
if !ok {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "streaming not supported"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "服务器不支持流式传输"})
|
||||
return
|
||||
}
|
||||
|
||||
sendEvent := func(event string, data interface{}) {
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
jsonData = []byte(`{"error":"failed to marshal event data"}`)
|
||||
jsonData = []byte(`{"error":"序列化事件数据失败"}`)
|
||||
}
|
||||
fmt.Fprintf(c.Writer, "event: %s\ndata: %s\n\n", event, jsonData)
|
||||
flusher.Flush()
|
||||
@@ -288,7 +288,7 @@ func (h *ReposHandler) CloneRepo(c *gin.Context) {
|
||||
func (h *ReposHandler) GetGraph(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ func (h *ReposHandler) GetGraph(c *gin.Context) {
|
||||
var localPath string
|
||||
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -309,7 +309,7 @@ func (h *ReposHandler) GetGraph(c *gin.Context) {
|
||||
|
||||
repo, err := services.OpenRepo(localPath)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "open repo: " + err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "打开仓库失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ func (h *ReposHandler) GetGraph(c *gin.Context) {
|
||||
func (h *ReposHandler) GetDiff(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -342,14 +342,14 @@ func (h *ReposHandler) GetDiff(c *gin.Context) {
|
||||
head := c.Query("head")
|
||||
|
||||
if base == "" || head == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "base and head query params are required"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请选择 Base 和 Head 分支"})
|
||||
return
|
||||
}
|
||||
|
||||
var localPath string
|
||||
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -390,7 +390,7 @@ func (h *ReposHandler) GetDiff(c *gin.Context) {
|
||||
func (h *ReposHandler) GetRefs(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ func (h *ReposHandler) GetRefs(c *gin.Context) {
|
||||
var localPath string
|
||||
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -425,7 +425,7 @@ func (h *ReposHandler) GetRefs(c *gin.Context) {
|
||||
func (h *ReposHandler) GetCommits(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ func (h *ReposHandler) GetCommits(c *gin.Context) {
|
||||
var localPath string
|
||||
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
+19
-19
@@ -24,7 +24,7 @@ func NewReviewHandler(db *sql.DB) *ReviewHandler {
|
||||
func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
var localPath string
|
||||
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -50,7 +50,7 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
Concurrency *int `json:"concurrency"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "base and head are required"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请选择 Base 和 Head 分支"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
|
||||
flusher, ok := c.Writer.(http.Flusher)
|
||||
if !ok {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "streaming not supported"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "服务器不支持流式传输"})
|
||||
return
|
||||
}
|
||||
|
||||
sendEvent := func(event string, data interface{}) {
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
jsonData = []byte(`{"error":"failed to marshal event data"}`)
|
||||
jsonData = []byte(`{"error":"序列化事件数据失败"}`)
|
||||
}
|
||||
fmt.Fprintf(c.Writer, "event: %s\ndata: %s\n\n", event, jsonData)
|
||||
flusher.Flush()
|
||||
@@ -117,18 +117,18 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
// Save analysis to DB with user_id
|
||||
resultJSON, err := json.Marshal(reviewResult)
|
||||
if err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "marshal result: " + err.Error()})
|
||||
sendEvent("error", map[string]interface{}{"message": "序列化结果失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
res, err := h.db.Exec(`INSERT INTO analyses (user_id, repo_id, type, base_ref, head_ref, result) VALUES (?, ?, 'code_review', ?, ?, ?)`,
|
||||
user.ID, id, req.Base, req.Head, string(resultJSON))
|
||||
if err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "save analysis: " + err.Error()})
|
||||
sendEvent("error", map[string]interface{}{"message": "保存分析结果失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
analysisID, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "get analysis id: " + err.Error()})
|
||||
sendEvent("error", map[string]interface{}{"message": "获取分析记录失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
sendEvent("analysis_saved", map[string]interface{}{
|
||||
@@ -140,7 +140,7 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
func (h *ReviewHandler) SaveNotes(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "analysis_id and scope are required"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "缺少必要参数"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
|
||||
case "overall", "file", "suggestion":
|
||||
// valid
|
||||
default:
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "scope must be overall, file, or suggestion"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "scope 参数无效"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
|
||||
var analysisOwnerID int64
|
||||
err := h.db.QueryRow(`SELECT user_id FROM analyses WHERE id = ?`, req.AnalysisID).Scan(&analysisOwnerID)
|
||||
if err == sql.ErrNoRows || analysisOwnerID != user.ID {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "analysis not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "分析记录未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -189,19 +189,19 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
|
||||
func (h *ReviewHandler) GetNotes(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
analysisIDStr := c.Query("analysis_id")
|
||||
if analysisIDStr == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "analysis_id query parameter is required"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "缺少 analysis_id 参数"})
|
||||
return
|
||||
}
|
||||
|
||||
analysisID, err := strconv.ParseInt(analysisIDStr, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid analysis_id"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "analysis_id 无效"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ func (h *ReviewHandler) GetNotes(c *gin.Context) {
|
||||
var analysisOwnerID int64
|
||||
err = h.db.QueryRow(`SELECT user_id FROM analyses WHERE id = ?`, analysisID).Scan(&analysisOwnerID)
|
||||
if err == sql.ErrNoRows || analysisOwnerID != user.ID {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "analysis not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "分析记录未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -235,7 +235,7 @@ func (h *ReviewHandler) GetNotes(c *gin.Context) {
|
||||
func (h *ReviewHandler) ListReviews(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func (h *ReviewHandler) ListReviews(c *gin.Context) {
|
||||
func (h *ReviewHandler) GetReview(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func (h *ReviewHandler) GetReview(c *gin.Context) {
|
||||
var result, baseRef, headRef, createdAt string
|
||||
err := h.db.QueryRow(`SELECT result, base_ref, head_ref, created_at FROM analyses WHERE id = ? AND user_id = ? AND type = 'code_review'`, aid, user.ID).Scan(&result, &baseRef, &headRef, &createdAt)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "analysis not found"})
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "分析记录未找到"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,7 @@ func NewSettingsHandler(db *sql.DB) *SettingsHandler {
|
||||
func (h *SettingsHandler) GetSettings(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,13 +41,13 @@ func (h *SettingsHandler) GetSettings(c *gin.Context) {
|
||||
func (h *SettingsHandler) UpdateSettings(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
var body map[string]string
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请求格式无效"})
|
||||
return
|
||||
}
|
||||
tx, err := h.db.Begin()
|
||||
|
||||
@@ -298,7 +298,7 @@ const DiffViewer = {
|
||||
this._onRenderComplete = options.onComplete || null;
|
||||
|
||||
if (!files || files.length === 0) {
|
||||
this.container.innerHTML = '<div class="text-gray-500 p-4">No changes</div>';
|
||||
this.container.innerHTML = '<div class="text-gray-500 p-4">暂无变更</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -664,12 +664,12 @@ const DiffViewer = {
|
||||
async loadDiff(repoId, base, head, options = {}) {
|
||||
if (!this.container) return;
|
||||
|
||||
this.container.innerHTML = '<div class="text-center p-8"><div class="spinner inline-block"></div><p class="mt-2 text-gray-500">Loading diff...</p></div>';
|
||||
this.container.innerHTML = '<div class="text-center p-8"><div class="spinner inline-block"></div><p class="mt-2 text-gray-500">加载 Diff 中...</p></div>';
|
||||
|
||||
try {
|
||||
const url = `/api/repos/${repoId}/diff?base=${encodeURIComponent(base)}&head=${encodeURIComponent(head)}`;
|
||||
const resp = await fetch(url, { credentials: 'same-origin' });
|
||||
if (!resp.ok) throw new Error('Failed to load diff');
|
||||
if (!resp.ok) throw new Error('加载 Diff 失败');
|
||||
|
||||
const data = await resp.json();
|
||||
|
||||
@@ -679,24 +679,24 @@ const DiffViewer = {
|
||||
this.renderFiles(data, options);
|
||||
}
|
||||
} catch (err) {
|
||||
this.container.innerHTML = `<div class="text-red-500 p-4">Error loading diff: ${err.message}</div>`;
|
||||
this.container.innerHTML = `<div class="text-red-500 p-4">加载 Diff 失败: ${err.message}</div>`;
|
||||
}
|
||||
},
|
||||
|
||||
async loadFiles(repoId, base, head) {
|
||||
if (!this.container) return;
|
||||
|
||||
this.container.innerHTML = '<div class="text-center p-8"><div class="spinner inline-block"></div><p class="text-gray-500">Loading files...</p></div>';
|
||||
this.container.innerHTML = '<div class="text-center p-8"><div class="spinner inline-block"></div><p class="text-gray-500">加载文件列表中...</p></div>';
|
||||
|
||||
try {
|
||||
const url = `/api/repos/${repoId}/diff?base=${encodeURIComponent(base)}&head=${encodeURIComponent(head)}&per_file=true`;
|
||||
const resp = await fetch(url, { credentials: 'same-origin' });
|
||||
if (!resp.ok) throw new Error('Failed to load diff');
|
||||
if (!resp.ok) throw new Error('加载 Diff 失败');
|
||||
|
||||
const files = await resp.json();
|
||||
this.renderFiles(files);
|
||||
} catch (err) {
|
||||
this.container.innerHTML = `<div class="text-red-500 p-4">Error: ${err.message}</div>`;
|
||||
this.container.innerHTML = `<div class="text-red-500 p-4">加载失败: ${err.message}</div>`;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
+3
-3
@@ -38,7 +38,7 @@ const GitGraph = {
|
||||
async load() {
|
||||
try {
|
||||
const resp = await fetch(`/api/repos/${this.repoId}/graph`, { credentials: 'same-origin' });
|
||||
if (!resp.ok) throw new Error('Failed to load graph');
|
||||
if (!resp.ok) throw new Error('加载提交图失败');
|
||||
const data = await resp.json();
|
||||
|
||||
this.commits = data.commits || [];
|
||||
@@ -47,7 +47,7 @@ const GitGraph = {
|
||||
|
||||
this.render();
|
||||
} catch (err) {
|
||||
this.container.innerHTML = `<div class="text-red-500 p-4">Error loading graph: ${err.message}</div>`;
|
||||
this.container.innerHTML = `<div class="text-red-500 p-4">加载提交图失败: ${err.message}</div>`;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -59,7 +59,7 @@ const GitGraph = {
|
||||
|
||||
render() {
|
||||
if (this.commits.length === 0) {
|
||||
this.container.innerHTML = '<div class="text-gray-500 p-4">No commits found</div>';
|
||||
this.container.innerHTML = '<div class="text-gray-500 p-4">暂无提交记录</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
{{define "footer"}}
|
||||
<footer class="bg-white border-t border-gray-200 py-4">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center text-sm text-gray-400">
|
||||
PR-Helper — AI-powered PR description & code review
|
||||
PR-Helper — AI 驱动的 PR 描述与代码审查
|
||||
</div>
|
||||
</footer>
|
||||
{{end}}
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
async function loadRefs() {
|
||||
try {
|
||||
const resp = await fetch(`/api/repos/${repoId}/refs`, { credentials: 'same-origin' });
|
||||
if (!resp.ok) throw new Error('Failed to load refs');
|
||||
if (!resp.ok) throw new Error('加载分支列表失败');
|
||||
const refs = await resp.json();
|
||||
|
||||
// Fetch recent commits for the "Recent Commits" group
|
||||
|
||||
@@ -142,7 +142,7 @@ document.getElementById('clone-form').addEventListener('submit', async function(
|
||||
|
||||
if (!resp.ok) {
|
||||
const data = await resp.json();
|
||||
throw new Error(data.error || 'clone failed');
|
||||
throw new Error(data.error || '克隆失败');
|
||||
}
|
||||
|
||||
const reader = resp.body.getReader();
|
||||
|
||||
@@ -223,7 +223,7 @@
|
||||
async function loadRefs() {
|
||||
try {
|
||||
const resp = await fetch(`/api/repos/${repoId}/refs`, { credentials: 'same-origin' });
|
||||
if (!resp.ok) throw new Error('Failed to load refs');
|
||||
if (!resp.ok) throw new Error('加载分支列表失败');
|
||||
const refs = await resp.json();
|
||||
|
||||
// Fetch recent commits for the "Recent Commits" group
|
||||
@@ -576,7 +576,7 @@
|
||||
try {
|
||||
// Fetch the review result
|
||||
const resp = await fetch(`/api/repos/${repoId}/review/analyses/${analysisId}`, { credentials: 'same-origin' });
|
||||
if (!resp.ok) throw new Error('Failed to load review');
|
||||
if (!resp.ok) throw new Error('加载评审数据失败');
|
||||
const data = await resp.json();
|
||||
|
||||
const result = data.result;
|
||||
|
||||
Reference in New Issue
Block a user