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).
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package onlyoffice
|
|
|
|
// Deep links to OnlyOffice portal objects.
|
|
//
|
|
// Used by tools that embed per-file links of the form
|
|
// /Products/Files/DocEditor.aspx?fileid=<id> in a cover document or a chat
|
|
// message. Those links must be consistent so they match the file ids returned
|
|
// by `oo projects files list` / `oo link`.
|
|
//
|
|
// Caveat: file ids are server-assigned and a re-upload/delete yields a NEW id,
|
|
// so an already-shared link can go stale. Use `oo projects files replace-in`
|
|
// (keeps the id stable) and, if a legacy link must keep working, an nginx alias
|
|
// can 302 the old fileid to the new one.
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// FileEditorURL builds the OnlyOffice DocEditor deep link for a portal file id:
|
|
//
|
|
// https://<portal>/Products/Files/DocEditor.aspx?fileid=<id>
|
|
//
|
|
// portalBase may include a trailing slash; fileID is trimmed and URL-escaped.
|
|
func FileEditorURL(portalBase, fileID string) string {
|
|
base := strings.TrimRight(strings.TrimSpace(portalBase), "/")
|
|
return fmt.Sprintf("%s/Products/Files/DocEditor.aspx?fileid=%s",
|
|
base, url.QueryEscape(strings.TrimSpace(fileID)))
|
|
}
|
|
|
|
// FileEditorURL is the client-bound convenience wrapper (uses the portal URL
|
|
// the client was built with).
|
|
func (c *Client) FileEditorURL(fileID string) string {
|
|
return FileEditorURL(c.baseURL(), fileID)
|
|
}
|
|
|
|
// FolderURL builds a Documents-folder deep link for a folder id.
|
|
func FolderURL(portalBase, folderID string) string {
|
|
base := strings.TrimRight(strings.TrimSpace(portalBase), "/")
|
|
return fmt.Sprintf("%s/Products/Files/Default.aspx#folder=%s", base, url.QueryEscape(strings.TrimSpace(folderID)))
|
|
}
|
|
|
|
// FolderURL is the client-bound convenience wrapper.
|
|
func (c *Client) FolderURL(folderID string) string {
|
|
return FolderURL(c.baseURL(), folderID)
|
|
}
|