Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(*): add "aggregate" fields to VersionInfo & listen for cloud event in collection #1900

Merged
merged 6 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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