Release Please / Release Please (push) Skipped
Release / GoReleaser (push) Skipped
Tests / Secret scan (gitleaks) (push) Skipped
Tests / Test (Go 1.25) (push) Skipped
Tests / Test (Go stable) (push) Skipped
Tests / Secret scan (gitleaks) (pull_request) Successful in 4s
Tests / Test (Go stable) (pull_request) Successful in 1m21s
Tests / Test (Go 1.25) (pull_request) Successful in 1m27s
The conversion / link / sheet commits predate the tree cleanup, so their comments and README/test examples still carried internal refs. Re-apply the genericization (no internal hosts, personal names or client file ids).
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
onlyoffice "github.com/eslider/go-onlyoffice"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(linkCmd())
|
|
}
|
|
|
|
// linkCmd prints deep links for file ids. Used to build third-party document
|
|
// packs whose cover embeds links to contracts and supporting files. File ids
|
|
// come from `oo projects files list` / `oo dav ls`; `oo projects files
|
|
// replace-in` keeps them clean when a document is re-uploaded.
|
|
func linkCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "link FILE_ID [FILE_ID...]",
|
|
Short: "Print OnlyOffice DocEditor deep links (Products/Files/DocEditor.aspx?fileid=…)",
|
|
Args: cobra.MinimumNArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
c, err := newOO(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, id := range args {
|
|
printObject(map[string]any{
|
|
"fileid": id,
|
|
"title": fileTitle(cmd, c, id),
|
|
"url": c.FileEditorURL(id),
|
|
})
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
// fileTitle best-effort resolves a file title; never fails the command.
|
|
func fileTitle(cmd *cobra.Command, c *onlyoffice.Client, id string) string {
|
|
f, err := c.GetFile(cmd.Context(), id)
|
|
if err != nil || f == nil || f.Title == nil {
|
|
return ""
|
|
}
|
|
return *f.Title
|
|
}
|