|
|
@@ -60,6 +60,7 @@ package v1 |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/entity" |
|
|
|
"code.gitea.io/gitea/routers/response" |
|
|
|
"net/http" |
|
|
|
"strings" |
|
|
|
|
|
|
@@ -366,6 +367,15 @@ func reqWeChat() macaron.Handler { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func reqWeChatStandard() macaron.Handler { |
|
|
|
return func(ctx *context.Context) { |
|
|
|
if setting.WechatAuthSwitch && ctx.User.WechatOpenId == "" { |
|
|
|
ctx.JSON(http.StatusOK, response.OuterTrBizError(response.WECHAT_NOT_BIND, ctx)) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// reqAnyRepoReader user should have any permission to read repository or permissions of site admin |
|
|
|
func reqAnyRepoReader() macaron.Handler { |
|
|
|
return func(ctx *context.Context) { |
|
|
@@ -635,14 +645,14 @@ func RegisterRoutes(m *macaron.Macaron) { |
|
|
|
|
|
|
|
m.Group("/:username/:reponame", func() { |
|
|
|
m.Group("/ai_task", func() { |
|
|
|
m.Post("/create", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), bind(entity.CreateReq{}), ai_task.CreateAITask) |
|
|
|
m.Post("/stop", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), reqAdminOrOwnerAITaskCreator(), ai_task.StopAITask) |
|
|
|
m.Post("/del", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), reqAdminOrOwnerAITaskCreator(), ai_task.DelAITask) |
|
|
|
m.Post("/restart", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), reqAdminOrAITaskCreator(), ai_task.RestartAITask) |
|
|
|
m.Get("/log", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), ai_task.GetAITaskLog) |
|
|
|
m.Get("/output", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), ai_task.GetAITaskOutput) |
|
|
|
m.Get("/debug_url", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), ai_task.GetNotebookUrl) |
|
|
|
m.Get("/creation/required", reqWeChat(), reqRepoWriter(models.UnitTypeCloudBrain), ai_task.GetCreationRequiredInfo) |
|
|
|
m.Post("/create", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), bind(entity.CreateReq{}), ai_task.CreateAITask) |
|
|
|
m.Post("/stop", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), reqAdminOrOwnerAITaskCreator(), ai_task.StopAITask) |
|
|
|
m.Post("/del", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), reqAdminOrOwnerAITaskCreator(), ai_task.DelAITask) |
|
|
|
m.Post("/restart", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), reqAdminOrAITaskCreator(), ai_task.RestartAITask) |
|
|
|
m.Get("/log", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), ai_task.GetAITaskLog) |
|
|
|
m.Get("/output", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), ai_task.GetAITaskOutput) |
|
|
|
m.Get("/debug_url", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), reqAITaskInRepo(), ai_task.GetNotebookUrl) |
|
|
|
m.Get("/creation/required", reqWeChatStandard(), reqRepoWriter(models.UnitTypeCloudBrain), ai_task.GetCreationRequiredInfo) |
|
|
|
}, reqToken(), context.RepoRef()) |
|
|
|
m.Group("/ai_task", func() { |
|
|
|
m.Get("", reqRepoReader(models.UnitTypeCloudBrain), ai_task.GetAITaskInfo) |
|
|
@@ -912,7 +922,7 @@ func RegisterRoutes(m *macaron.Macaron) { |
|
|
|
|
|
|
|
m.Group("/file_notebook", func() { |
|
|
|
m.Get("", repo.GetFileNoteBookInfo) |
|
|
|
m.Post("/create", reqToken(), reqWeChat(), bind(api.CreateFileNotebookJobOption{}), repo.CreateFileNoteBook) |
|
|
|
m.Post("/create", reqToken(), reqWeChatStandard(), bind(api.CreateFileNotebookJobOption{}), repo.CreateFileNoteBook) |
|
|
|
m.Post("/status", reqToken(), bind(api.CreateFileNotebookJobOption{}), repo.FileNoteBookStatus) |
|
|
|
}) |
|
|
|
|
|
|
|