From 41ff8f6c595ebb3e0f264e3c2276d951bb95b805 Mon Sep 17 00:00:00 2001 From: KJHJason Date: Mon, 21 Oct 2024 01:10:58 +0800 Subject: [PATCH] add ConvertFileSizeFromMB function to Filters --- filters/filters.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/filters/filters.go b/filters/filters.go index 63481fd..e37402d 100644 --- a/filters/filters.go +++ b/filters/filters.go @@ -9,8 +9,8 @@ import ( ) type Filters struct { - MinFileSize int64 - MaxFileSize int64 + MinFileSize int64 // In bytes + MaxFileSize int64 // In bytes FileExt []string @@ -20,6 +20,12 @@ type Filters struct { FileNameFilter *regexp.Regexp } +func (f *Filters) ConvertFileSizeFromMB() { + const mb = 1024 * 1024 + f.MinFileSize = f.MinFileSize * mb + f.MaxFileSize = f.MaxFileSize * mb +} + func (f *Filters) Copy() *Filters { return &Filters{ MinFileSize: f.MinFileSize, @@ -63,6 +69,7 @@ func (f *Filters) ValidateArgs() error { return nil } +// Note: In bytes func (f *Filters) IsFileSizeInRange(fileSize int64) bool { if f.MinFileSize == 0 && f.MaxFileSize == 0 { return true