1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2024-11-28 10:03:42 +02:00

fixed formatting

This commit is contained in:
Gani Georgiev 2023-01-12 13:44:37 +02:00
parent a5ceee33df
commit 5fb1e85372
3 changed files with 20 additions and 13 deletions

View File

@ -4,6 +4,8 @@
- Added video and audio file previews.
- Added `filesystem.GetFile()` helper to read files through the FileSystem abstraction ([#1578](https://github.com/pocketbase/pocketbase/pull/1578); thanks @avarabyeu).
## v0.11.1

View File

@ -98,6 +98,18 @@ func (s *System) Attributes(fileKey string) (*blob.Attributes, error) {
return s.bucket.Attributes(s.ctx, fileKey)
}
// GetFile returns a file content reader for the given fileKey.
//
// NB! Make sure to call `Close()` after you are done working with it.
func (s *System) GetFile(fileKey string) (io.ReadCloser, error) {
br, err := s.bucket.NewReader(s.ctx, fileKey, nil)
if err != nil {
return nil, err
}
return br, nil
}
// Upload writes content into the fileKey location.
func (s *System) Upload(content []byte, fileKey string) error {
opts := &blob.WriterOptions{
@ -285,16 +297,6 @@ var manualExtensionContentTypes = map[string]string{
".css": "text/css", // (see https://github.com/gabriel-vasile/mimetype/pull/113)
}
// / GetFile returns a file content reader for given file key
// / NB! Make sure to call `Close()` after you are done working with it.
func (s *System) GetFile(fileKey string) (io.ReadCloser, error) {
br, readErr := s.bucket.NewReader(s.ctx, fileKey, nil)
if readErr != nil {
return nil, readErr
}
return br, nil
}
// Serve serves the file at fileKey location to an HTTP response.
func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey string, name string) error {
br, readErr := s.bucket.NewReader(s.ctx, fileKey, nil)

View File

@ -348,6 +348,7 @@ func TestFileSystemServe(t *testing.T) {
}
}
}
func TestFileSystemGetFile(t *testing.T) {
dir := createTestDir(t)
defer os.RemoveAll(dir)
@ -358,15 +359,17 @@ func TestFileSystemGetFile(t *testing.T) {
}
defer fs.Close()
f, fErr := fs.GetFile("image.png")
if fErr != nil {
t.Fatal(fErr)
f, err := fs.GetFile("image.png")
if err != nil {
t.Fatal(err)
}
defer f.Close()
if f == nil {
t.Fatal("File is supposed to be found")
}
}
func TestFileSystemServeSingleRange(t *testing.T) {
dir := createTestDir(t)
defer os.RemoveAll(dir)