Browse Source

提交代码

pull/3033/head
ychao_1983 2 years ago
parent
commit
bbd8847a8d
2 changed files with 29 additions and 10 deletions
  1. +7
    -9
      routers/modelapp/desensitization.go
  2. +22
    -1
      web_src/vuepages/pages/model/tuomin/index.vue

+ 7
- 9
routers/modelapp/desensitization.go View File

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


import ( import (
"bytes" "bytes"
"code.gitea.io/gitea/models"
"crypto/tls" "crypto/tls"
"image" "image"
"image/png" "image/png"
"net/http"
"strconv" "strconv"


"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@@ -17,7 +19,7 @@ import (


var restyClient *resty.Client var restyClient *resty.Client
var tplExploreUpload base.TplName = "model/tuomin/upload" var tplExploreUpload base.TplName = "model/tuomin/upload"
var uploadUrl string = "/extension/tuomin/upload"
var uploadUrl = "/extension/tuomin/upload"
var allowedContentType = []string{"image/jpeg", "image/jpg", "image/png"} var allowedContentType = []string{"image/jpeg", "image/jpg", "image/png"}


func ProcessImageUI(ctx *context.Context) { func ProcessImageUI(ctx *context.Context) {
@@ -28,8 +30,7 @@ func ProcessImage(ctx *context.Context) {


file, header, err := ctx.GetFile("file") file, header, err := ctx.GetFile("file")
if err != nil { if err != nil {
ctx.Flash.Error(ctx.Tr("model_app.get_file_fail"))
ctx.Redirect(setting.AppSubURL + uploadUrl)
ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.get_file_fail")))
return return
} }
defer file.Close() defer file.Close()
@@ -37,8 +38,7 @@ func ProcessImage(ctx *context.Context) {
contentType := header.Header.Get("Content-Type") contentType := header.Header.Get("Content-Type")


if !isInAllowedContentType(contentType) { if !isInAllowedContentType(contentType) {
ctx.Flash.Error(ctx.Tr("model_app.content_type_unsupported"))
ctx.Redirect(setting.AppSubURL + uploadUrl)
ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.content_type_unsupported")))
return return
} }


@@ -46,14 +46,12 @@ func ProcessImage(ctx *context.Context) {
res, err := client.R().SetMultipartField( res, err := client.R().SetMultipartField(
"file", header.Filename, contentType, file).Post(setting.ModelApp.DesensitizationUrl + "?mode=" + strconv.Itoa(ctx.QueryInt("mode"))) "file", header.Filename, contentType, file).Post(setting.ModelApp.DesensitizationUrl + "?mode=" + strconv.Itoa(ctx.QueryInt("mode")))
if err != nil { if err != nil {
ctx.Flash.Error(ctx.Tr("model_app.process_image_fail"))
ctx.Redirect(setting.AppSubURL + uploadUrl)
ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.process_image_fail")))
return return
} }
image, _, err := image.Decode(bytes.NewReader(res.Body())) image, _, err := image.Decode(bytes.NewReader(res.Body()))
if err != nil { if err != nil {
ctx.Flash.Error(ctx.Tr("model_app.process_image_fail"))
ctx.Redirect(setting.AppSubURL + uploadUrl)
ctx.JSON(http.StatusBadRequest,models.BaseErrorMessage(ctx.Tr("model_app.process_image_fail")))
return return
} }




+ 22
- 1
web_src/vuepages/pages/model/tuomin/index.vue View File

@@ -184,11 +184,32 @@
this.tranformImageLoading = false this.tranformImageLoading = false
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
this.tranformImageLoading = false

this.tranformImageLoading = false;
if (err.response.status === 400) {
const fr = new FileReader();
fr.onload = (e) => {
try {
const jsonResult = JSON.parse(e.target.result);
this.$message({
type: 'error',
message: jsonResult.Message
});
} catch (e) {
this.$message({
type: 'error',
message: this.$t('tranformImageFailed')
});
}
};
fr.readAsText(err.response.data);
}else{

this.$message({ this.$message({
type: 'error', type: 'error',
message: this.$t('tranformImageFailed') message: this.$t('tranformImageFailed')
}); });
}
}) })


}, },


Loading…
Cancel
Save