Browse Source

增加名称和描述的校验

tags/v1.22.4.1^2
ychao_1983 3 years ago
parent
commit
d6cd08cee5
5 changed files with 31 additions and 17 deletions
  1. +1
    -6
      options/locale/locale_en-US.ini
  2. +1
    -1
      options/locale/locale_zh-CN.ini
  3. +20
    -3
      routers/repo/cloudbrain.go
  4. +4
    -7
      routers/repo/dataset.go
  5. +5
    -0
      routers/repo/util.go

+ 1
- 6
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.
@@ -920,11 +920,6 @@ image_delete_fail=Failed to delete image, please try again later.
download=Download
score=Score

images.name = Image Name
images.name_placerholder = Please enter the image name
image.label_tooltips = Example Python 3.7, Tensorflow 2.0, cuda 10, pytorch 1.6
images.public_tooltips = After the image is set to public, it can be seen by other users.

cloudbrain=Cloudbrain
cloudbrain.new=New cloudbrain
cloudbrain.desc=Cloudbrain


+ 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=查询数据集失败。


+ 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}$`)

Loading…
Cancel
Save