From 0637632258c9148ca83ce61dc45b53d789b9c2da Mon Sep 17 00:00:00 2001
From: Michael Yang <mxyng@pm.me>
Date: Thu, 6 Jul 2023 12:30:36 -0700
Subject: [PATCH] simple pull response

---
 api/client.go    | 15 +--------------
 server/routes.go | 12 +++++++++++-
 2 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/api/client.go b/api/client.go
index b13e41ef2..4e434faea 100644
--- a/api/client.go
+++ b/api/client.go
@@ -8,7 +8,6 @@ import (
 	"fmt"
 	"io"
 	"net/http"
-	"strings"
 	"sync"
 )
 
@@ -140,20 +139,8 @@ func (c *Client) Pull(ctx context.Context, req *PullRequest, callback func(progr
 	var wg sync.WaitGroup
 	wg.Add(1)
 	if err := c.stream(ctx, http.MethodPost, "/api/pull", req, func(progressBytes []byte) {
-		/*
-			Events have the following format for progress:
-				event:progress
-				data:{"total":123,"completed":123,"percent":0.1}
-			Need to parse out the data part and unmarshal it.
-		*/
-		eventParts := strings.Split(string(progressBytes), "data:")
-		if len(eventParts) < 2 {
-			// no data part, ignore
-			return
-		}
-		eventData := eventParts[1]
 		var progress PullProgress
-		if err := json.Unmarshal([]byte(eventData), &progress); err != nil {
+		if err := json.Unmarshal(progressBytes, &progress); err != nil {
 			fmt.Println(err)
 			return
 		}
diff --git a/server/routes.go b/server/routes.go
index fdfc22ec7..a14cfe400 100644
--- a/server/routes.go
+++ b/server/routes.go
@@ -120,7 +120,17 @@ func Serve(ln net.Listener) error {
 			if !ok {
 				return false
 			}
-			c.SSEvent("progress", progress)
+
+			bts, err := json.Marshal(progress)
+			if err != nil {
+				return false
+			}
+
+			bts = append(bts, '\n')
+			if _, err := w.Write(bts); err != nil {
+				return false
+			}
+
 			return true
 		})
 	})