Skip to content

Commit 51c703c

Browse files
committed
feat(func): media library fix remote fetch error
1 parent 0e33727 commit 51c703c

5 files changed

Lines changed: 43 additions & 13 deletions

File tree

go.mod

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ require (
4141
github.com/foxxorcat/weiyun-sdk-go v0.1.4
4242
github.com/gin-contrib/cors v1.7.6
4343
github.com/gin-gonic/gin v1.10.1
44+
github.com/glebarez/sqlite v1.11.0
4445
github.com/go-resty/resty/v2 v2.16.5
4546
github.com/go-webauthn/webauthn v0.13.4
4647
github.com/golang-jwt/jwt/v4 v4.5.2
@@ -85,8 +86,8 @@ require (
8586
gopkg.in/ldap.v3 v3.1.0
8687
gorm.io/driver/mysql v1.5.7
8788
gorm.io/driver/postgres v1.5.9
88-
gorm.io/driver/sqlite v1.5.6
89-
gorm.io/gorm v1.25.11
89+
gorm.io/driver/sqlite v1.6.0
90+
gorm.io/gorm v1.30.0
9091
)
9192

9293
require (
@@ -105,10 +106,12 @@ require (
105106
github.com/cloudsoda/sddl v0.0.0-20250224235906-926454e91efc // indirect
106107
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
107108
github.com/cronokirby/saferith v0.33.0 // indirect
109+
github.com/dustin/go-humanize v1.0.1 // indirect
108110
github.com/ebitengine/purego v0.8.4 // indirect
109111
github.com/emersion/go-message v0.18.2 // indirect
110112
github.com/emersion/go-vcard v0.0.0-20241024213814-c9703dde27ff // indirect
111113
github.com/geoffgarside/ber v1.2.0 // indirect
114+
github.com/glebarez/go-sqlite v1.21.2 // indirect
112115
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
113116
github.com/hashicorp/go-uuid v1.0.3 // indirect
114117
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
@@ -118,17 +121,23 @@ require (
118121
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
119122
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
120123
github.com/lanrat/extsort v1.0.2 // indirect
124+
github.com/mattn/go-sqlite3 v1.14.22 // indirect
121125
github.com/mikelolasagasti/xz v1.0.1 // indirect
122126
github.com/minio/minlz v1.0.0 // indirect
123127
github.com/minio/xxml v0.0.3 // indirect
124128
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
125129
github.com/quic-go/qpack v0.5.1 // indirect
126130
github.com/relvacode/iso8601 v1.6.0 // indirect
131+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
127132
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
128133
go.uber.org/mock v0.5.0 // indirect
129134
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
130135
golang.org/x/mod v0.30.0 // indirect
131136
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
137+
modernc.org/libc v1.22.5 // indirect
138+
modernc.org/mathutil v1.5.0 // indirect
139+
modernc.org/memory v1.5.0 // indirect
140+
modernc.org/sqlite v1.23.1 // indirect
132141
)
133142

134143
require (
@@ -244,7 +253,6 @@ require (
244253
github.com/mattn/go-isatty v0.0.20 // indirect
245254
github.com/mattn/go-localereader v0.0.1 // indirect
246255
github.com/mattn/go-runewidth v0.0.16 // indirect
247-
github.com/mattn/go-sqlite3 v1.14.22 // indirect
248256
github.com/minio/sha256-simd v1.0.1 // indirect
249257
github.com/mitchellh/go-homedir v1.1.0 // indirect
250258
github.com/mitchellh/mapstructure v1.5.0 // indirect

go.sum

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cn
246246
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 h1:2tV76y6Q9BB+NEBasnqvs7e49aEBFI8ejC89PSnWH+4=
247247
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707/go.mod h1:qssHWj60/X5sZFNxpG4HBPDHVqxNm4DfnCKgrbZOT+s=
248248
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
249+
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
250+
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
249251
github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 h1:I6KUy4CI6hHjqnyJLNCEi7YHVMkwwtfSr2k9splgdSM=
250252
github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564/go.mod h1:yekO+3ZShy19S+bsmnERmznGy9Rfg6dWWWpiGJjNAz8=
251253
github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw=
@@ -279,6 +281,10 @@ github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w
279281
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
280282
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
281283
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
284+
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
285+
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
286+
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
287+
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
282288
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
283289
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
284290
github.com/go-darwin/apfs v0.0.0-20211011131704-f84b94dbf348 h1:JnrjqG5iR07/8k7NqrLNilRsl3s1EPRQEGvbPyOce68=
@@ -335,6 +341,8 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
335341
github.com/google/go-tpm v0.9.5 h1:ocUmnDebX54dnW+MQWGQRbdaAcJELsa6PqZhJ48KwVU=
336342
github.com/google/go-tpm v0.9.5/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
337343
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
344+
github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b h1:Qcx5LM0fSiks9uCyFZwDBUasd3lxd1RM0GYpL+Li5o4=
345+
github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
338346
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
339347
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
340348
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -574,6 +582,9 @@ github.com/rclone/rclone v1.70.3 h1:rg/WNh4DmSVZyKP2tHZ4lAaWEyMi7h/F0r7smOMA3IE=
574582
github.com/rclone/rclone v1.70.3/go.mod h1:nLyN+hpxAsQn9Rgt5kM774lcRDad82x/KqQeBZ83cMo=
575583
github.com/relvacode/iso8601 v1.6.0 h1:eFXUhMJN3Gz8Rcq82f9DTMW0svjtAVuIEULglM7QHTU=
576584
github.com/relvacode/iso8601 v1.6.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I=
585+
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
586+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
587+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
577588
github.com/rfjakob/eme v1.1.2 h1:SxziR8msSOElPayZNFfQw4Tjx/Sbaeeh3eRvrHVMUs4=
578589
github.com/rfjakob/eme v1.1.2/go.mod h1:cVvpasglm/G3ngEfcfT/Wt0GwhkuO32pf/poW6Nyk1k=
579590
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -844,13 +855,21 @@ gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
844855
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
845856
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
846857
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
847-
gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
848-
gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
858+
gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ=
859+
gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8=
849860
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
850-
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
851-
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
861+
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
862+
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
852863
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
853864
lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
865+
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
866+
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
867+
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
868+
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
869+
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
870+
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
871+
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
872+
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
854873
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
855874
resty.dev/v3 v3.0.0-beta.2 h1:xu4mGAdbCLuc3kbk7eddWfWm4JfhwDtdapwss5nCjnQ=
856875
resty.dev/v3 v3.0.0-beta.2/go.mod h1:OgkqiPvTDtOuV4MGZuUDhwOpkY8enjOsjjMzeOHefy4=

internal/bootstrap/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"github.com/OpenListTeam/OpenList/v4/cmd/flags"
1010
"github.com/OpenListTeam/OpenList/v4/internal/conf"
1111
"github.com/OpenListTeam/OpenList/v4/internal/db"
12+
"github.com/glebarez/sqlite"
1213
log "github.com/sirupsen/logrus"
1314
"gorm.io/driver/mysql"
1415
"gorm.io/driver/postgres"
15-
"gorm.io/driver/sqlite"
1616
"gorm.io/gorm"
1717
"gorm.io/gorm/logger"
1818
"gorm.io/gorm/schema"

internal/media/scanner.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func doScan(cfg *model.MediaConfig, p *ScanProgress) error {
134134

135135
if cfg.PathMerge {
136136
// 路径合并模式:每个子文件夹作为一个条目
137-
entries, err := fs.List(ctx, scanRoot, &fs.ListArgs{NoLog: true})
137+
// 先刷新根目录缓存,再扫描
138+
entries, err := fs.List(ctx, scanRoot, &fs.ListArgs{NoLog: true, Refresh: true})
138139
if err != nil {
139140
return err
140141
}
@@ -144,7 +145,7 @@ func doScan(cfg *model.MediaConfig, p *ScanProgress) error {
144145
}
145146
}
146147
} else {
147-
// 普通模式:递归扫描所有匹配文件
148+
// 普通模式:递归扫描所有匹配文件(每个目录都刷新缓存)
148149
if err := walkVFS(ctx, scanRoot, cfg.MediaType, &targets); err != nil {
149150
return err
150151
}
@@ -209,9 +210,9 @@ func FetchFileReader(ctx context.Context, vfsPath string) io.ReadCloser {
209210
return resp.Body
210211
}
211212

212-
// walkVFS 递归遍历 VFS 路径,收集匹配的媒体文件路径
213+
// walkVFS 递归遍历 VFS 路径,收集匹配的媒体文件路径(每个目录都刷新缓存)
213214
func walkVFS(ctx context.Context, dirPath string, mediaType model.MediaType, targets *[]string) error {
214-
entries, err := fs.List(ctx, dirPath, &fs.ListArgs{NoLog: true})
215+
entries, err := fs.List(ctx, dirPath, &fs.ListArgs{NoLog: true, Refresh: true})
215216
if err != nil {
216217
log.Warnf("media scan: list vfs path [%s] error: %v", dirPath, err)
217218
return nil // 跳过无权限目录,不中断整体扫描

server/handles/down.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ func Proxy(c *gin.Context) {
5656
common.ErrorPage(c, err, 500)
5757
return
5858
}
59-
if canProxy(storage, filename) {
59+
// 支持 ?force 参数强制代理(用于媒体库等需要 JS 加载文件内容的场景,避免 CORS 问题)
60+
_, forceProxy := c.GetQuery("force")
61+
if forceProxy || canProxy(storage, filename) {
6062
if _, ok := c.GetQuery("d"); !ok {
6163
if url := common.GenerateDownProxyURL(storage.GetStorage(), rawPath); url != "" {
6264
c.Redirect(302, url)

0 commit comments

Comments
 (0)