fix: 修复文件预览重定向与扩展名解析

This commit is contained in:
richjohnrambo
2026-09-09 16:32:49 +08:00
parent cae5039afe
commit 23afc1b7f1
7 changed files with 117 additions and 12 deletions
+20
View File
@@ -113,6 +113,11 @@ func largeFileServeHTTP(wrt http.ResponseWriter, req *http.Request) {
return
}
if err = authorizeLargeFileRequestURL(principal.TenantID, principal.UID, req.URL.String()); err != nil {
writeHttpResponse(decodeStoreError(err, "", now, nil), err)
return
}
// Check if media handler redirects or adds headers.
headers, statusCode, err := mh.Headers(principal.TenantID, req.Method, req.URL, req.Header, true)
if err != nil {
@@ -517,6 +522,21 @@ func (*grpcNodeServer) LargeFileServe(req *pbx.FileDownReq, stream pbx.Node_Larg
return err
}
func authorizeLargeFileRequestURL(tenantID types.TenantID, uid types.Uid, rawURL string) error {
if store.Store == nil {
return types.ErrUnsupported
}
fid := store.Store.GetMediaHandler().GetIdFromUrl(rawURL)
if fid.IsZero() {
return types.ErrNotFound
}
fd, err := store.Files.Get(tenantID, fid.String())
if err != nil {
return err
}
return authorizeLargeFileDownload(tenantID, uid, rawURL, fd)
}
func authorizeLargeFileDownload(tenantID types.TenantID, uid types.Uid, rawURL string, fd *types.FileDef) error {
if fd == nil {
return types.ErrNotFound