mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-30 23:44:59 +00:00
fix: pkg/downloader
should respect basePath for file://
urls (#2481)
* pass basePath down to pkg/downloader Signed-off-by: Dave Lee <dave@gray101.com> * enforce Signed-off-by: Dave Lee <dave@gray101.com> --------- Signed-off-by: Dave Lee <dave@gray101.com>
This commit is contained in:
parent
bdd6769b2d
commit
2fc6fe806b
9 changed files with 23 additions and 17 deletions
|
@ -23,7 +23,7 @@ const (
|
|||
GithubURI2 = "github://"
|
||||
)
|
||||
|
||||
func GetURI(url string, f func(url string, i []byte) error) error {
|
||||
func GetURI(url string, basePath string, f func(url string, i []byte) error) error {
|
||||
url = ConvertURL(url)
|
||||
|
||||
if strings.HasPrefix(url, "file://") {
|
||||
|
@ -33,6 +33,11 @@ func GetURI(url string, f func(url string, i []byte) error) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Check if the local file is rooted in basePath
|
||||
err = utils.VerifyPath(resolvedFile, basePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Read the response body
|
||||
body, err := os.ReadFile(resolvedFile)
|
||||
if err != nil {
|
||||
|
|
|
@ -10,7 +10,7 @@ var _ = Describe("Gallery API tests", func() {
|
|||
Context("URI", func() {
|
||||
It("parses github with a branch", func() {
|
||||
Expect(
|
||||
GetURI("github:go-skynet/model-gallery/gpt4all-j.yaml", func(url string, i []byte) error {
|
||||
GetURI("github:go-skynet/model-gallery/gpt4all-j.yaml", "", func(url string, i []byte) error {
|
||||
Expect(url).To(Equal("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml"))
|
||||
return nil
|
||||
}),
|
||||
|
@ -18,7 +18,7 @@ var _ = Describe("Gallery API tests", func() {
|
|||
})
|
||||
It("parses github without a branch", func() {
|
||||
Expect(
|
||||
GetURI("github:go-skynet/model-gallery/gpt4all-j.yaml@main", func(url string, i []byte) error {
|
||||
GetURI("github:go-skynet/model-gallery/gpt4all-j.yaml@main", "", func(url string, i []byte) error {
|
||||
Expect(url).To(Equal("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml"))
|
||||
return nil
|
||||
}),
|
||||
|
@ -26,7 +26,7 @@ var _ = Describe("Gallery API tests", func() {
|
|||
})
|
||||
It("parses github with urls", func() {
|
||||
Expect(
|
||||
GetURI("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml", func(url string, i []byte) error {
|
||||
GetURI("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml", "", func(url string, i []byte) error {
|
||||
Expect(url).To(Equal("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml"))
|
||||
return nil
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue