Browse Source

提交代码

tags/v1.22.10.1^2
ychao_1983 2 years ago
parent
commit
40e7b95a30
5 changed files with 105 additions and 3 deletions
  1. +10
    -0
      modules/setting/setting.go
  2. +5
    -0
      options/locale/locale_en-US.ini
  3. +4
    -0
      options/locale/locale_zh-CN.ini
  4. +79
    -0
      routers/modelapp/desensitization.go
  5. +7
    -3
      routers/routes/routes.go

+ 10
- 0
modules/setting/setting.go View File

@@ -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")



+ 5
- 0
options/locale/locale_en-US.ini View File

@@ -3257,3 +3257,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.

+ 4
- 0
options/locale/locale_zh-CN.ini View File

@@ -3278,3 +3278,7 @@ points_acquisition_instructions = 积分获取说明
insufficient_points_balance = 积分余额不足


[model_app]
get_file_fail= 获取上传文件失败,请稍后再试。
content_type_unsupported=请上传jpg、jpeg或png图片。
process_image_fail=图片处理失败,请稍后再试。

+ 79
- 0
routers/modelapp/desensitization.go View File

@@ -0,0 +1,79 @@
package modelapp

import (
"bytes"
"crypto/tls"
"image"
"image/png"
"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 = "explore/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.Flash.Error(ctx.Tr("model_app.get_file_fail"))
ctx.Redirect(setting.AppSubURL + "/" + string(tplExploreUpload))
return
}
defer file.Close()

contentType := header.Header.Get("Content-Type")

if !isInAllowedContentType(contentType) {
ctx.Flash.Error(ctx.Tr("model_app.content_type_unsupported"))
ctx.Redirect(setting.AppSubURL + "/" + string(tplExploreUpload))
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.Flash.Error(ctx.Tr("model_app.process_image_fail"))
ctx.Redirect(setting.AppSubURL + "/" + string(tplExploreUpload))
return
}
image, _, err := image.Decode(bytes.NewReader(res.Body()))
if err != nil {
ctx.Flash.Error(ctx.Tr("model_app.process_image_fail"))
ctx.Redirect(setting.AppSubURL + "/" + string(tplExploreUpload))
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
}

+ 7
- 3
routers/routes/routes.go View File

@@ -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", modelapp.ProcessImage)
m.Group("/explore", func() {
m.Get("", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/explore/repos")


Loading…
Cancel
Save