From 70fd711fa561c96778a71dda1f86bd0421932037 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 6 Jul 2023 19:47:27 +0800 Subject: [PATCH] =?UTF-8?q?TODO=20=E5=90=84=E7=A7=8D=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/basic/basic.go | 6 ------ utils/check/check.go | 7 ++----- utils/format/s3keyname.go | 26 +++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/utils/basic/basic.go b/utils/basic/basic.go index 257fa6bd..86ecf94f 100644 --- a/utils/basic/basic.go +++ b/utils/basic/basic.go @@ -193,12 +193,6 @@ func RequestFileParse(r *http.Request, req any) error { field := reqValue.Field(i) - // aa1: - // field.Field(0).Set(fheader.Filename) - // field.Field(1).Set( fheader.Header) - // field.Field(2).Set( fheader.Size) - // field.Field(3).Set( data) - if field.Kind() == reflect.Ptr { if field.IsNil() { fsfile := reflect.New(field.Type().Elem()) diff --git a/utils/check/check.go b/utils/check/check.go index 9212d373..1bedba80 100644 --- a/utils/check/check.go +++ b/utils/check/check.go @@ -2,18 +2,15 @@ package check import ( "errors" + "fusenapi/utils/format" "regexp" "strings" "unicode/utf8" ) -var category = map[string]bool{ - "personalization": true, -} - // CheckCategory 检查是否存在该类型 func CheckCategory(key string) bool { - _, ok := category[key] + _, ok := format.CategoryMap[key] return ok } diff --git a/utils/format/s3keyname.go b/utils/format/s3keyname.go index b02a84ac..c4514795 100644 --- a/utils/format/s3keyname.go +++ b/utils/format/s3keyname.go @@ -13,8 +13,22 @@ const ( TypeS3KeyGuest TypeFormatS3KeyName = 2 // 游客 ) +type TypeCategory string + +const TCategoryPersonalization TypeCategory = "personalization" +const TCategory3DTools TypeCategory = "3dtools" +const TCategoryQuotation TypeCategory = "quotation" +const TCategoryRenderMegre TypeCategory = "render_megre" + +var CategoryMap = map[string]bool{ + string(TCategoryPersonalization): true, + string(TCategory3DTools): true, + string(TCategoryQuotation): true, + string(TCategoryRenderMegre): true, +} + // FormatS3KeyName 需要输入选 -func FormatS3KeyName(keytype TypeFormatS3KeyName, uid int64, now time.Time, env, category, name string) string { +func FormatS3KeyName(keytype TypeFormatS3KeyName, uid int64, now time.Time, env string, category TypeCategory, name string) string { if keytype == TypeS3KeyUser { return FormatS3KeyNameUser(uid, now, env, category, name) } else if keytype == TypeS3KeyGuest { @@ -25,7 +39,7 @@ func FormatS3KeyName(keytype TypeFormatS3KeyName, uid int64, now time.Time, env, } // FormatS3KeyNameUser -func FormatS3KeyNameUser(userid int64, now time.Time, env, category, name string) string { +func FormatS3KeyNameUser(userid int64, now time.Time, env string, category TypeCategory, name string) string { year, month, _ := now.Date() names := strings.Split(name, ".") var ext string @@ -35,11 +49,17 @@ func FormatS3KeyNameUser(userid int64, now time.Time, env, category, name string name = names[0] ext = names[1] } + + switch category { + case TCategoryPersonalization: + // TODO: + } + return fmt.Sprintf("/%s/%s/%d/%04d%02d/%s_%d.%s", env, category, userid, year, int(month), name, now.Unix(), ext) } // FormatS3KeyNameGuest 游客的格式化存储 -func FormatS3KeyNameGuest(guestid int64, now time.Time, env, category, name string) string { +func FormatS3KeyNameGuest(guestid int64, now time.Time, env string, category TypeCategory, name string) string { year, month, _ := now.Date() names := strings.Split(name, ".") var ext string