soft-deprecated and replaced GetFile with GetReader

This commit is contained in:
Gani Georgiev 2025-05-02 11:26:06 +03:00
parent 87c6c5b483
commit 5dbd9821e8
5 changed files with 3021 additions and 3009 deletions

View File

@ -5,6 +5,9 @@
- Updated `app.DB()` to automatically routes raw write SQL statements to the nonconcurrent db pool ([#6689](https://github.com/pocketbase/pocketbase/discussions/6689)). - Updated `app.DB()` to automatically routes raw write SQL statements to the nonconcurrent db pool ([#6689](https://github.com/pocketbase/pocketbase/discussions/6689)).
_For the rare cases when it is needed users still have the option to explicitly target the specific pool they want using `app.ConcurrentDB()`/`app.NonconcurrentDB()`._ _For the rare cases when it is needed users still have the option to explicitly target the specific pool they want using `app.ConcurrentDB()`/`app.NonconcurrentDB()`._
- ⚠️ Soft-deprecated and replaced `fsys.GetFile(fileKey)` with `fsys.GetReader(fileKey)` to avoid the confusion with `filesystem.File`.
_The old method will still continue to work for at least until v0.29.0 but you'll get a console warning to replace it with `GetReader`._
## v0.27.2 ## v0.27.2

View File

@ -190,7 +190,7 @@ func (app *BaseApp) RestoreBackup(ctx context.Context, name string) error {
// extract the zip // extract the zip
if e.App.Settings().Backups.S3.Enabled { if e.App.Settings().Backups.S3.Enabled {
br, err := fsys.GetFile(name) br, err := fsys.GetReader(name)
if err != nil { if err != nil {
return err return err
} }

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,7 @@ import (
"strings" "strings"
"github.com/disintegration/imaging" "github.com/disintegration/imaging"
"github.com/fatih/color"
"github.com/gabriel-vasile/mimetype" "github.com/gabriel-vasile/mimetype"
"github.com/pocketbase/pocketbase/tools/filesystem/blob" "github.com/pocketbase/pocketbase/tools/filesystem/blob"
"github.com/pocketbase/pocketbase/tools/filesystem/internal/fileblob" "github.com/pocketbase/pocketbase/tools/filesystem/internal/fileblob"
@ -107,17 +108,21 @@ func (s *System) Attributes(fileKey string) (*blob.Attributes, error) {
return s.bucket.Attributes(s.ctx, fileKey) return s.bucket.Attributes(s.ctx, fileKey)
} }
// GetFile returns a file content reader for the given fileKey. // GetReader returns a file content reader for the given fileKey.
// //
// NB! Make sure to call Close() on the file after you are done working with it. // NB! Make sure to call Close() on the file after you are done working with it.
// //
// If the file doesn't exist returns ErrNotFound. // If the file doesn't exist returns ErrNotFound.
// func (s *System) GetReader(fileKey string) (*blob.Reader, error) {
// @todo consider renaming to GetFileReader to avoid the confusion with filesystem.File
func (s *System) GetFile(fileKey string) (*blob.Reader, error) {
return s.bucket.NewReader(s.ctx, fileKey) return s.bucket.NewReader(s.ctx, fileKey)
} }
// Deprecated: Please use GetReader(fileKey) instead.
func (s *System) GetFile(fileKey string) (*blob.Reader, error) {
color.Yellow("Deprecated: Please replace GetFile with GetReader.")
return s.GetReader(fileKey)
}
// Copy copies the file stored at srcKey to dstKey. // Copy copies the file stored at srcKey to dstKey.
// //
// If srcKey file doesn't exist, it returns ErrNotFound. // If srcKey file doesn't exist, it returns ErrNotFound.
@ -382,7 +387,7 @@ const forceAttachmentParam = "download"
// Internally this method uses [http.ServeContent] so Range requests, // Internally this method uses [http.ServeContent] so Range requests,
// If-Match, If-Unmodified-Since, etc. headers are handled transparently. // If-Match, If-Unmodified-Since, etc. headers are handled transparently.
func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey string, name string) error { func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey string, name string) error {
br, readErr := s.GetFile(fileKey) br, readErr := s.GetReader(fileKey)
if readErr != nil { if readErr != nil {
return readErr return readErr
} }
@ -454,7 +459,7 @@ func (s *System) CreateThumb(originalKey string, thumbKey, thumbSize string) err
} }
// fetch the original // fetch the original
r, readErr := s.GetFile(originalKey) r, readErr := s.GetReader(originalKey)
if readErr != nil { if readErr != nil {
return readErr return readErr
} }

View File

@ -526,7 +526,7 @@ func TestFileSystemServe(t *testing.T) {
} }
} }
func TestFileSystemGetFile(t *testing.T) { func TestFileSystemGetReader(t *testing.T) {
dir := createTestDir(t) dir := createTestDir(t)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
@ -547,7 +547,7 @@ func TestFileSystemGetFile(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
t.Run(s.file, func(t *testing.T) { t.Run(s.file, func(t *testing.T) {
f, err := fsys.GetFile(s.file) f, err := fsys.GetReader(s.file)
defer func() { defer func() {
if f != nil { if f != nil {
f.Close() f.Close()
@ -600,7 +600,7 @@ func TestFileSystemCopy(t *testing.T) {
if err := fsys.Copy(src, dst); err != nil { if err := fsys.Copy(src, dst); err != nil {
t.Fatalf("Failed to copy %q to %q: %v", src, dst, err) t.Fatalf("Failed to copy %q to %q: %v", src, dst, err)
} }
f, err := fsys.GetFile(dst) f, err := fsys.GetReader(dst)
//nolint //nolint
defer f.Close() defer f.Close()
if err != nil { if err != nil {
@ -801,7 +801,7 @@ func TestFileSystemCreateThumb(t *testing.T) {
return return
} }
f, err := fsys.GetFile(s.thumb) f, err := fsys.GetReader(s.thumb)
if err != nil { if err != nil {
t.Fatalf("Missing expected thumb %s (%v)", s.thumb, err) t.Fatalf("Missing expected thumb %s (%v)", s.thumb, err)
} }