Skip to content

Commit 6f3fc8b

Browse files
committed
Fix indexes get
1 parent 350d921 commit 6f3fc8b

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

docs/pkgs.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<p>An index file contains the info about a core and its tools. You can see an example at <a href="" target="_blank">https://downloads.arduino.cc/packages/package_index.json</a></p>
1212

13-
<p>index files are saved (with an urlencoded filename) in the folder ~/.arduino-create/indexes</p>
13+
<p>index files are saved (with an urlencoded filename) in the folder <code>~/.arduino-create/indexes</code></p>
1414

1515
<textarea cols="100" id="indexesGet">
1616
fetch('http://localhost:8991/v2/pkgs/indexes')
@@ -31,7 +31,6 @@
3131
target.innerHTML = res.statusText + "\n";
3232
return res.json();
3333
}).then(function (body) {
34-
debugger
3534
target.innerHTML = target.innerHTML + JSON.stringify(body, " ", " ");
3635
return;
3736
})

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func loop() {
289289
r.POST("/update", updateHandler)
290290

291291
// Mount goa handlers
292-
goa := v2.Server()
292+
goa := v2.Server(directory)
293293
r.Any("/v2/*path", gin.WrapH(goa))
294294

295295
go func() {

v2/http.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v2
33
import (
44
"context"
55
"net/http"
6+
"path/filepath"
67

78
docssvr "github.com/arduino/arduino-create-agent/gen/http/docs/server"
89
indexessvr "github.com/arduino/arduino-create-agent/gen/http/indexes/server"
@@ -15,7 +16,7 @@ import (
1516
"goa.design/goa/http/middleware"
1617
)
1718

18-
func Server() http.Handler {
19+
func Server(home string) http.Handler {
1920
mux := goahttp.NewMuxer()
2021

2122
// Instantiate logger
@@ -25,7 +26,8 @@ func Server() http.Handler {
2526

2627
// Mount indexes
2728
indexesSvc := pkgs.Indexes{
28-
Log: logger,
29+
Log: logger,
30+
Folder: filepath.Join(home, "indexes"),
2931
}
3032
indexesEndpoints := indexessvc.NewEndpoints(&indexesSvc)
3133
indexesServer := indexessvr.New(indexesEndpoints, mux, goahttp.RequestDecoder, goahttp.ResponseEncoder, errorHandler(logger))

v2/pkgs/indexes.go

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ func (c *Indexes) Get(ctx context.Context, uri string) (index Index, err error)
6969

7070
// List reads from the Indexes Folder and returns the indexes that have been downloaded
7171
func (c *Indexes) List(context.Context) ([]string, error) {
72+
// Create folder if it doesn't exist
73+
_ = os.MkdirAll(c.Folder, 0755)
7274
// Read files
7375
files, err := ioutil.ReadDir(c.Folder)
7476
if err != nil {

0 commit comments

Comments
 (0)