Browse Source

Merge branch 'fix-323' of https://git.openi.org.cn/OpenI/aiforge into fix-323

pull/1839/head
zhoupzh 3 years ago
parent
commit
494b714363
9 changed files with 69 additions and 15 deletions
  1. +1
    -0
      models/user.go
  2. +1
    -1
      modules/auth/cloudbrain.go
  3. +1
    -1
      options/locale/locale_en-US.ini
  4. +1
    -1
      options/locale/locale_zh-CN.ini
  5. +30
    -0
      routers/image/image.go
  6. +20
    -3
      routers/repo/cloudbrain.go
  7. +4
    -7
      routers/repo/dataset.go
  8. +5
    -0
      routers/repo/util.go
  9. +6
    -2
      routers/routes/routes.go

+ 1
- 0
models/user.go View File

@@ -157,6 +157,7 @@ type User struct {
NumFollowing int `xorm:"NOT NULL DEFAULT 0"`
NumStars int
NumDatasetStars int `xorm:"NOT NULL DEFAULT 0"`
NumImageStars int `xorm:"NOT NULL DEFAULT 0"`
NumRepos int

// For organization


+ 1
- 1
modules/auth/cloudbrain.go View File

@@ -25,7 +25,7 @@ type CreateCloudBrainForm struct {
type CommitImageCloudBrainForm struct {
Description string `form:"description" binding:"Required"`
Type int `form:"type" binding:"Required"`
Tag string `form:"tag" binding:"Required;MaxSize(64)" `
Tag string `form:"tag" binding:"Required;MaxSize(100)" `
IsPrivate bool `form:"isPrivate" binding:"Required"`
Topics string `form:"topics"`
}


+ 1
- 1
options/locale/locale_en-US.ini View File

@@ -725,7 +725,7 @@ dataset_setting= Dataset Setting
title = Name
title_format_err=Name can only contain number,letter,'-','_' or '.', and can be up to 100 characters long.
description = Description
description_format_err=Description's length can be up to 1024 characters long.
description_format_err=Description's length can be up to %s characters long.
create_dataset = Create Dataset
create_dataset_fail=Failed to create dataset.
query_dataset_fail=Failed to query dataset.


+ 1
- 1
options/locale/locale_zh-CN.ini View File

@@ -728,7 +728,7 @@ dataset_setting=数据集设置
title=名称
title_format_err=名称最多允许输入100个字符,只允许字母,数字,中划线 (‘-’),下划线 (‘_’) 和点 (‘.’) 。
description=描述
description_format_err=描述最多允许输入1024个字符。
description_format_err=描述最多允许输入%s个字符。
create_dataset=创建数据集
create_dataset_fail=创建数据集失败。
query_dataset_fail=查询数据集失败。


+ 30
- 0
routers/image/image.go View File

@@ -0,0 +1,30 @@
package image

import (
"net/http"
"strconv"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
)

func Action(ctx *context.Context) {
var err error
imageId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64)
switch ctx.Params(":action") {

case "star":
err = models.StarImage(ctx.User.ID, imageId, true)
case "unstar":
err = models.StarImage(ctx.User.ID, imageId, false)
case "recommend":
err = models.RecommendImage(imageId, true)
case "unrecommend":
err = models.RecommendImage(imageId, false)
}
if err != nil {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.star_fail", ctx.Params(":action"))))
} else {
ctx.JSON(http.StatusOK, models.BaseOKMessage)
}
}

+ 20
- 3
routers/repo/cloudbrain.go View File

@@ -2,11 +2,9 @@ package repo

import (
"bufio"
"code.gitea.io/gitea/modules/timeutil"
"encoding/json"
"errors"
"fmt"
"github.com/unknwon/i18n"
"io"
"net/http"
"os"
@@ -15,6 +13,10 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"

"code.gitea.io/gitea/modules/timeutil"
"github.com/unknwon/i18n"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
@@ -470,12 +472,17 @@ func CloudBrainImageEdit(ctx *context.Context) {
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
}
ctx.Data["Image"] = image
ctx.HTML(http.StatusOK, tplCloudBrainImageSubmit)
ctx.HTML(http.StatusOK, tplCloudBrainImageEdit)
}
}

