From 8daa6845cf5b6a2fdbeba7e26cc1100cfc7fe1c8 Mon Sep 17 00:00:00 2001 From: Laura Brekelmans Date: Fri, 1 Aug 2025 17:43:50 +0200 Subject: [PATCH 1/3] Add option to show (not hide) template files in ls command and filter nodes accordingly --- model/document.go | 1 + shell/ls.go | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/model/document.go b/model/document.go index 247b54c2..39269ef7 100644 --- a/model/document.go +++ b/model/document.go @@ -3,6 +3,7 @@ package model const ( DirectoryType = "CollectionType" DocumentType = "DocumentType" + TemplateType = "TemplateType" ) type Document struct { diff --git a/shell/ls.go b/shell/ls.go index c2f7ef66..abdc272f 100644 --- a/shell/ls.go +++ b/shell/ls.go @@ -10,6 +10,21 @@ import ( flag "github.com/ogier/pflag" ) +func filterNodes(in []*model.Node, options LsOptions) []*model.Node { + var filtered []*model.Node + if options.ShowTemplates { + filtered = in + } + if !options.ShowTemplates { + for _, node := range in { + if node.Document.Type != model.TemplateType { + filtered = append(filtered, node) + } + } + } + return filtered +} + func sortNodes(in []*model.Node, options LsOptions) []*model.Node { sort.SliceStable(in, func(i, j int) bool { if options.DirFirst { @@ -62,11 +77,12 @@ func displayNode(c *ishell.Context, e *model.Node, d LsOptions) { } type LsOptions struct { - Long bool - Compact bool - Reverse bool - DirFirst bool - ByTime bool + Long bool + Compact bool + Reverse bool + DirFirst bool + ByTime bool + ShowTemplates bool } func lsCmd(ctx *ShellCtxt) *ishell.Cmd { @@ -82,6 +98,7 @@ func lsCmd(ctx *ShellCtxt) *ishell.Cmd { flagSet.BoolVarP(&d.Reverse, "reverse", "r", false, "reverse sort") flagSet.BoolVarP(&d.DirFirst, "group-directories", "d", false, "group directories") flagSet.BoolVarP(&d.ByTime, "time", "t", false, "sort by time") + flagSet.BoolVarP(&d.ShowTemplates, "show-templates", "s", false, "don't hide template files") if err := flagSet.Parse(c.Args); err != nil { if err != flag.ErrHelp { c.Err(err) @@ -104,7 +121,7 @@ func lsCmd(ctx *ShellCtxt) *ishell.Cmd { } } - sorted := sortNodes(nodes, d) + sorted := sortNodes(filterNodes(nodes, d), d) for _, e := range sorted { displayNode(c, e, d) From 2d3276c3aa6aaceeae02d9055f9a811dfa9ca3df Mon Sep 17 00:00:00 2001 From: Marco Barcelos Date: Mon, 18 May 2026 16:26:15 -0300 Subject: [PATCH 2/3] fix: add .docSchema extension when fetching document index in Mirror BlobDoc.Mirror() was passing only the UUID as rm-filename header when fetching the document index blob. The API requires UUID.docSchema, consistent with how uploads already use addExt(doc.DocumentID, DocSchemaExt). Fixes status 400 on document blob fetches --- api/sync15/blobdoc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/sync15/blobdoc.go b/api/sync15/blobdoc.go index 3aab17d0..46199ce5 100644 --- a/api/sync15/blobdoc.go +++ b/api/sync15/blobdoc.go @@ -214,7 +214,7 @@ func (d *BlobDoc) LineWithSchema(schema string) string { // Mirror updates the document to be the same as the remote func (d *BlobDoc) Mirror(e *Entry, r RemoteStorage) error { d.Entry = *e - entryIndex, err := r.GetReader(e.Hash, e.DocumentID) + entryIndex, err := r.GetReader(e.Hash, addExt(e.DocumentID, archive.DocSchemaExt)) if err != nil { return err } From 33c484f3da6eedff39de119ca9b676e8f66e6ff4 Mon Sep 17 00:00:00 2001 From: Laura Brekelmans Date: Wed, 7 Jan 2026 16:37:48 +0100 Subject: [PATCH 3/3] Add ability to download files by ID --- README.md | 14 ++++++++++++++ shell/get.go | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a115d626..2c6edcdb 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,20 @@ mput (-src sourcfolder) /Papers Use `get path_to_file` to download a file from the cloud to your local computer. +### Download flags + +- `--id`: Interpret the argument as a document ID instead of a path. This is useful when you have the document ID from the `find` command's JSON output. + +Examples: + +```bash +# Download by path +get /Books/MyBook + +# Download by document ID (find document ID using the stat command or --json flag) +get --id abc123-def456-789 +``` + ## Recursively download directories and files Use `mget path_to_dir` to recursively download all the files in that directory. diff --git a/shell/get.go b/shell/get.go index 88c7face..644a20e2 100644 --- a/shell/get.go +++ b/shell/get.go @@ -5,11 +5,13 @@ import ( "fmt" "github.com/abiosoft/ishell" + "github.com/juruen/rmapi/model" "github.com/juruen/rmapi/util" + "github.com/ogier/pflag" ) func getCmd(ctx *ShellCtxt) *ishell.Cmd { - longHelp := `Usage: get ` + longHelp := `Usage: get [--id] ` return &ishell.Cmd{ Name: "get", @@ -17,25 +19,43 @@ func getCmd(ctx *ShellCtxt) *ishell.Cmd { Completer: createEntryCompleter(ctx), LongHelp: longHelp, Func: func(c *ishell.Context) { - if checkHelp(longHelp, c.Args, c) { + flagSet := pflag.NewFlagSet("get", pflag.ContinueOnError) + var byId bool + flagSet.BoolVar(&byId, "id", false, "interpret argument as document ID instead of path") + if !processFlagSet(flagSet, longHelp, c.Args, c) { return } + args := flagSet.Args() - if len(c.Args) == 0 { - c.Err(errors.New("missing source file")) + if len(args) == 0 { + c.Err(errors.New("missing source file or id")) return } - srcName := c.Args[0] + srcArg := args[0] + var node *model.Node + var err error - node, err := ctx.api.Filetree().NodeByPath(srcName, ctx.node) + if byId { + node = ctx.api.Filetree().NodeById(srcArg) + if node == nil { + c.Err(errors.New("document with given ID doesn't exist")) + return + } + } else { + node, err = ctx.api.Filetree().NodeByPath(srcArg, ctx.node) + if err != nil { + c.Err(errors.New("file doesn't exist")) + return + } + } - if err != nil || node.IsDirectory() { - c.Err(errors.New("file doesn't exist")) + if node.IsDirectory() { + c.Err(errors.New("cannot download a directory")) return } - c.Println(fmt.Sprintf("downloading: [%s]...", srcName)) + c.Println(fmt.Sprintf("downloading: [%s]...", node.Name())) err = ctx.api.FetchDocument(node.Document.ID, fmt.Sprintf("%s.%s", node.Name(), util.RMDOC)) @@ -44,7 +64,7 @@ func getCmd(ctx *ShellCtxt) *ishell.Cmd { return } - c.Err(errors.New(fmt.Sprintf("Failed to download file %s with %s", srcName, err.Error()))) + c.Err(errors.New(fmt.Sprintf("Failed to download file %s with %s", node.Name(), err.Error()))) }, } -} +} \ No newline at end of file