Merge pull request #10059 from FunkyM/local-image-store
Add support for internal image store
This commit is contained in:
@@ -162,6 +162,10 @@ func (hs *HttpServer) newMacaron() *macaron.Macaron {
|
||||
hs.mapStatic(m, setting.StaticRootPath, "", "public")
|
||||
hs.mapStatic(m, setting.StaticRootPath, "robots.txt", "robots.txt")
|
||||
|
||||
if setting.ImageUploadProvider == "local" {
|
||||
hs.mapStatic(m, setting.ImagesDir, "", "/public/img/attachments")
|
||||
}
|
||||
|
||||
m.Use(macaron.Renderer(macaron.RenderOptions{
|
||||
Directory: path.Join(setting.StaticRootPath, "views"),
|
||||
IndentJSON: macaron.Env != macaron.PROD,
|
||||
|
||||
@@ -88,6 +88,8 @@ func NewImageUploader() (ImageUploader, error) {
|
||||
container_name := azureBlobSec.Key("container_name").MustString("")
|
||||
|
||||
return NewAzureBlobUploader(account_name, account_key, container_name), nil
|
||||
case "local":
|
||||
return NewLocalImageUploader()
|
||||
}
|
||||
|
||||
if setting.ImageUploadProvider != "" {
|
||||
|
||||
@@ -143,5 +143,23 @@ func TestImageUploaderFactory(t *testing.T) {
|
||||
So(original.container_name, ShouldEqual, "container_name")
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Local uploader", func() {
|
||||
var err error
|
||||
|
||||
setting.NewConfigContext(&setting.CommandLineArgs{
|
||||
HomePath: "../../../",
|
||||
})
|
||||
|
||||
setting.ImageUploadProvider = "local"
|
||||
|
||||
uploader, err := NewImageUploader()
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
original, ok := uploader.(*LocalUploader)
|
||||
|
||||
So(ok, ShouldBeTrue)
|
||||
So(original, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package imguploader
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
type LocalUploader struct {
|
||||
}
|
||||
|
||||
func (u *LocalUploader) Upload(ctx context.Context, imageOnDiskPath string) (string, error) {
|
||||
filename := filepath.Base(imageOnDiskPath)
|
||||
image_url := setting.ToAbsUrl(path.Join("public/img/attachments", filename))
|
||||
return image_url, nil
|
||||
}
|
||||
|
||||
func NewLocalImageUploader() (*LocalUploader, error) {
|
||||
return &LocalUploader{}, nil
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package imguploader
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestUploadToLocal(t *testing.T) {
|
||||
Convey("[Integration test] for external_image_store.local", t, func() {
|
||||
localUploader, _ := NewLocalImageUploader()
|
||||
path, err := localUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png")
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(path, ShouldContainSubstring, "/public/img/attachments")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user