|
package assets |
|
|
|
import ( |
|
"embed" |
|
"fmt" |
|
"io/fs" |
|
"os" |
|
"path/filepath" |
|
|
|
"github.com/mudler/LocalAI/pkg/library" |
|
) |
|
|
|
func ResolvePath(dir string, paths ...string) string { |
|
return filepath.Join(append([]string{dir, "backend-assets"}, paths...)...) |
|
} |
|
|
|
func ExtractFiles(content embed.FS, extractDir string) error { |
|
|
|
err := os.MkdirAll(extractDir, 0750) |
|
if err != nil { |
|
return fmt.Errorf("failed to create directory: %v", err) |
|
} |
|
|
|
|
|
err = fs.WalkDir(content, ".", func(path string, d fs.DirEntry, err error) error { |
|
if err != nil { |
|
return err |
|
} |
|
|
|
|
|
targetFile := filepath.Join(extractDir, path) |
|
if d.IsDir() { |
|
|
|
err := os.MkdirAll(targetFile, 0750) |
|
if err != nil { |
|
return fmt.Errorf("failed to create directory: %v", err) |
|
} |
|
return nil |
|
} |
|
|
|
|
|
fileData, err := content.ReadFile(path) |
|
if err != nil { |
|
return fmt.Errorf("failed to read file: %v", err) |
|
} |
|
|
|
|
|
err = os.WriteFile(targetFile, fileData, 0700) |
|
if err != nil { |
|
return fmt.Errorf("failed to write file: %v", err) |
|
} |
|
|
|
return nil |
|
}) |
|
|
|
|
|
|
|
|
|
library.LoadExtractedLibs(extractDir) |
|
|
|
return err |
|
} |
|
|