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

@ -9,7 +9,7 @@ import (
"sync"
"github.com/mudler/LocalAI/core/config"
"github.com/mudler/LocalAI/pkg/gallery"
"github.com/mudler/LocalAI/core/gallery"
"github.com/mudler/LocalAI/pkg/startup"
"github.com/mudler/LocalAI/pkg/utils"
"gopkg.in/yaml.v2"
@ -96,6 +96,7 @@ func (g *GalleryService) Start(c context.Context, cl *config.BackendConfigLoader
// delete a model
if op.Delete {
modelConfig := &config.BackendConfig{}
// Galleryname is the name of the model in this case
dat, err := os.ReadFile(filepath.Join(g.appConfig.ModelPath, op.GalleryModelName+".yaml"))
if err != nil {
@ -174,7 +175,7 @@ type galleryModel struct {
ID string `json:"id"`
}
func processRequests(modelPath string, galleries []gallery.Gallery, requests []galleryModel) error {
func processRequests(modelPath string, galleries []config.Gallery, requests []galleryModel) error {
var err error
for _, r := range requests {
utils.ResetDownloadTimers()
@ -189,7 +190,7 @@ func processRequests(modelPath string, galleries []gallery.Gallery, requests []g
return err
}
func ApplyGalleryFromFile(modelPath, s string, galleries []gallery.Gallery) error {
func ApplyGalleryFromFile(modelPath, s string, galleries []config.Gallery) error {
dat, err := os.ReadFile(s)
if err != nil {
return err
@ -203,7 +204,7 @@ func ApplyGalleryFromFile(modelPath, s string, galleries []gallery.Gallery) erro
return processRequests(modelPath, galleries, requests)
}
func ApplyGalleryFromString(modelPath, s string, galleries []gallery.Gallery) error {
func ApplyGalleryFromString(modelPath, s string, galleries []config.Gallery) error {
var requests []galleryModel
err := json.Unmarshal([]byte(s), &requests)
if err != nil {