diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index ca16093a6..acabf3bd4 100755
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -261,7 +261,7 @@ search_issue=Issue
search_pr=Pull Request
search_user=User
search_org=Organization
-search_finded=Find
+search_finded=Find
search_related=related
search_maybe=maybe
search_ge=
@@ -274,7 +274,7 @@ use_plt__fuction = To use the AI collaboration functions provided by this platfo
provide_resoure = Computing resources of CPU/GPU/NPU are provided freely for various types of AI tasks.
activity = Activity
no_events = There are no events related
-or_t = or
+or_t = or
[explore]
repos = Repositories
@@ -1299,6 +1299,8 @@ editor.require_signed_commit = Branch requires a signed commit
editor.repo_too_large = Repository can not exceed %d MB
editor.repo_file_invalid = Upload files are invalid
editor.upload_file_too_much = Can not upload more than %d files at a time
+editor.rename = rename "%s" to %s"
+editor.file_changed_while_renaming=The version of the file or folder to be renamed has changed. Please refresh the page and try again
commits.desc = Browse source code change history.
@@ -1363,7 +1365,7 @@ issues.add_milestone_at = `added this to the %s milestone %s`
issues.change_milestone_at = `modified the milestone from %s to %s %s`
issues.remove_milestone_at = `removed this from the %s milestone %s`
-issues.add_branch_at=`added this to the %s branch %s`
+issues.add_branch_at=`added this to the %s branch %s`
issues.add_tag_at =`added this to the %s tag %s`
issues.change_branch_tag_at= `modified the branch/tag from %s to %s %s`
issues.remove_branch_at=`removed this from the %s branch %s`
@@ -3015,4 +3017,4 @@ SNN4IMAGENET = SNN4IMAGENET
BRAINSCORE = BRAINSCORE
TRAIN = TRAIN
INFERENCE = INFERENCE
-BENCHMARK = BENCHMARK
\ No newline at end of file
+BENCHMARK = BENCHMARK
diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini
index 474b96c3f..bc983b334 100755
--- a/options/locale/locale_zh-CN.ini
+++ b/options/locale/locale_zh-CN.ini
@@ -269,7 +269,7 @@ search_maybe=约为
search_ge=个
wecome_AI_plt=欢迎来到启智AI协作平台!
-explore_AI = 探索更好的AI,来这里发现更有意思的
+explore_AI = 探索更好的AI,来这里发现更有意思的
datasets = 数据集
repositories = 项目
use_plt__fuction = 使用本平台提供的AI协作功能,如:托管代码、共享数据、调试算法或训练模型,请先
@@ -277,7 +277,7 @@ provide_resoure = 平台目前免费提供CPU、GPU、NPU的算力资源,可
create_pro = 创建项目
activity = 活动
no_events = 还没有与您相关的活动
-or_t = 或
+or_t = 或
[explore]
@@ -1311,6 +1311,8 @@ editor.require_signed_commit=分支需要签名提交
editor.repo_too_large = 代码仓总大小不能超过%dMB
editor.repo_file_invalid = 提交的文件非法
editor.upload_file_too_much = 不能同时提交超过%d个文件
+editor.rename = 重命名"%s"为"%s"
+editor.file_changed_while_renaming=待重命名的文件或文件夹版本已发生变化,请您刷新页面后重试
commits.desc=浏览代码修改历史
commits.commits=次代码提交
diff --git a/routers/repo/editor.go b/routers/repo/editor.go
index b80a7c2ef..babc748bf 100644
--- a/routers/repo/editor.go
+++ b/routers/repo/editor.go
@@ -5,6 +5,7 @@
package repo
import (
+ "code.gitea.io/gitea/routers/response"
repo_service "code.gitea.io/gitea/services/repository"
"encoding/json"
"fmt"
@@ -803,11 +804,15 @@ func RenameFilePost(ctx *context.Context, form auth.RenameRepoFileForm) {
}
func renameFilePost(ctx *context.Context, form auth.RenameRepoFileForm) {
- //需要校验参数 commitId和
+ if form.TreePath == "" || form.LastCommit == "" {
+ ctx.JSON(http.StatusOK, response.ServerError("param error"))
+ return
+ }
+
canCommit := renderCommitRights(ctx)
branchName := ctx.Repo.BranchName
if ctx.HasError() {
- ctx.HTML(200, tplEditFile)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Flash.ErrorMsg))
return
}
@@ -815,15 +820,11 @@ func renameFilePost(ctx *context.Context, form auth.RenameRepoFileForm) {
if branchName == ctx.Repo.BranchName && !canCommit {
ctx.Data["Err_NewBranchName"] = true
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
- ctx.RenderWithErr(ctx.Tr("repo.editor.cannot_commit_to_protected_branch", branchName), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.cannot_commit_to_protected_branch", branchName)))
return
}
- message := ctx.Tr("repo.editor.update", form.TreePath)
-
- if len(message) > 0 {
- message += "\n\n" + message
- }
+ message := ctx.Tr("repo.editor.rename", ctx.Repo.TreePath, form.TreePath)
if err := repofiles.RenameRepoFile(ctx.Repo.Repository, ctx.User, &repofiles.RenameRepoFileOptions{
LastCommitID: form.LastCommit,
@@ -834,62 +835,60 @@ func renameFilePost(ctx *context.Context, form auth.RenameRepoFileForm) {
}); err != nil {
// This is where we handle all the errors thrown by repofiles.CreateOrUpdateRepoFile
if git.IsErrNotExist(err) {
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", ctx.Repo.TreePath), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.file_editing_no_longer_exists", ctx.Repo.TreePath)))
} else if models.IsErrLFSFileLocked(err) {
- ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(models.ErrLFSFileLocked).Path, err.(models.ErrLFSFileLocked).UserName), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.file_editing_no_longer_exists", ctx.Tr("repo.editor.upload_file_is_locked", err.(models.ErrLFSFileLocked).Path, err.(models.ErrLFSFileLocked).UserName))))
} else if models.IsErrFilenameInvalid(err) {
- ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_invalid", form.TreePath), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.filename_is_invalid", form.TreePath)))
} else if models.IsErrFilePathInvalid(err) {
- ctx.Data["Err_TreePath"] = true
if fileErr, ok := err.(models.ErrFilePathInvalid); ok {
switch fileErr.Type {
case git.EntryModeSymlink:
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_is_a_symlink", fileErr.Path), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.file_is_a_symlink", fileErr.Path)))
case git.EntryModeTree:
- ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_a_directory", fileErr.Path), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.filename_is_a_directory", fileErr.Path)))
case git.EntryModeBlob:
- ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", fileErr.Path), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.directory_is_a_file", fileErr.Path)))
default:
- ctx.Error(500, err.Error())
+ ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
}
} else {
- ctx.Error(500, err.Error())
+ ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
}
} else if models.IsErrRepoFileAlreadyExists(err) {
- ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_already_exists", form.TreePath), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.file_already_exists", form.TreePath)))
} else if git.IsErrBranchNotExist(err) {
// For when a user adds/updates a file to a branch that no longer exists
if branchErr, ok := err.(git.ErrBranchNotExist); ok {
- ctx.RenderWithErr(ctx.Tr("repo.editor.branch_does_not_exist", branchErr.Name), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.branch_does_not_exist", branchErr.Name)))
} else {
- ctx.Error(500, err.Error())
+ ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
}
} else if models.IsErrBranchAlreadyExists(err) {
// For when a user specifies a new branch that already exists
ctx.Data["Err_NewBranchName"] = true
if branchErr, ok := err.(models.ErrBranchAlreadyExists); ok {
- ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchErr.BranchName), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.branch_already_exists", branchErr.BranchName)))
} else {
+ ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
ctx.Error(500, err.Error())
}
} else if models.IsErrCommitIDDoesNotMatch(err) {
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing"), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.file_changed_while_renaming")))
} else if git.IsErrPushOutOfDate(err) {
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing"), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.file_changed_while_renaming")))
} else if git.IsErrPushRejected(err) {
errPushRej := err.(*git.ErrPushRejected)
if len(errPushRej.Message) == 0 {
- ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected_no_message"), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.push_rejected_no_message")))
} else {
- ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected", utils.SanitizeFlashErrorString(errPushRej.Message)), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.push_rejected", utils.SanitizeFlashErrorString(errPushRej.Message))))
}
} else {
- ctx.RenderWithErr(ctx.Tr("repo.editor.fail_to_update_file", form.TreePath, utils.SanitizeFlashErrorString(err.Error())), tplEditFile, &form)
+ ctx.JSON(http.StatusOK, response.ServerError(ctx.Tr("repo.editor.fail_to_update_file", form.TreePath, utils.SanitizeFlashErrorString(err.Error()))))
}
+ return
}
- ctx.JSON(http.StatusOK, "success")
+ ctx.JSON(http.StatusOK, response.Success())
}
diff --git a/routers/response/response.go b/routers/response/response.go
new file mode 100644
index 000000000..edd3b9cca
--- /dev/null
+++ b/routers/response/response.go
@@ -0,0 +1,32 @@
+package response
+
+const (
+ RESPONSE_CODE_SUCCESS = 0
+ RESPONSE_MSG_SUCCESS = "ok"
+ RESPONSE_CODE_ERROR_DEFAULT = 99
+)
+
+type AiforgeResponse struct {
+ Code int
+ Msg string
+ Data interface{}
+}
+
+func Success() *AiforgeResponse {
+ return &AiforgeResponse{Code: RESPONSE_CODE_SUCCESS, Msg: RESPONSE_MSG_SUCCESS}
+}
+
+func Error(code int, msg string) *AiforgeResponse {
+ return &AiforgeResponse{Code: code, Msg: msg}
+}
+
+func ServerError(msg string) *AiforgeResponse {
+ return &AiforgeResponse{Code: RESPONSE_CODE_ERROR_DEFAULT, Msg: msg}
+}
+
+func SuccessWithData(data interface{}) *AiforgeResponse {
+ return &AiforgeResponse{Code: RESPONSE_CODE_ERROR_DEFAULT, Msg: RESPONSE_MSG_SUCCESS, Data: data}
+}
+func ErrorWithData(code int, msg string, data interface{}) *AiforgeResponse {
+ return &AiforgeResponse{Code: code, Msg: msg, Data: data}
+}