Skip to content

Commit

Permalink
refactor(*): add "aggregate" fields to VersionInfo & listen for clo…
Browse files Browse the repository at this point in the history
…ud event in `collection`

Merge pull request #1900 from qri-io/ramfox/refactor_version_info
  • Loading branch information
ramfox authored Sep 3, 2021
2 parents 358ddd8 + 6dc15c8 commit 4725f38
Show file tree
Hide file tree
Showing 19 changed files with 1,029 additions and 676 deletions.
15 changes: 15 additions & 0 deletions api/handlers.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package api

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

"github.com/qri-io/qri/api/util"
"github.com/qri-io/qri/base/archive"
"github.com/qri-io/qri/event"
"github.com/qri-io/qri/lib"
)

Expand Down Expand Up @@ -38,6 +40,7 @@ func GetBodyCSVHandler(inst *lib.Instance) http.HandlerFunc {
util.RespondWithError(w, err)
return
}
publishDownloadEvent(r.Context(), inst, p.Ref)
writeFileResponse(w, outBytes, "body.csv", "csv")
}
}
Expand Down Expand Up @@ -71,6 +74,8 @@ func GetHandler(inst *lib.Instance, routePrefix string) http.HandlerFunc {
util.RespondWithError(w, err)
return
}

publishDownloadEvent(r.Context(), inst, p.Ref)
writeFileResponse(w, outBytes, "body.csv", "csv")
return

Expand All @@ -87,6 +92,7 @@ func GetHandler(inst *lib.Instance, routePrefix string) http.HandlerFunc {
util.RespondWithError(w, err)
return
}
publishDownloadEvent(r.Context(), inst, p.Ref)
writeFileResponse(w, zipResults.Bytes, zipResults.GeneratedName, "zip")
return

Expand Down Expand Up @@ -192,3 +198,12 @@ func arrayContains(subject []string, target string) bool {
}
return false
}

func publishDownloadEvent(ctx context.Context, inst *lib.Instance, refStr string) {
ref, _, err := inst.ParseAndResolveRef(ctx, refStr, "local")
if err != nil {
log.Debugw("api.GetBodyCSVHandler - unable to resolve ref %q", err)
return
}
inst.Bus().Publish(ctx, event.ETDatasetDownload, ref.InitID)
}
Loading

0 comments on commit 4725f38

Please sign in to comment.