From 0dae71afe65ca97de7d3e539975dd6e1a61b9d5e Mon Sep 17 00:00:00 2001 From: David Florness Date: Fri, 31 Dec 2021 19:06:22 -0600 Subject: [PATCH] Log uploads to file So that homeserver admins can know which media files that tallyard uploads can be deleted. --- election/utils.go | 22 ++++++++++++++++++++++ election/voter.go | 2 ++ 2 files changed, 24 insertions(+) create mode 100644 election/utils.go diff --git a/election/utils.go b/election/utils.go new file mode 100644 index 0000000..fbf78bc --- /dev/null +++ b/election/utils.go @@ -0,0 +1,22 @@ +package election + +import ( + "fmt" + "os" + "time" + + "github.com/kyoh86/xdg" + log "github.com/sirupsen/logrus" + "maunium.net/go/mautrix/id" +) + +func LogUpload(contentURI id.ContentURI) { + file, err := os.OpenFile(xdg.DataHome() + "/tallyard/uploads.tsv", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) + if err != nil { + log.Warnf("couldn't open uploads file: %s", err) + return + } + defer file.Close() + t, _ := time.Now().UTC().MarshalText() + fmt.Fprintf(file, "%s\t%s\n", string(t), contentURI.String()) +} diff --git a/election/voter.go b/election/voter.go index 9cbf541..2c9f1e3 100644 --- a/election/voter.go +++ b/election/voter.go @@ -191,6 +191,7 @@ func (el *Election) SendProvingKeys(client *mautrix.Client, eventStore *EventSto if err != nil { return fmt.Errorf("couldn't upload eval proving key: %s", err) } + LogUpload(uploadResp.ContentURI) evalProvingKeyURI = uploadResp.ContentURI } @@ -222,6 +223,7 @@ func (el *Election) SendProvingKeys(client *mautrix.Client, eventStore *EventSto if err != nil { return fmt.Errorf("couldn't upload sum proving key: %s", err) } + LogUpload(uploadResp.ContentURI) sumProvingKeyURI = uploadResp.ContentURI } -- 2.38.4