diff --git a/pkg/filemanager/driver/upyun/media.go b/pkg/filemanager/driver/upyun/media.go index bf36acb1..743a3c72 100644 --- a/pkg/filemanager/driver/upyun/media.go +++ b/pkg/filemanager/driver/upyun/media.go @@ -31,8 +31,6 @@ func (handler *Driver) extractImageMeta(ctx context.Context, path string) ([]dri return nil, err } - fmt.Println(resp) - var imageInfo ImageInfo if err := json.Unmarshal([]byte(resp), &imageInfo); err != nil { return nil, fmt.Errorf("failed to unmarshal image info: %w", err) diff --git a/pkg/hashid/hash.go b/pkg/hashid/hash.go index 9f93c6e6..d3017b61 100644 --- a/pkg/hashid/hash.go +++ b/pkg/hashid/hash.go @@ -75,76 +75,69 @@ func (e *hashEncoder) Decode(raw string, t int) (int, error) { return res[0], nil } +func encodeID(encoder Encoder, id, t int) string { + res, _ := encoder.Encode([]int{id, t}) + return res +} + // EncodeUserID encode user id to hash id func EncodeUserID(encoder Encoder, uid int) string { - res, _ := encoder.Encode([]int{uid, UserID}) - return res + return encodeID(encoder, uid, UserID) } // EncodeGroupID encode group id to hash id func EncodeGroupID(encoder Encoder, uid int) string { - res, _ := encoder.Encode([]int{uid, GroupID}) - return res + return encodeID(encoder, uid, GroupID) } // EncodePaymentID encode payment id to hash id func EncodePaymentID(encoder Encoder, uid int) string { - res, _ := encoder.Encode([]int{uid, PaymentID}) - return res + return encodeID(encoder, uid, PaymentID) } // EncodeFileID encode file id to hash id func EncodeFileID(encoder Encoder, uid int) string { - res, _ := encoder.Encode([]int{uid, FileID}) - return res + return encodeID(encoder, uid, FileID) } // EncodeAuditLogID encode audit log id to hash id func EncodeAuditLogID(encoder Encoder, uid int) string { - res, _ := encoder.Encode([]int{uid, AuditLogID}) - return res + return encodeID(encoder, uid, AuditLogID) } // EncodeTaskID encode task id to hash id func EncodeTaskID(encoder Encoder, uid int) string { - res, _ := encoder.Encode([]int{uid, TaskID}) - return res + return encodeID(encoder, uid, TaskID) } // EncodeEntityID encode entity id to hash id func EncodeEntityID(encoder Encoder, id int) string { - res, _ := encoder.Encode([]int{id, EntityID}) - return res + return encodeID(encoder, id, EntityID) } // EncodeNodeID encode node id to hash id func EncodeNodeID(encoder Encoder, id int) string { - res, _ := encoder.Encode([]int{id, NodeID}) - return res + return encodeID(encoder, id, NodeID) } -// EncodeEntityID encode policy id to hash id +// EncodePolicyID encode policy id to hash id func EncodePolicyID(encoder Encoder, id int) string { - res, _ := encoder.Encode([]int{id, PolicyID}) - return res + return encodeID(encoder, id, PolicyID) } -// EncodeEntityID encode share id to hash id +// EncodeShareID encode share id to hash id func EncodeShareID(encoder Encoder, id int) string { - res, _ := encoder.Encode([]int{id, ShareID}) - return res + return encodeID(encoder, id, ShareID) } // EncodeDavAccountID encode dav account id to hash id func EncodeDavAccountID(encoder Encoder, id int) string { - res, _ := encoder.Encode([]int{id, DavAccountID}) - return res + return encodeID(encoder, id, DavAccountID) } // EncodeSourceLinkID encode source link id to hash id func EncodeSourceLinkID(encoder Encoder, id int) string { - res, _ := encoder.Encode([]int{id, SourceLinkID}) - return res + return encodeID(encoder, id, SourceLinkID) } func FromContext(c context.Context) int { diff --git a/pkg/request/request.go b/pkg/request/request.go index 5ada9695..38c2e9cb 100644 --- a/pkg/request/request.go +++ b/pkg/request/request.go @@ -21,9 +21,6 @@ import ( "github.com/samber/lo" ) -// GeneralClient 通用 HTTP Client -var GeneralClient Client = NewClientDeprecated() - const ( CorrelationHeader = constants.CrHeaderPrefix + "Correlation-Id" SiteURLHeader = constants.CrHeaderPrefix + "Site-Url" @@ -72,20 +69,6 @@ func NewClient(config conf.ConfigProvider, opts ...Option) Client { return client } -// Deprecated -func NewClientDeprecated(opts ...Option) Client { - client := &HTTPClient{ - options: newDefaultOption(), - tpsLimiter: globalTPSLimiter, - } - - for _, o := range opts { - o.apply(client.options) - } - - return client -} - func (c *HTTPClient) Apply(opts ...Option) { for _, o := range opts { o.apply(c.options) diff --git a/pkg/request/request_test.go b/pkg/request/request_test.go index a32c05ed..3c58756a 100644 --- a/pkg/request/request_test.go +++ b/pkg/request/request_test.go @@ -56,7 +56,7 @@ func TestWithContext(t *testing.T) { func TestHTTPClient_Request(t *testing.T) { asserts := assert.New(t) - client := NewClientDeprecated(WithSlaveMeta(1)) + client := NewClient(nil, WithSlaveMeta(1)) // 正常 { @@ -239,7 +239,7 @@ func TestBlackHole(t *testing.T) { func TestHTTPClient_TPSLimit(t *testing.T) { a := assert.New(t) - client := NewClientDeprecated() + client := NewClient(nil, ) finished := make(chan struct{}) go func() { @@ -296,7 +296,7 @@ func TestSignBaseTimeShiftsExpiry(t *testing.T) { })) defer srv.Close() - client := NewClientDeprecated(WithEndpoint(srv.URL)) + client := NewClient(nil, WithEndpoint(srv.URL)) base := time.Now().Add(2 * time.Hour) resp := client.Request( "POST", diff --git a/pkg/thumb/builtin.go b/pkg/thumb/builtin.go index 0f6be179..2503769e 100644 --- a/pkg/thumb/builtin.go +++ b/pkg/thumb/builtin.go @@ -77,8 +77,8 @@ func NewThumbFromFile(file io.Reader, ext string) (*Thumb, error) { }, nil } -// GetThumb 生成给定最大尺寸的缩略图 -func (image *Thumb) GetThumb(width, height uint) { +// Resize 生成给定最大尺寸的缩略图(就地修改) +func (image *Thumb) Resize(width, height uint) { //image.src = resize.Thumbnail(width, height, image.src, resize.Lanczos3) image.src = Thumbnail(width, height, image.src) } @@ -170,7 +170,7 @@ func (b Builtin) Generate(ctx context.Context, es entitysource.EntitySource, ext } w, h := b.settings.ThumbSize(ctx) - img.GetThumb(uint(w), uint(h)) + img.Resize(uint(w), uint(h)) tempPath := filepath.Join( util.DataPath(b.settings.TempPath(ctx)), thumbTempFolder, diff --git a/pkg/thumb/ffmpeg.go b/pkg/thumb/ffmpeg.go index 0112b8e6..a520572f 100644 --- a/pkg/thumb/ffmpeg.go +++ b/pkg/thumb/ffmpeg.go @@ -30,7 +30,7 @@ type FfmpegGenerator struct { } func (f *FfmpegGenerator) Generate(ctx context.Context, es entitysource.EntitySource, ext string, previous *Result) (*Result, error) { - if !util.IsInExtensionListExt(f.settings.FFMpegThumbExts(ctx), ext) { + if !util.IsExtInList(f.settings.FFMpegThumbExts(ctx), ext) { return nil, fmt.Errorf("unsupported video format: %w", ErrPassThrough) } diff --git a/pkg/thumb/libraw.go b/pkg/thumb/libraw.go index e43ba8b3..fa2bab64 100644 --- a/pkg/thumb/libraw.go +++ b/pkg/thumb/libraw.go @@ -30,7 +30,7 @@ type LibRawGenerator struct { } func (l *LibRawGenerator) Generate(ctx context.Context, es entitysource.EntitySource, ext string, previous *Result) (*Result, error) { - if !util.IsInExtensionListExt(l.settings.LibRawThumbExts(ctx), ext) { + if !util.IsExtInList(l.settings.LibRawThumbExts(ctx), ext) { return nil, fmt.Errorf("unsupported video format: %w", ErrPassThrough) } diff --git a/pkg/thumb/libreoffice.go b/pkg/thumb/libreoffice.go index 42d6abd7..d73c10ee 100644 --- a/pkg/thumb/libreoffice.go +++ b/pkg/thumb/libreoffice.go @@ -27,7 +27,7 @@ type LibreOfficeGenerator struct { } func (l *LibreOfficeGenerator) Generate(ctx context.Context, es entitysource.EntitySource, ext string, previous *Result) (*Result, error) { - if !util.IsInExtensionListExt(l.settings.LibreOfficeThumbExts(ctx), ext) { + if !util.IsExtInList(l.settings.LibreOfficeThumbExts(ctx), ext) { return nil, fmt.Errorf("unsupported video format: %w", ErrPassThrough) } diff --git a/pkg/thumb/music.go b/pkg/thumb/music.go index 4947336c..6520d814 100644 --- a/pkg/thumb/music.go +++ b/pkg/thumb/music.go @@ -23,7 +23,7 @@ type MusicCoverGenerator struct { } func (v *MusicCoverGenerator) Generate(ctx context.Context, es entitysource.EntitySource, ext string, previous *Result) (*Result, error) { - if !util.IsInExtensionListExt(v.settings.MusicCoverThumbExts(ctx), ext) { + if !util.IsExtInList(v.settings.MusicCoverThumbExts(ctx), ext) { return nil, fmt.Errorf("unsupported music format: %w", ErrPassThrough) } diff --git a/pkg/thumb/vips.go b/pkg/thumb/vips.go index 99dadca5..d2a3e443 100644 --- a/pkg/thumb/vips.go +++ b/pkg/thumb/vips.go @@ -28,7 +28,7 @@ type VipsGenerator struct { } func (v *VipsGenerator) Generate(ctx context.Context, es entitysource.EntitySource, ext string, previous *Result) (*Result, error) { - if !util.IsInExtensionListExt(v.settings.VipsThumbExts(ctx), ext) { + if !util.IsExtInList(v.settings.VipsThumbExts(ctx), ext) { return nil, fmt.Errorf("unsupported video format: %w", ErrPassThrough) } diff --git a/pkg/util/common.go b/pkg/util/common.go index 3791d7de..e999bd99 100644 --- a/pkg/util/common.go +++ b/pkg/util/common.go @@ -3,7 +3,6 @@ package util import ( "context" cryptoRand "crypto/rand" - "fmt" "math/big" "math/rand" "path" @@ -12,7 +11,6 @@ import ( "strconv" "strings" "time" - "unicode/utf8" "github.com/gin-gonic/gin" "github.com/gofrs/uuid" @@ -85,7 +83,7 @@ func IsInExtensionList(extList []string, fileName string) bool { } // IsInExtensionList 返回文件的扩展名是否在给定的列表范围内 -func IsInExtensionListExt(extList []string, ext string) bool { +func IsExtInList(extList []string, ext string) bool { // 无扩展名时 if len(ext) == 0 { return false @@ -260,101 +258,6 @@ func BoolToString(b bool) string { return "0" } -func EncodeTimeFlowString(str string, timeNow int64) string { - timeNow = timeNow / 1000 - timeDigits := []int{} - timeDigitIndex := 0 - - if len(str) == 0 { - return "" - } - - str = fmt.Sprintf("%d|%s", timeNow, str) - - res := make([]int32, 0, utf8.RuneCountInString(str)) - for timeNow > 0 { - timeDigits = append(timeDigits, int(timeNow%int64(10))) - timeNow = timeNow / 10 - } - - add := false - for pos, rune := range str { - // take single digit with index timeDigitIndex from timeNow - newIndex := pos - if add { - newIndex = pos + timeDigits[timeDigitIndex]*timeDigitIndex - } else { - newIndex = 2*timeDigitIndex*timeDigits[timeDigitIndex] - pos - } - - if newIndex < 0 { - newIndex = newIndex * -1 - } - - res = append(res, rune) - newIndex = newIndex % len(res) - - res[newIndex], res[len(res)-1] = res[len(res)-1], res[newIndex] - - add = !add - // Add timeDigitIndex by 1, but does not exceed total digits in timeNow - timeDigitIndex++ - timeDigitIndex = timeDigitIndex % len(timeDigits) - } - - return string(res) -} - -func DecodeTimeFlowStringTime(str string, timeNow int64) string { - timeNow = timeNow / 1000 - timeDigits := []int{} - - if len(str) == 0 { - return "" - } - - for timeNow > 0 { - timeDigits = append(timeDigits, int(timeNow%int64(10))) - timeNow = timeNow / 10 - } - - res := make([]int32, utf8.RuneCountInString(str)) - secret := []rune(str) - add := false - if len(secret)%2 == 0 { - add = true - } - timeDigitIndex := (len(secret) - 1) % len(timeDigits) - for pos := range secret { - // take single digit with index timeDigitIndex from timeNow - newIndex := len(res) - 1 - pos - if add { - newIndex = newIndex + timeDigits[timeDigitIndex]*timeDigitIndex - } else { - newIndex = 2*timeDigitIndex*timeDigits[timeDigitIndex] - newIndex - } - - if newIndex < 0 { - newIndex = newIndex * -1 - } - - newIndex = newIndex % len(secret) - - res[len(res)-1-pos] = secret[newIndex] - secret[newIndex], secret[len(res)-1-pos] = secret[len(res)-1-pos], secret[newIndex] - secret = secret[:len(secret)-1] - - add = !add - // Add timeDigitIndex by 1, but does not exceed total digits in timeNow - timeDigitIndex-- - if timeDigitIndex < 0 { - timeDigitIndex = len(timeDigits) - 1 - } - } - - return string(res) -} - func ToPtr[T any](v T) *T { return &v } diff --git a/routers/controllers/oauth.go b/routers/controllers/oauth.go index bc196af2..1635ba25 100644 --- a/routers/controllers/oauth.go +++ b/routers/controllers/oauth.go @@ -37,7 +37,7 @@ func GetAppRegistration(c *gin.Context) { func GrantAppConsent(c *gin.Context) { service := ParametersFromContext[*oauth.GrantService](c, oauth.GrantParamCtx{}) - res, err := service.Get(c) + res, err := service.Issue(c) if err != nil { c.JSON(200, serializer.Err(c, err)) c.Abort() diff --git a/service/oauth/oauth.go b/service/oauth/oauth.go index 4593f244..24023314 100644 --- a/service/oauth/oauth.go +++ b/service/oauth/oauth.go @@ -58,7 +58,7 @@ type ( } ) -func (s *GrantService) Get(c *gin.Context) (*GrantResponse, error) { +func (s *GrantService) Issue(c *gin.Context) (*GrantResponse, error) { dep := dependency.FromContext(c) user := inventory.UserFromContext(c) kv := dep.KV()