refactor: gallery inconsistencies (#2647)

* refactor(gallery): move under core/

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(unarchive): do not allow symlinks

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2024-06-24 17:32:12 +02:00 committed by GitHub
parent 69206fcd4b
commit a181dd0ebc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 93 additions and 54 deletions

View file

@ -6,7 +6,6 @@ import (
"encoding/json"
"time"
"github.com/mudler/LocalAI/pkg/gallery"
"github.com/mudler/LocalAI/pkg/xsysinfo"
"github.com/rs/zerolog/log"
)
@ -36,7 +35,7 @@ type ApplicationConfig struct {
ModelLibraryURL string
Galleries []gallery.Gallery
Galleries []Gallery
BackendAssets embed.FS
AssetsDestination string
@ -180,10 +179,10 @@ func WithBackendAssets(f embed.FS) AppOption {
func WithStringGalleries(galls string) AppOption {
return func(o *ApplicationConfig) {
if galls == "" {
o.Galleries = []gallery.Gallery{}
o.Galleries = []Gallery{}
return
}
var galleries []gallery.Gallery
var galleries []Gallery
if err := json.Unmarshal([]byte(galls), &galleries); err != nil {
log.Error().Err(err).Msg("failed loading galleries")
}
@ -191,7 +190,7 @@ func WithStringGalleries(galls string) AppOption {
}
}
func WithGalleries(galleries []gallery.Gallery) AppOption {
func WithGalleries(galleries []Gallery) AppOption {
return func(o *ApplicationConfig) {
o.Galleries = append(o.Galleries, galleries...)
}

View file

@ -390,10 +390,6 @@ func (c *BackendConfig) Validate() bool {
}
}
if c.Name == "" {
return false
}
if c.Backend != "" {
// a regex that checks that is a string name with no special characters, except '-' and '_'
re := regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)

View file

@ -16,7 +16,8 @@ var _ = Describe("Test cases for config related functions", func() {
Expect(err).To(BeNil())
defer os.Remove(tmp.Name())
_, err = tmp.WriteString(
`backend: "foo-bar"
`backend: "../foo-bar"
name: "foo"
parameters:
model: "foo-bar"`)
Expect(err).ToNot(HaveOccurred())

6
core/config/gallery.go Normal file
View file

@ -0,0 +1,6 @@
package config
type Gallery struct {
URL string `json:"url" yaml:"url"`
Name string `json:"name" yaml:"name"`
}