commit e7d3ccfd4186c0f4fa196dc3f282fee6140702db from: Oliver Lowe date: Fri Mar 15 00:12:04 2024 UTC cmd/apget: add little tool for downloading objects commit - 662ec9733f1620bf3657cc08bf574d45f7ca1de9 commit + e7d3ccfd4186c0f4fa196dc3f282fee6140702db blob - /dev/null blob + 3388f1a80c40332a3159524dbd23d3e97170a27f (mode 644) --- /dev/null +++ cmd/apget/apget.go @@ -0,0 +1,61 @@ +// Command apget retrieves the ActivityPub object accessible at url +// and prints a JSON-encoded representation to the standard output. +// +// Its usage is: +// +// apget [-m] url +// +// The flags understood are: +// +// -m +// Print the activity as a RFC5322 message +// +// # Examples +// +// Deliver a Mastodon post to a local user using apsend: +// +// apget -m https://hachyderm.io/@otl/112093503066930591 | apsend otl +package main + +import ( + "encoding/json" + "flag" + "log" + "os" + + "olowe.co/apub" +) + +var mflag bool + +func init() { + flag.BoolVar(&mflag, "m", false, "format as mail") + flag.Parse() +} + +const usage = "apget [-m] url" + +func main() { + if len(flag.Args()) != 1 { + log.Fatalln("usage:", usage) + } + activity, err := apub.Lookup(flag.Args()[0]) + if err != nil { + log.Fatalf("lookup %s: %v", flag.Args()[0], err) + } + if mflag { + msg, err := apub.MarshalMail(activity) + if err != nil { + log.Println(err) + } + if _, err := os.Stdout.Write(msg); err != nil { + log.Fatal(err) + } + return + } + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", " ") + if err := enc.Encode(activity); err != nil { + os.Exit(1) + } +}