diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 15f2d53d7..7332be5e9 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -707,6 +707,9 @@ var ( NPU_MINDSPORE_IMAGE_ID int NPU_TENSORFLOW_IMAGE_ID int }{} + ModelApp = struct { + DesensitizationUrl string + }{} ) // DateLang transforms standard language locale name to corresponding value in datetime plugin. @@ -1527,6 +1530,7 @@ func NewContext() { getGrampusConfig() getModelartsCDConfig() getModelConvertConfig() + getModelAppConfig() } func getModelConvertConfig() { @@ -1548,6 +1552,12 @@ func getModelConvertConfig() { ModelConvert.NPU_TENSORFLOW_IMAGE_ID = sec.Key("NPU_TENSORFLOW_IMAGE_ID").MustInt(35) } +func getModelAppConfig() { + sec := Cfg.Section("model_app") + ModelApp.DesensitizationUrl = sec.Key("desensitization_url").MustString("") + +} + func getModelartsCDConfig() { sec := Cfg.Section("modelarts-cd") diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index dbd3f81f8..282ff9418 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3261,3 +3261,8 @@ hours = Hours expected_time = , expected to be available for points_acquisition_instructions = Points Acquisition Instructions insufficient_points_balance = Insufficient points balance + +[model_app] +get_file_fail= Can not get the image content, please try again later. +content_type_unsupported=Allowed image type is jpg, jpeg or png. +process_image_fail=Fail to process image, please try again later. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 21c4f45bd..979da91d5 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -3282,3 +3282,7 @@ points_acquisition_instructions = 积分获取说明 insufficient_points_balance = 积分余额不足 +[model_app] +get_file_fail= 获取上传文件失败,请稍后再试。 +content_type_unsupported=请上传jpg、jpeg或png图片。 +process_image_fail=图片处理失败,请稍后再试。 diff --git a/public/img/origin.png b/public/img/origin.png new file mode 100644 index 000000000..26eccf7ce Binary files /dev/null and b/public/img/origin.png differ diff --git a/public/img/tuomin.png b/public/img/tuomin.png new file mode 100644 index 000000000..116662b2f Binary files /dev/null and b/public/img/tuomin.png differ diff --git a/routers/modelapp/desensitization.go b/routers/modelapp/desensitization.go new file mode 100644 index 000000000..9de33526e --- /dev/null +++ b/routers/modelapp/desensitization.go @@ -0,0 +1,78 @@ +package modelapp + +import ( + "bytes" + "code.gitea.io/gitea/models" + "crypto/tls" + "image" + "image/png" + "net/http" + "strconv" + + "code.gitea.io/gitea/modules/setting" + + "code.gitea.io/gitea/modules/base" + + "code.gitea.io/gitea/modules/context" + "github.com/go-resty/resty/v2" +) + +var restyClient *resty.Client +var tplExploreUpload base.TplName = "model/tuomin/upload" +var uploadUrl = "/extension/tuomin/upload" +var allowedContentType = []string{"image/jpeg", "image/jpg", "image/png"} + +func ProcessImageUI(ctx *context.Context) { + ctx.HTML(200, tplExploreUpload) +} + +func ProcessImage(ctx *context.Context) { + + file, header, err := ctx.GetFile("file") + if err != nil { + ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.get_file_fail"))) + return + } + defer file.Close() + + contentType := header.Header.Get("Content-Type") + + if !isInAllowedContentType(contentType) { + ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.content_type_unsupported"))) + return + } + + client := getRestyClient() + res, err := client.R().SetMultipartField( + "file", header.Filename, contentType, file).Post(setting.ModelApp.DesensitizationUrl + "?mode=" + strconv.Itoa(ctx.QueryInt("mode"))) + if err != nil { + ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.process_image_fail"))) + return + } + image, _, err := image.Decode(bytes.NewReader(res.Body())) + if err != nil { + ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.process_image_fail"))) + return + } + + png.Encode(ctx.Resp, image) + return + +} + +func isInAllowedContentType(contentType string) bool { + for _, allowType := range allowedContentType { + if allowType == contentType { + return true + } + } + return false +} + +func getRestyClient() *resty.Client { + if restyClient == nil { + restyClient = resty.New() + restyClient.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) + } + return restyClient +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 66a357c79..4d4dbbec1 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -6,15 +6,17 @@ package routes import ( "bytes" - "code.gitea.io/gitea/routers/reward/point" - "code.gitea.io/gitea/routers/task" - "code.gitea.io/gitea/services/reward" "encoding/gob" "net/http" "path" "text/template" "time" + "code.gitea.io/gitea/routers/modelapp" + "code.gitea.io/gitea/routers/reward/point" + "code.gitea.io/gitea/routers/task" + "code.gitea.io/gitea/services/reward" + "code.gitea.io/gitea/modules/slideimage" "code.gitea.io/gitea/routers/image" @@ -346,6 +348,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/user/login/kanban", user.SignInPostAPI) m.Get("/home/term", routers.HomeTerm) m.Get("/home/privacy", routers.HomePrivacy) + m.Get("/extension/tuomin/upload", modelapp.ProcessImageUI) + m.Post("/extension/tuomin/upload", reqSignIn, modelapp.ProcessImage) m.Group("/explore", func() { m.Get("", func(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/explore/repos") diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 3de7b25a0..f9908f6f0 100755 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -32,9 +32,15 @@ - {{.i18n.Tr "custom.head.project"}} {{.i18n.Tr "custom.head.dataset"}} +
+ {{ $t("dataDesensitizationModelDesc") }} tengxiao / tuomin +
+