mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-04-18 14:23:34 +02:00
fixed formatting
This commit is contained in:
parent
a5ceee33df
commit
5fb1e85372
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
- Added video and audio file previews.
|
- 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
|
## v0.11.1
|
||||||
|
|
||||||
|
@ -98,6 +98,18 @@ 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.
|
||||||
|
//
|
||||||
|
// 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.
|
// Upload writes content into the fileKey location.
|
||||||
func (s *System) Upload(content []byte, fileKey string) error {
|
func (s *System) Upload(content []byte, fileKey string) error {
|
||||||
opts := &blob.WriterOptions{
|
opts := &blob.WriterOptions{
|
||||||
@ -285,16 +297,6 @@ var manualExtensionContentTypes = map[string]string{
|
|||||||
".css": "text/css", // (see https://github.com/gabriel-vasile/mimetype/pull/113)
|
".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.
|
// 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 {
|
func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey string, name string) error {
|
||||||
br, readErr := s.bucket.NewReader(s.ctx, fileKey, nil)
|
br, readErr := s.bucket.NewReader(s.ctx, fileKey, nil)
|
||||||
|
@ -348,6 +348,7 @@ func TestFileSystemServe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileSystemGetFile(t *testing.T) {
|
func TestFileSystemGetFile(t *testing.T) {
|
||||||
dir := createTestDir(t)
|
dir := createTestDir(t)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
@ -358,15 +359,17 @@ func TestFileSystemGetFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer fs.Close()
|
defer fs.Close()
|
||||||
|
|
||||||
f, fErr := fs.GetFile("image.png")
|
f, err := fs.GetFile("image.png")
|
||||||
if fErr != nil {
|
if err != nil {
|
||||||
t.Fatal(fErr)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
if f == nil {
|
if f == nil {
|
||||||
t.Fatal("File is supposed to be found")
|
t.Fatal("File is supposed to be found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileSystemServeSingleRange(t *testing.T) {
|
func TestFileSystemServeSingleRange(t *testing.T) {
|
||||||
dir := createTestDir(t)
|
dir := createTestDir(t)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user