TODO 各种格式

This commit is contained in:
eson 2023-07-06 19:47:27 +08:00
parent 3b462edc89
commit 70fd711fa5
3 changed files with 25 additions and 14 deletions

View File

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

View File

@ -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
}

View File

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