CI / go (Media) (push) Successful in 14m33s
CI / go (Server) (push) Failing after 23m30s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 9m30s
CI / desktop (ubuntu-latest) (push) Successful in 1h21m24s
CI / mobile (push) Failing after 4m16s
CI / docker (push) Successful in 1h1m25s
Docs / build (push) Successful in 14m59s
Docs / deploy (push) Skipped
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Phase G of docs/AFFINE.md (ADR-17): - Invite links: one per workspace (member or guest, optional end date, optional admin approval) on a new /join page. Requests are approved (optionally as another role) or declined from workspace settings; join_request, join_approved and join_declined notifications reach the inbox, phones and the email digest. Workspace admins decide, else the organization's admins, else superadmins. Signup honours ?redirect=. - Workspace switches: allowSharing (off makes every share link answer 404 until it is back on) and urlPreview (chat apps may show private pages' titles). docwell-web writes title and Open Graph tags for known link-preview bots, asking docwell-server via DOCWELL_PREVIEW_API_URL; search engines are left out. - Page analytics: page_views counts opens per page, person and day from the existing visit call and share-link reads; editors see totals, a daily chart and recent viewers in the Info panel. analytics.prune drops rows after 400 days. - Unused files: attachments whose id appears in no page's Yjs state, page icon or comment (older than a day) are listed and deleted from workspace settings. - Migration, schema snapshot, OpenAPI, generated clients, translations in five languages, phone inbox, compose files and user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package directory
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"docwell/server/internal/apperr"
|
|
"docwell/server/internal/store/pocketbase"
|
|
)
|
|
|
|
// ---- Link previews for chat apps -------------------------------------------
|
|
//
|
|
// When a Docwell link is posted in Slack, Teams, Mattermost and the like,
|
|
// their bots fetch it to show a preview. docwell-web asks these lookups for
|
|
// what to put in the page's meta tags (ADR-17). A share link always gets its
|
|
// page's title and the start of its text, since anyone can read it anyway.
|
|
// A private page gets only its title and workspace, and only when the
|
|
// workspace turned URL previews on; pages restricted to some people never
|
|
// get one.
|
|
|
|
// PagePreview is what a chat app's link preview shows.
|
|
type PagePreview struct {
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
// Site is the workspace's name.
|
|
Site string `json:"site"`
|
|
}
|
|
|
|
func previewTitle(p pageRecord) string {
|
|
t := strings.TrimSpace(p.Title)
|
|
if t == "" {
|
|
t = "Untitled"
|
|
}
|
|
if p.Icon != "" {
|
|
t = p.Icon + " " + t
|
|
}
|
|
return t
|
|
}
|
|
|
|
// GetPagePreview previews a private page for a link; it is not found unless
|
|
// the page's workspace turned URL previews on.
|
|
func (s *Service) GetPagePreview(ctx context.Context, pageID string) (PagePreview, error) {
|
|
notFound := apperr.NotFound("no preview")
|
|
p, err := s.getPage(ctx, pageID)
|
|
if err != nil || p.DeletedAt != "" || p.Restricted {
|
|
return PagePreview{}, notFound
|
|
}
|
|
ws, err := s.getWorkspace(ctx, p.Workspace)
|
|
if err != nil || !ws.URLPreview {
|
|
return PagePreview{}, notFound
|
|
}
|
|
return PagePreview{Title: previewTitle(p), Site: ws.Name}, nil
|
|
}
|
|
|
|
// GetSharePreview previews a page reached through a share link (pageID ""
|
|
// for the shared page itself).
|
|
func (s *Service) GetSharePreview(ctx context.Context, token, pageID string) (PagePreview, error) {
|
|
link, p, _, err := s.sharedScope(ctx, token, pageID)
|
|
if err != nil {
|
|
return PagePreview{}, err
|
|
}
|
|
out := PagePreview{Title: previewTitle(p)}
|
|
if ws, err := s.getWorkspace(ctx, link.Workspace); err == nil {
|
|
out.Site = ws.Name
|
|
}
|
|
res, err := pocketbase.List[struct {
|
|
ContentText string `json:"content_text"`
|
|
}](ctx, s.pb, "pages", pocketbase.ListOptions{PerPage: 1, Filter: fmt.Sprintf("id = '%s'", p.ID), Fields: "content_text"})
|
|
if err == nil && len(res.Items) > 0 {
|
|
out.Description = excerpt(res.Items[0].ContentText)
|
|
}
|
|
return out, nil
|
|
}
|