Skip to content

Commit dcd1209

Browse files
committed
🐛 Upgrade dependencies and refactor file storage logic.
Updated several dependencies including go-co-op/gocron, meilisearch-go, and others to their newer versions for improved functionality and security. Refactored file access methods to remove redundant path formatting and optimized response handling in the file middleware. Additionally, added a configuration feature to set the maximum number of retries for MinIO storage operations.
1 parent 7cdd98a commit dcd1209

File tree

5 files changed

+60
-49
lines changed

5 files changed

+60
-49
lines changed

go.mod

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ toolchain go1.23.2
77
require (
88
github.com/coreos/go-oidc/v3 v3.11.0
99
github.com/domodwyer/mailyak/v3 v3.6.2
10-
github.com/go-co-op/gocron/v2 v2.12.1
10+
github.com/go-co-op/gocron/v2 v2.12.4
1111
github.com/goccy/go-json v0.10.3
1212
github.com/gofiber/fiber/v3 v3.0.0-beta.3
1313
github.com/gofiber/storage/redis/v3 v3.1.2
1414
github.com/gofiber/utils/v2 v2.0.0-beta.7
1515
github.com/gookit/goutil v0.6.17
1616
github.com/gookit/validate v1.5.2
1717
github.com/joho/godotenv v1.5.1
18-
github.com/meilisearch/meilisearch-go v0.28.0
19-
github.com/minio/minio-go/v7 v7.0.74
18+
github.com/meilisearch/meilisearch-go v0.29.0
19+
github.com/minio/minio-go/v7 v7.0.81
2020
github.com/olekukonko/tablewriter v0.0.5
2121
github.com/redis/go-redis/v9 v9.7.0
2222
github.com/rs/xid v1.6.0
@@ -27,7 +27,7 @@ require (
2727
go.mongodb.org/mongo-driver v1.17.1
2828
go.oease.dev/omgo v1.0.0
2929
go.uber.org/zap v1.27.0
30-
golang.org/x/net v0.30.0
30+
golang.org/x/net v0.32.0
3131
golang.org/x/oauth2 v0.21.0
3232
)
3333

@@ -39,14 +39,14 @@ require (
3939
github.com/dustin/go-humanize v1.0.1 // indirect
4040
github.com/go-ini/ini v1.67.0 // indirect
4141
github.com/go-jose/go-jose/v4 v4.0.2 // indirect
42-
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
42+
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
4343
github.com/golang/snappy v0.0.4 // indirect
4444
github.com/google/uuid v1.6.0 // indirect
4545
github.com/gookit/filter v1.2.1 // indirect
4646
github.com/jonboulle/clockwork v0.4.0 // indirect
4747
github.com/josharian/intern v1.0.0 // indirect
4848
github.com/klauspost/compress v1.17.11 // indirect
49-
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
49+
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
5050
github.com/kr/pretty v0.3.1 // indirect
5151
github.com/mailru/easyjson v0.7.7 // indirect
5252
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -59,17 +59,17 @@ require (
5959
github.com/rivo/uniseg v0.4.7 // indirect
6060
github.com/robfig/cron/v3 v3.0.1 // indirect
6161
github.com/tinylib/msgp v1.1.8 // indirect
62-
github.com/valyala/fasthttp v1.56.0 // indirect
62+
github.com/valyala/fasthttp v1.57.0 // indirect
6363
github.com/valyala/tcplisten v1.0.0 // indirect
6464
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
6565
github.com/xdg-go/scram v1.1.2 // indirect
6666
github.com/xdg-go/stringprep v1.0.4 // indirect
6767
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
6868
go.uber.org/multierr v1.11.0 // indirect
69-
golang.org/x/crypto v0.28.0 // indirect
70-
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
71-
golang.org/x/sync v0.8.0 // indirect
72-
golang.org/x/sys v0.26.0 // indirect
73-
golang.org/x/text v0.19.0 // indirect
69+
golang.org/x/crypto v0.30.0 // indirect
70+
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d // indirect
71+
golang.org/x/sync v0.10.0 // indirect
72+
golang.org/x/sys v0.28.0 // indirect
73+
golang.org/x/text v0.21.0 // indirect
7474
gopkg.in/yaml.v3 v3.0.1 // indirect
7575
)

go.sum

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
12
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
23
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
34
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
@@ -22,6 +23,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
2223
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
2324
github.com/go-co-op/gocron/v2 v2.12.1 h1:dCIIBFbzhWKdgXeEifBjHPzgQ1hoWhjS4289Hjjy1uw=
2425
github.com/go-co-op/gocron/v2 v2.12.1/go.mod h1:xY7bJxGazKam1cz04EebrlP4S9q4iWdiAylMGP3jY9w=
26+
github.com/go-co-op/gocron/v2 v2.12.4 h1:h1HWApo3T+61UrZqEY2qG1LUpDnB7tkYITxf6YIK354=
27+
github.com/go-co-op/gocron/v2 v2.12.4/go.mod h1:xY7bJxGazKam1cz04EebrlP4S9q4iWdiAylMGP3jY9w=
2528
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
2629
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
2730
github.com/go-jose/go-jose/v4 v4.0.2 h1:R3l3kkBds16bO7ZFAEEcofK0MkrAJt3jlJznWZG0nvk=
@@ -36,6 +39,8 @@ github.com/gofiber/utils/v2 v2.0.0-beta.7 h1:NnHFrRHvhrufPABdWajcKZejz9HnCWmT/as
3639
github.com/gofiber/utils/v2 v2.0.0-beta.7/go.mod h1:J/M03s+HMdZdvhAeyh76xT72IfVqBzuz/OJkrMa7cwU=
3740
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
3841
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
42+
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
43+
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
3944
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
4045
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
4146
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@@ -61,6 +66,8 @@ github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90
6166
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
6267
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
6368
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
69+
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
70+
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
6471
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
6572
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
6673
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -77,10 +84,14 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
7784
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
7885
github.com/meilisearch/meilisearch-go v0.28.0 h1:f3XJ66ZM+R8bANAOLqsjvoq/HhQNpVJPYoNt6QgNzME=
7986
github.com/meilisearch/meilisearch-go v0.28.0/go.mod h1:Szcc9CaDiKIfjdgdt49jlmDKpEzjD+x+b6Y6heMdlQ0=
87+
github.com/meilisearch/meilisearch-go v0.29.0 h1:HZ9NEKN59USINQ/DXJge/aaXq8IrsKbXGTdAoBaaDz4=
88+
github.com/meilisearch/meilisearch-go v0.29.0/go.mod h1:2cRCAn4ddySUsFfNDLVPod/plRibQsJkXF/4gLhxbOk=
8089
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
8190
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
8291
github.com/minio/minio-go/v7 v7.0.74 h1:fTo/XlPBTSpo3BAMshlwKL5RspXRv9us5UeHEGYCFe0=
8392
github.com/minio/minio-go/v7 v7.0.74/go.mod h1:qydcVzV8Hqtj1VtEocfxbmVFa2siu6HGa+LDEPogjD8=
93+
github.com/minio/minio-go/v7 v7.0.81 h1:SzhMN0TQ6T/xSBu6Nvw3M5M8voM+Ht8RH3hE8S7zxaA=
94+
github.com/minio/minio-go/v7 v7.0.81/go.mod h1:84gmIilaX4zcvAWWzJ5Z1WI5axN+hAbM5w25xf8xvC0=
8495
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
8596
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
8697
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
@@ -119,6 +130,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
119130
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
120131
github.com/valyala/fasthttp v1.56.0 h1:bEZdJev/6LCBlpdORfrLu/WOZXXxvrUQSiyniuaoW8U=
121132
github.com/valyala/fasthttp v1.56.0/go.mod h1:sReBt3XZVnudxuLOx4J/fMrJVorWRiWY2koQKgABiVI=
133+
github.com/valyala/fasthttp v1.57.0 h1:Xw8SjWGEP/+wAAgyy5XTvgrWlOD1+TxbbvNADYCm1Tg=
134+
github.com/valyala/fasthttp v1.57.0/go.mod h1:h6ZBaPRlzpZ6O3H5t2gEk1Qi33+TmLvfwgLLp0t9CpE=
122135
github.com/valyala/quicktemplate v1.8.0 h1:zU0tjbIqTRgKQzFY1L42zq0qR3eh4WoQQdIdqCysW5k=
123136
github.com/valyala/quicktemplate v1.8.0/go.mod h1:qIqW8/igXt8fdrUln5kOSb+KWMaJ4Y8QUsfd1k6L2jM=
124137
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
@@ -152,8 +165,12 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
152165
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
153166
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
154167
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
168+
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
169+
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
155170
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
156171
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
172+
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d h1:0olWaB5pg3+oychR51GUVCEsGkeCU/2JxjBgIo4f3M0=
173+
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
157174
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
158175
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
159176
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -162,13 +179,17 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
162179
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
163180
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
164181
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
182+
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
183+
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
165184
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
166185
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
167186
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
168187
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
169188
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
170189
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
171190
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
191+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
192+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
172193
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
173194
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
174195
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -180,6 +201,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
180201
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
181202
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
182203
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
204+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
205+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
183206
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
184207
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
185208
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
@@ -192,6 +215,8 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
192215
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
193216
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
194217
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
218+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
219+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
195220
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
196221
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
197222
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

middlewares/file.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (m *FileMiddlewares) HandleUpload() fiber.Handler {
267267
}
268268

269269
// Save the file to storage
270-
if err := ctx.SaveFileToStorage(file, fmt.Sprintf("./%s", idealFileName), m.storage); err != nil {
270+
if err := ctx.SaveFileToStorage(file, fmt.Sprintf("%s", idealFileName), m.storage); err != nil {
271271
return webresult.SystemBusy(err)
272272
}
273273

@@ -328,25 +328,27 @@ func (m *FileMiddlewares) HandleView() fiber.Handler {
328328
}
329329

330330
//get file content from storage and display it
331-
fileData, err := m.storage.Get(fmt.Sprintf("./%s", fileInfo.UploadedName))
331+
fileData, err := m.storage.Get(fmt.Sprintf("%s", fileInfo.UploadedName))
332332
if err != nil {
333333
return webresult.SystemBusy(err)
334334
}
335335
if fileData == nil {
336336
return webresult.NotFound("file not found in upstream storage")
337337
}
338338
ctx.Response().Header.SetContentType(fileInfo.MimeType)
339-
ctx.Response().SetStatusCode(fiber.StatusOK)
339+
ctx.Response().Header.SetContentLength(int(fileInfo.Size))
340+
//ctx.Response().SetStatusCode(fiber.StatusOK)
340341

342+
ctx.Attachment()
341343
if mustDownload {
342344
if downloadName != "" {
343345
ctx.Response().Header.Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", downloadName))
344346
} else {
345347
ctx.Response().Header.Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", fileInfo.Filename))
346348
}
347349
}
348-
349-
return ctx.Send(fileData)
350+
ctx.Response().SetBody(fileData)
351+
return ctx.SendStatus(fiber.StatusOK)
350352
}
351353
}
352354

@@ -377,7 +379,7 @@ func (m *FileMiddlewares) HandleDelete() fiber.Handler {
377379
}
378380

379381
//delete file from storage
380-
err = m.storage.Delete(fmt.Sprintf("./%s", fileInfo.UploadedName))
382+
err = m.storage.Delete(fmt.Sprintf("%s", fileInfo.UploadedName))
381383
if err != nil {
382384
return webresult.SystemBusy(err)
383385
}

storages/s3minio/config.go

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ type Config struct {
4141
// Optional. Default is false
4242
Reset bool
4343

44+
// The maximum number of times requests that encounter retryable failures should be attempted.
45+
// Optional. Default is 10, same as the MinIO client.
46+
MaxRetry int
47+
4448
// Credentials Minio access key and Minio secret key.
4549
// Need to be defined
4650
Credentials Credentials
@@ -75,6 +79,7 @@ var ConfigDefault = Config{
7579
Token: "",
7680
Secure: false,
7781
Reset: false,
82+
MaxRetry: minio.MaxRetry,
7883
Credentials: Credentials{},
7984
GetObjectOptions: minio.GetObjectOptions{},
8085
PutObjectOptions: minio.PutObjectOptions{},
@@ -97,5 +102,9 @@ func configDefault(config ...Config) Config {
97102
cfg.Bucket = ConfigDefault.Bucket
98103
}
99104

105+
if cfg.MaxRetry < 1 {
106+
cfg.MaxRetry = ConfigDefault.MaxRetry
107+
}
108+
100109
return cfg
101110
}

storages/s3minio/minio.go

+6-31
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func New(config ...Config) *Storage {
2727
// Set default config
2828
cfg := configDefault(config...)
2929

30+
// Set MaxRetry
31+
minio.MaxRetry = cfg.MaxRetry
32+
3033
// Minio instance
3134
minioClient, err := minio.New(cfg.Endpoint, &minio.Options{
3235
Creds: credentials.NewStaticV4(cfg.Credentials.AccessKeyID, cfg.Credentials.SecretAccessKey, cfg.Token),
@@ -83,30 +86,7 @@ func (s *Storage) Get(key string) ([]byte, error) {
8386
return bb.Bytes(), nil
8487
}
8588

86-
func (s *Storage) MustGet(key string) []byte {
87-
if len(key) <= 0 {
88-
return nil
89-
}
90-
// get object
91-
object, err := s.minio.GetObject(s.ctx, s.cfg.Bucket, key, s.cfg.GetObjectOptions)
92-
if err != nil {
93-
return nil
94-
}
95-
// convert to byte
96-
bb := bytebufferpool.Get()
97-
defer bytebufferpool.Put(bb)
98-
_, err = bb.ReadFrom(object)
99-
if err != nil {
100-
return nil
101-
}
102-
return bb.Bytes()
103-
}
104-
10589
// Set key with value
106-
// The method `Set` sets the value for a given key in the storage. It creates a Reader from the value byte slice,
107-
// sets the content type in the storage configuration, and then puts the object in the bucket using the Minio client.
108-
// It acquires a lock on the storage mutex to ensure thread safety when setting the configuration options.
109-
// Finally, it returns any errors encountered while putting the object.
11090
func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
11191

11292
if len(key) <= 0 {
@@ -141,11 +121,6 @@ func (s *Storage) Delete(key string) error {
141121
}
142122

143123
// Reset all entries, including unexpired
144-
// This method resets all entries in the storage, including unexpired entries. It deletes all objects in the storage bucket.
145-
// The method achieves this by listing all the objects in the bucket and sending their names to a channel. A separate goroutine
146-
// listens to the channel and removes the objects one by one using the minio client's RemoveObjects method. The method also logs
147-
// any errors encountered during the deletion process.
148-
// DANGER ZONE!!!!!!: This method is dangerous and should be used with caution. It deletes all objects in the storage bucket.
149124
func (s *Storage) Reset() error {
150125

151126
objectsCh := make(chan minio.ObjectInfo)
@@ -187,17 +162,17 @@ func (s *Storage) CheckBucket() error {
187162
return nil
188163
}
189164

190-
// CreateBucket creates a new bucket if it does not exist
165+
// CreateBucket Bucket not found so Make a new bucket
191166
func (s *Storage) CreateBucket() error {
192167
return s.minio.MakeBucket(s.ctx, s.cfg.Bucket, minio.MakeBucketOptions{Region: s.cfg.Region})
193168
}
194169

195-
// RemoveBucket removes the bucket if it is empty.
170+
// RemoveBucket Bucket remove if bucket is empty
196171
func (s *Storage) RemoveBucket() error {
197172
return s.minio.RemoveBucket(s.ctx, s.cfg.Bucket)
198173
}
199174

200-
// Conn returns the minio client.
175+
// Conn Return minio client
201176
func (s *Storage) Conn() *minio.Client {
202177
return s.minio
203178
}

0 commit comments

Comments
 (0)