func CloudBrainImageEditPost(ctx *context.Context, form auth.EditImageCloudBrainForm) {

if utf8.RuneCountInString(form.Description) > 255 {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err", 255)))
return
}

validTopics, errMessage := checkTopics(form.Topics)
if errMessage != "" {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr(errMessage)))
@@ -529,6 +536,16 @@ func CloudBrainImageDelete(ctx *context.Context) {

func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) {

if !NamePattern.MatchString(form.Tag) {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.title_format_err")))
return
}

if utf8.RuneCountInString(form.Description) > 255 {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err", 255)))
return
}

validTopics, errMessage := checkTopics(form.Topics)
if errMessage != "" {
ctx.JSON(http.StatusOK, ctx.Tr(errMessage))


+ 4
- 7
routers/repo/dataset.go View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"regexp"
"sort"
"strconv"
"strings"
@@ -25,8 +24,6 @@ const (
taskstplIndex base.TplName = "repo/datasets/tasks/index"
)

var titlePattern = regexp.MustCompile(`^[A-Za-z0-9-_\\.]{1,100}$`)

// MustEnableDataset check if repository enable internal dataset
func MustEnableDataset(ctx *context.Context) {
if !ctx.Repo.CanRead(models.UnitTypeDatasets) {
@@ -211,12 +208,12 @@ func CreateDatasetPost(ctx *context.Context, form auth.CreateDatasetForm) {

dataset := &models.Dataset{}

if !titlePattern.MatchString(form.Title) {
if !NamePattern.MatchString(form.Title) {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.title_format_err")))
return
}
if utf8.RuneCountInString(form.Description) > 1024 {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err")))
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err", 1024)))
return
}

@@ -248,12 +245,12 @@ func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) {

ctx.Data["Title"] = ctx.Tr("dataset.edit_dataset")

if !titlePattern.MatchString(form.Title) {
if !NamePattern.MatchString(form.Title) {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.title_format_err")))
return
}
if utf8.RuneCountInString(form.Description) > 1024 {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err")))
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err", 1024)))
return
}



+ 5
- 0
routers/repo/util.go View File

@@ -0,0 +1,5 @@
package repo

import "regexp"

var NamePattern = regexp.MustCompile(`^[A-Za-z0-9-_\\.]{1,100}$`)

+ 6
- 2
routers/routes/routes.go View File

@@ -12,6 +12,8 @@ import (
"text/template"
"time"

"code.gitea.io/gitea/routers/image"

"code.gitea.io/gitea/routers/authentication"

"code.gitea.io/gitea/modules/cloudbrain"
@@ -529,6 +531,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("", admin.Images)
m.Get("/data", repo.GetAllImages)
})
m.Put("/image/:id/action/:action", image.Action)

m.Group("/^:configType(hooks|system-hooks)$", func() {
m.Get("", admin.DefaultOrSystemWebhooks)
@@ -976,11 +979,12 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/:username/:reponame", func() {
m.Post("/topics", repo.TopicsPost)
}, context.RepoAssignment(), context.RepoMustNotBeArchived(), reqRepoAdmin)
m.Group("/image/:id", func() {
m.Group("/image/:id", func() {
m.Get("/:from", cloudbrain.AdminOrImageCreaterRight, repo.CloudBrainImageEdit)
m.Post("", cloudbrain.AdminOrImageCreaterRight, bindIgnErr(auth.EditImageCloudBrainForm{}), repo.CloudBrainImageEditPost)
m.Delete("", cloudbrain.AdminOrImageCreaterRight, repo.CloudBrainImageDelete)
m.Put("action/:action", reqSignIn, image.Action)
})
m.Group("/:username/:reponame", func() {
m.Group("", func() {


Loading…
Cancel
Save