Skip to content

Commit 55efafa

Browse files
committed
fix: fixup multiple installs (strings.Clone)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 060793d commit 55efafa

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

core/http/elements/gallery.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ func DoneProgress(uid string) string {
2323
).Render()
2424
}
2525

26+
func ErrorProgress(err string) string {
27+
return elem.Div(
28+
attrs.Props{},
29+
elem.H3(
30+
attrs.Props{
31+
"role": "status",
32+
"id": "pblabel",
33+
"tabindex": "-1",
34+
"autofocus": "",
35+
},
36+
elem.Text("Error"+err),
37+
),
38+
).Render()
39+
}
40+
2641
func ProgressBar(progress string) string {
2742
return elem.Div(attrs.Props{
2843
"class": "progress",

core/http/routes/ui.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,25 @@ func RegisterUIRoutes(app *fiber.App,
5959

6060
// https://htmx.org/examples/progress-bar/
6161
app.Post("/browse/install/model/:id", auth, func(c *fiber.Ctx) error {
62-
galleryID := c.Params("id")
62+
galleryID := strings.Clone(c.Params("id")) // strings.Clone is required!
6363

64-
uuid, err := uuid.NewUUID()
64+
id, err := uuid.NewUUID()
6565
if err != nil {
6666
return err
6767
}
6868

69+
uid := id.String()
70+
71+
op := gallery.GalleryOp{
72+
Id: uid,
73+
GalleryName: galleryID,
74+
Galleries: appConfig.Galleries,
75+
}
6976
go func() {
70-
galleryService.C <- gallery.GalleryOp{
71-
Id: uuid.String(),
72-
GalleryName: galleryID,
73-
Galleries: appConfig.Galleries,
74-
}
77+
galleryService.C <- op
7578
}()
7679

77-
return c.SendString(elements.StartProgressBar(uuid.String(), "0"))
80+
return c.SendString(elements.StartProgressBar(uid, "0"))
7881
})
7982

8083
// https://htmx.org/examples/progress-bar/
@@ -87,10 +90,13 @@ func RegisterUIRoutes(app *fiber.App,
8790
return c.SendString(elements.ProgressBar("0"))
8891
}
8992

90-
if status.Processed || status.Progress == 100 {
93+
if status.Progress == 100 {
9194
c.Set("HX-Trigger", "done")
9295
return c.SendString(elements.ProgressBar("100"))
9396
}
97+
if status.Error != nil {
98+
return c.SendString(elements.ErrorProgress(status.Error.Error()))
99+
}
94100

95101
return c.SendString(elements.ProgressBar(fmt.Sprint(status.Progress)))
96102
})

pkg/downloader/progress.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ func (pw *progressWriter) Write(p []byte) (n int, err error) {
2020
percentage := float64(pw.written) / float64(pw.total) * 100
2121
if pw.totalFiles > 1 {
2222
// This is a multi-file download
23+
// so we need to adjust the percentage
24+
// to reflect the progress of the whole download
25+
// This is the file pw.fileNo of pw.totalFiles files. We assume that
26+
// the files before successfully downloaded.
2327
percentage = percentage / float64(pw.totalFiles)
2428
if pw.fileNo > 1 {
2529
percentage += float64(pw.fileNo-1) * 100 / float64(pw.totalFiles)

pkg/gallery/op.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package gallery
22

33
type GalleryOp struct {
4-
Req GalleryModel
54
Id string
6-
Galleries []Gallery
75
GalleryName string
86
ConfigURL string
7+
8+
Req GalleryModel
9+
Galleries []Gallery
910
}
1011

1112
type GalleryOpStatus struct {

0 commit comments

Comments
 (0)