Add public share links and the share dialog
Editors can give a page a public link that anyone can read without an account, optionally with the pages under it. The link is the stored token, so editors can copy it again later; turning sharing off deletes it and the URL stops working. Reads through a link never reach trashed pages, pages outside the shared subtree, or their attachments, and are marked noindex. The page header gets a Share button: the dialog explains who can open the page through its space, lists the space's people and groups, copies the page link and manages the public link. Shared pages open at /share/<token> in a read-only view with a tree of the shared subpages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
011833fcef
commit
dac6d6da63
16 files changed
+1177
No files matched your search
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
// Public share links: anyone with the link can read the page (and, if
|
||||
// include_subpages, the pages under it) without signing in. The token is the
|
||||
// link itself, so it is stored as is and shown to editors again; deleting the
|
||||
// record revokes the link.
|
||||
|
||||
migrate(
|
||||
(app) => {
|
||||
const users = app.findCollectionByNameOrId("users");
|
||||
const pages = app.findCollectionByNameOrId("pages");
|
||||
const workspaces = app.findCollectionByNameOrId("workspaces");
|
||||
|
||||
app.save(
|
||||
new Collection({
|
||||
type: "base",
|
||||
name: "share_links",
|
||||
fields: [
|
||||
{ name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true },
|
||||
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
||||
{ name: "token", type: "text", required: true, min: 24, max: 64 },
|
||||
{ name: "include_subpages", type: "bool" },
|
||||
{ name: "created_by", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: false },
|
||||
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
||||
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
||||
],
|
||||
indexes: [
|
||||
"CREATE UNIQUE INDEX idx_share_links_token ON share_links (token)",
|
||||
"CREATE UNIQUE INDEX idx_share_links_page ON share_links (page)",
|
||||
],
|
||||
}),
|
||||
);
|
||||
},
|
||||
(app) => {
|
||||
try {
|
||||
app.delete(app.findCollectionByNameOrId("share_links"));
|
||||
} catch (_) {}
|
||||
},
|
||||
);
|
||||
@@ -37,6 +37,8 @@ export type Group = Schemas["Group"];
|
||||
export type PageItem = Schemas["PageItem"];
|
||||
export type Attachment = Schemas["Attachment"];
|
||||
export type SearchHit = Schemas["SearchHit"];
|
||||
export type ShareLink = Schemas["ShareLink"];
|
||||
export type SharedPage = Schemas["SharedPage"];
|
||||
export type SearchResult = Schemas["SearchResult"];
|
||||
export type GroupRequest = Schemas["GroupRequest"];
|
||||
export type SpaceGroup = Schemas["SpaceGroup"];
|
||||
@@ -170,6 +172,15 @@ export function createClient(opts: ClientOptions) {
|
||||
removeAttachment: (id: string) => request<void>("DELETE", `/api/v1/attachments/${encodeURIComponent(id)}`),
|
||||
},
|
||||
|
||||
/** Reading pages through a public link (no session needed). */
|
||||
share: {
|
||||
get: (token: string, page?: string) =>
|
||||
request<SharedPage>(
|
||||
"GET",
|
||||
`/api/v1/share/${encodeURIComponent(token)}${page ? `/pages/${encodeURIComponent(page)}` : ""}`,
|
||||
),
|
||||
},
|
||||
|
||||
invites: {
|
||||
list: (params: { workspace?: string; organization?: string } = {}) =>
|
||||
request<Invite[]>("GET", `/api/v1/invites${query(params)}`),
|
||||
@@ -298,6 +309,11 @@ export function createClient(opts: ClientOptions) {
|
||||
form.append("file", file, name);
|
||||
return upload<Attachment>(`/api/v1/pages/${encodeURIComponent(id)}/attachments`, form);
|
||||
},
|
||||
/** The public link; rejects with a 404 ApiError when sharing is off. */
|
||||
shareLink: (id: string) => request<ShareLink>("GET", `/api/v1/pages/${encodeURIComponent(id)}/share`),
|
||||
setShareLink: (id: string, includeSubpages: boolean) =>
|
||||
request<ShareLink>("PUT", `/api/v1/pages/${encodeURIComponent(id)}/share`, { includeSubpages }),
|
||||
deleteShareLink: (id: string) => request<void>("DELETE", `/api/v1/pages/${encodeURIComponent(id)}/share`),
|
||||
export: (id: string, format: "markdown" | "html") =>
|
||||
download(`/api/v1/pages/${encodeURIComponent(id)}/export${query({ format })}`),
|
||||
/** Records that the user opened the page, for their recent list. */
|
||||
|
||||
Vendored
+250
@@ -1207,6 +1207,89 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/pages/{id}/share": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/** The page's public link (404 when sharing is off) */
|
||||
get: operations["getShareLink"];
|
||||
/**
|
||||
* Turn the public link on, or change what it covers (editor)
|
||||
* @description An existing link keeps its URL.
|
||||
*/
|
||||
put: operations["setShareLink"];
|
||||
post?: never;
|
||||
/** Turn the public link off; its URL stops working (editor) */
|
||||
delete: operations["deleteShareLink"];
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/share/{token}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
token: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/** Read a shared page (no account needed) */
|
||||
get: operations["getSharedPage"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/share/{token}/pages/{pageId}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
token: string;
|
||||
pageId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/** Read a page under the shared page, when the link includes subpages */
|
||||
get: operations["getSharedSubpage"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/share/{token}/files/{fileId}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
token: string;
|
||||
fileId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/** Download an attachment of a page readable through the link */
|
||||
get: operations["downloadSharedFile"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
}
|
||||
export type webhooks = Record<string, never>;
|
||||
export interface components {
|
||||
@@ -1587,6 +1670,26 @@ export interface components {
|
||||
items: components["schemas"]["SearchHit"][];
|
||||
total: number;
|
||||
};
|
||||
ShareLink: {
|
||||
token: string;
|
||||
/** @description The link on docwell-web (DOCWELL_WEB_URL/share/<token>) */
|
||||
url: string;
|
||||
includeSubpages: boolean;
|
||||
created: string;
|
||||
};
|
||||
SharedPage: {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
updated: string;
|
||||
/** @description Tiptap JSON; files load from /api/v1/share/{token}/files/{fileId} */
|
||||
content: {
|
||||
[key: string]: unknown;
|
||||
} | null;
|
||||
root: components["schemas"]["PageRef"];
|
||||
/** @description Pages under the shared page */
|
||||
pages: components["schemas"]["PageNode"][];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description Signed in */
|
||||
@@ -3742,4 +3845,151 @@ export interface operations {
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
getShareLink: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ShareLink"];
|
||||
};
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
setShareLink: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
includeSubpages?: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ShareLink"];
|
||||
};
|
||||
};
|
||||
400: components["responses"]["Error"];
|
||||
403: components["responses"]["Error"];
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
deleteShareLink: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Off */
|
||||
204: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
403: components["responses"]["Error"];
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
getSharedPage: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
token: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["SharedPage"];
|
||||
};
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
getSharedSubpage: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
token: string;
|
||||
pageId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["SharedPage"];
|
||||
};
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
downloadSharedFile: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
token: string;
|
||||
fileId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description The file */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/octet-stream": string;
|
||||
};
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1730,3 +1730,87 @@ class SearchResult {
|
||||
'total': total,
|
||||
};
|
||||
}
|
||||
|
||||
class ShareLink {
|
||||
const ShareLink({
|
||||
required this.token,
|
||||
required this.url,
|
||||
required this.includeSubpages,
|
||||
required this.created,
|
||||
});
|
||||
|
||||
factory ShareLink.fromJson(Map<String, dynamic> json) => ShareLink(
|
||||
token: json['token'] as String,
|
||||
url: json['url'] as String,
|
||||
includeSubpages: json['includeSubpages'] as bool,
|
||||
created: json['created'] as String,
|
||||
);
|
||||
|
||||
final String token;
|
||||
|
||||
/// The link on docwell-web (DOCWELL_WEB_URL/share/<token>)
|
||||
final String url;
|
||||
|
||||
final bool includeSubpages;
|
||||
|
||||
final String created;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'token': token,
|
||||
'url': url,
|
||||
'includeSubpages': includeSubpages,
|
||||
'created': created,
|
||||
};
|
||||
}
|
||||
|
||||
class SharedPage {
|
||||
const SharedPage({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.icon,
|
||||
required this.updated,
|
||||
required this.content,
|
||||
required this.root,
|
||||
required this.pages,
|
||||
});
|
||||
|
||||
factory SharedPage.fromJson(Map<String, dynamic> json) => SharedPage(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
icon: json['icon'] as String,
|
||||
updated: json['updated'] as String,
|
||||
content: json['content'] == null
|
||||
? null
|
||||
: json['content'] as Map<String, dynamic>,
|
||||
root: PageRef.fromJson(json['root'] as Map<String, dynamic>),
|
||||
pages: (json['pages'] as List)
|
||||
.map((e) => PageNode.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
final String id;
|
||||
|
||||
final String title;
|
||||
|
||||
final String icon;
|
||||
|
||||
final String updated;
|
||||
|
||||
/// Tiptap JSON; files load from /api/v1/share/{token}/files/{fileId}
|
||||
final Map<String, dynamic>? content;
|
||||
|
||||
final PageRef root;
|
||||
|
||||
/// Pages under the shared page
|
||||
final List<PageNode> pages;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'icon': icon,
|
||||
'updated': updated,
|
||||
'content': content,
|
||||
'root': root.toJson(),
|
||||
'pages': pages.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
@@ -524,6 +524,30 @@ type Session struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
|
||||
// ShareLink defines model for ShareLink.
|
||||
type ShareLink struct {
|
||||
Created string `json:"created"`
|
||||
IncludeSubpages bool `json:"includeSubpages"`
|
||||
Token string `json:"token"`
|
||||
|
||||
// Url The link on docwell-web (DOCWELL_WEB_URL/share/<token>)
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// SharedPage defines model for SharedPage.
|
||||
type SharedPage struct {
|
||||
// Content Tiptap JSON; files load from /api/v1/share/{token}/files/{fileId}
|
||||
Content *map[string]interface{} `json:"content"`
|
||||
Icon string `json:"icon"`
|
||||
Id string `json:"id"`
|
||||
|
||||
// Pages Pages under the shared page
|
||||
Pages []PageNode `json:"pages"`
|
||||
Root PageRef `json:"root"`
|
||||
Title string `json:"title"`
|
||||
Updated string `json:"updated"`
|
||||
}
|
||||
|
||||
// SignupRequest defines model for SignupRequest.
|
||||
type SignupRequest struct {
|
||||
Email openapi_types.Email `json:"email"`
|
||||
@@ -793,6 +817,11 @@ type MovePageJSONBody struct {
|
||||
Parent *string `json:"parent,omitempty"`
|
||||
}
|
||||
|
||||
// SetShareLinkJSONBody defines parameters for SetShareLink.
|
||||
type SetShareLinkJSONBody struct {
|
||||
IncludeSubpages *bool `json:"includeSubpages,omitempty"`
|
||||
}
|
||||
|
||||
// UpdateSpaceJSONBody defines parameters for UpdateSpace.
|
||||
type UpdateSpaceJSONBody struct {
|
||||
// DefaultRole Role that workspace members (not guests) get in an open space without an explicit role.
|
||||
@@ -940,6 +969,9 @@ type SavePageContentJSONRequestBody SavePageContentJSONBody
|
||||
// MovePageJSONRequestBody defines body for MovePage for application/json ContentType.
|
||||
type MovePageJSONRequestBody MovePageJSONBody
|
||||
|
||||
// SetShareLinkJSONRequestBody defines body for SetShareLink for application/json ContentType.
|
||||
type SetShareLinkJSONRequestBody SetShareLinkJSONBody
|
||||
|
||||
// UpdateSpaceJSONRequestBody defines body for UpdateSpace for application/json ContentType.
|
||||
type UpdateSpaceJSONRequestBody UpdateSpaceJSONBody
|
||||
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package directory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/apperr"
|
||||
"docwell/server/internal/store/pocketbase"
|
||||
)
|
||||
|
||||
// ---- Public share links ----------------------------------------------------
|
||||
//
|
||||
// A share link lets anyone read a page without an account; with subpages, the
|
||||
// pages under it too. Editors turn it on and off. Reads through a link never
|
||||
// see trashed pages, and attachments are reachable only for shared pages.
|
||||
|
||||
// ShareLink is a page's public link, as editors see it.
|
||||
type ShareLink struct {
|
||||
Token string `json:"token"`
|
||||
URL string `json:"url"`
|
||||
IncludeSubpages bool `json:"includeSubpages"`
|
||||
Created string `json:"created"`
|
||||
}
|
||||
|
||||
type shareRecord struct {
|
||||
ID string `json:"id"`
|
||||
Page string `json:"page"`
|
||||
Workspace string `json:"workspace"`
|
||||
Token string `json:"token"`
|
||||
IncludeSubpages bool `json:"include_subpages"`
|
||||
Created string `json:"created"`
|
||||
}
|
||||
|
||||
func (s *Service) shareView(r shareRecord) ShareLink {
|
||||
return ShareLink{
|
||||
Token: r.Token, URL: strings.TrimRight(s.mailer.WebURL, "/") + "/share/" + r.Token,
|
||||
IncludeSubpages: r.IncludeSubpages, Created: r.Created,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) shareOf(ctx context.Context, pageID string) (shareRecord, error) {
|
||||
res, err := pocketbase.List[shareRecord](ctx, s.pb, "share_links", pocketbase.ListOptions{
|
||||
PerPage: 1, Filter: fmt.Sprintf("page = '%s'", pageID),
|
||||
})
|
||||
if err != nil || len(res.Items) == 0 {
|
||||
return shareRecord{}, err
|
||||
}
|
||||
return res.Items[0], nil
|
||||
}
|
||||
|
||||
// GetShareLink returns a page's link; ok is false when sharing is off (viewer).
|
||||
func (s *Service) GetShareLink(ctx context.Context, c access.Caller, pageID string) (ShareLink, bool, error) {
|
||||
p, _, err := s.pageFor(ctx, c, pageID)
|
||||
if err != nil {
|
||||
return ShareLink{}, false, err
|
||||
}
|
||||
rec, err := s.shareOf(ctx, p.ID)
|
||||
if err != nil || rec.ID == "" {
|
||||
return ShareLink{}, false, err
|
||||
}
|
||||
return s.shareView(rec), true, nil
|
||||
}
|
||||
|
||||
// SetShareLink turns a page's link on (keeping its token if it exists) and
|
||||
// sets whether it covers subpages (editor).
|
||||
func (s *Service) SetShareLink(ctx context.Context, c access.Caller, pageID string, includeSubpages bool) (ShareLink, error) {
|
||||
p, err := s.editablePage(ctx, c, pageID)
|
||||
if err != nil {
|
||||
return ShareLink{}, err
|
||||
}
|
||||
rec, err := s.shareOf(ctx, p.ID)
|
||||
if err != nil {
|
||||
return ShareLink{}, err
|
||||
}
|
||||
if rec.ID != "" {
|
||||
rec, err = pocketbase.Update[shareRecord](ctx, s.pb, "share_links", rec.ID, map[string]any{"include_subpages": includeSubpages})
|
||||
return s.shareView(rec), mapPB(err, "page not found")
|
||||
}
|
||||
b := make([]byte, 24)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return ShareLink{}, err
|
||||
}
|
||||
rec, err = pocketbase.Create[shareRecord](ctx, s.pb, "share_links", map[string]any{
|
||||
"page": p.ID, "workspace": p.Workspace, "token": base64.RawURLEncoding.EncodeToString(b),
|
||||
"include_subpages": includeSubpages, "created_by": c.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return ShareLink{}, mapPB(err, "page not found")
|
||||
}
|
||||
return s.shareView(rec), nil
|
||||
}
|
||||
|
||||
// DeleteShareLink turns a page's link off; the old URL stops working (editor).
|
||||
func (s *Service) DeleteShareLink(ctx context.Context, c access.Caller, pageID string) error {
|
||||
// Unlike other edits this works in the trash too: hiding a page there
|
||||
// should not need a restore first.
|
||||
p, a, err := s.pageFor(ctx, c, pageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := access.EditPages(a.role); err != nil {
|
||||
return err
|
||||
}
|
||||
rec, err := s.shareOf(ctx, p.ID)
|
||||
if err != nil || rec.ID == "" {
|
||||
return err
|
||||
}
|
||||
return mapPB(s.pb.Delete(ctx, "share_links", rec.ID), "page not found")
|
||||
}
|
||||
|
||||
// SharedPage is what a link's visitors see.
|
||||
type SharedPage struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Updated string `json:"updated"`
|
||||
Content json.RawMessage `json:"content"`
|
||||
// Root is the shared page; Pages lists the pages under it when the link
|
||||
// includes subpages (tree order, empty otherwise).
|
||||
Root PageRef `json:"root"`
|
||||
Pages []PageNode `json:"pages"`
|
||||
}
|
||||
|
||||
// sharedScope resolves a token and checks that pageID ("" = the shared page)
|
||||
// is readable through it. It returns the link and the page.
|
||||
func (s *Service) sharedScope(ctx context.Context, token, pageID string) (shareRecord, pageRecord, tree, error) {
|
||||
notFound := apperr.NotFound("this link does not exist or was turned off")
|
||||
token = strings.TrimSpace(token)
|
||||
if len(token) < 24 || len(token) > 64 || !validID(token) {
|
||||
return shareRecord{}, pageRecord{}, tree{}, notFound
|
||||
}
|
||||
res, err := pocketbase.List[shareRecord](ctx, s.pb, "share_links", pocketbase.ListOptions{
|
||||
PerPage: 1, Filter: fmt.Sprintf("token = '%s'", token),
|
||||
})
|
||||
if err != nil {
|
||||
return shareRecord{}, pageRecord{}, tree{}, err
|
||||
}
|
||||
if len(res.Items) == 0 {
|
||||
return shareRecord{}, pageRecord{}, tree{}, notFound
|
||||
}
|
||||
link := res.Items[0]
|
||||
root, err := s.getPage(ctx, link.Page)
|
||||
if err != nil {
|
||||
return link, pageRecord{}, tree{}, notFound
|
||||
}
|
||||
t, err := s.loadTree(ctx, root.Space)
|
||||
if err != nil {
|
||||
return link, pageRecord{}, tree{}, err
|
||||
}
|
||||
if !t.live(root.ID) {
|
||||
return link, pageRecord{}, tree{}, notFound
|
||||
}
|
||||
if pageID == "" || pageID == root.ID {
|
||||
return link, root, t, nil
|
||||
}
|
||||
p, ok := t.byID[pageID]
|
||||
if !ok || !link.IncludeSubpages || !t.live(p.ID) || !t.within(p.ID, root.ID) {
|
||||
return link, pageRecord{}, tree{}, apperr.NotFound("page not found")
|
||||
}
|
||||
return link, p, t, nil
|
||||
}
|
||||
|
||||
// GetSharedPage returns a page through a link: the shared page, or with
|
||||
// pageID one of the pages under it.
|
||||
func (s *Service) GetSharedPage(ctx context.Context, token, pageID string) (SharedPage, error) {
|
||||
link, p, t, err := s.sharedScope(ctx, token, pageID)
|
||||
if err != nil {
|
||||
return SharedPage{}, err
|
||||
}
|
||||
doc, err := s.docs.Content(ctx, p.ID)
|
||||
if err != nil {
|
||||
return SharedPage{}, err
|
||||
}
|
||||
root := t.byID[link.Page]
|
||||
out := SharedPage{
|
||||
ID: p.ID, Title: p.Title, Icon: p.Icon, Updated: p.Updated, Content: doc,
|
||||
Root: PageRef{ID: root.ID, Title: root.Title, Icon: root.Icon}, Pages: []PageNode{},
|
||||
}
|
||||
if link.IncludeSubpages {
|
||||
var walk func(parent string)
|
||||
walk = func(parent string) {
|
||||
for _, c := range t.children[parent] {
|
||||
out.Pages = append(out.Pages, c.node())
|
||||
walk(c.ID)
|
||||
}
|
||||
}
|
||||
walk(root.ID)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// OpenSharedFile opens an attachment of a page readable through a link.
|
||||
func (s *Service) OpenSharedFile(ctx context.Context, token, fileID string, header http.Header) (FileDownload, error) {
|
||||
rec, err := s.getAttachment(ctx, fileID)
|
||||
if err != nil {
|
||||
return FileDownload{}, err
|
||||
}
|
||||
if _, _, _, err := s.sharedScope(ctx, token, rec.Page); err != nil {
|
||||
return FileDownload{}, apperr.NotFound("file not found")
|
||||
}
|
||||
return s.openFile(ctx, rec, header)
|
||||
}
|
||||
@@ -150,6 +150,7 @@ func (a *api) routes(mux *routeMux) {
|
||||
a.favoriteRoutes(mux)
|
||||
a.searchRoutes(mux)
|
||||
a.transferRoutes(mux)
|
||||
a.shareRoutes(mux)
|
||||
}
|
||||
|
||||
func (a *api) decode(w http.ResponseWriter, r *http.Request, v any) bool {
|
||||
|
||||
@@ -39,6 +39,7 @@ type DirectoryService interface {
|
||||
AttachmentService
|
||||
SearchService
|
||||
TransferService
|
||||
ShareService
|
||||
}
|
||||
|
||||
func caller(r *http.Request) access.Caller {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/directory"
|
||||
)
|
||||
|
||||
// ShareService is the part of directory.Service for public share links.
|
||||
type ShareService interface {
|
||||
GetShareLink(ctx context.Context, c access.Caller, pageID string) (directory.ShareLink, bool, error)
|
||||
SetShareLink(ctx context.Context, c access.Caller, pageID string, includeSubpages bool) (directory.ShareLink, error)
|
||||
DeleteShareLink(ctx context.Context, c access.Caller, pageID string) error
|
||||
GetSharedPage(ctx context.Context, token, pageID string) (directory.SharedPage, error)
|
||||
OpenSharedFile(ctx context.Context, token, fileID string, header http.Header) (directory.FileDownload, error)
|
||||
}
|
||||
|
||||
func (a *api) shareRoutes(mux *routeMux) {
|
||||
mux.HandleFunc("GET /api/v1/pages/{id}/share", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
link, ok, err := a.dir.GetShareLink(r.Context(), caller(r), r.PathValue("id"))
|
||||
if err == nil && !ok {
|
||||
writeJSON(w, http.StatusNotFound, map[string]string{"error": "not_found", "message": "sharing is off"})
|
||||
return
|
||||
}
|
||||
a.respond(w, link, err)
|
||||
}))
|
||||
mux.HandleFunc("PUT /api/v1/pages/{id}/share", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct{ IncludeSubpages bool }
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
link, err := a.dir.SetShareLink(r.Context(), caller(r), r.PathValue("id"), in.IncludeSubpages)
|
||||
a.respond(w, link, err)
|
||||
}))
|
||||
mux.HandleFunc("DELETE /api/v1/pages/{id}/share", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.dir.DeleteShareLink(r.Context(), caller(r), r.PathValue("id")))
|
||||
}))
|
||||
|
||||
// Public reads through a link: no account needed, never indexed.
|
||||
mux.HandleFunc("GET /api/v1/share/{token}", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-Robots-Tag", "noindex")
|
||||
p, err := a.dir.GetSharedPage(r.Context(), r.PathValue("token"), "")
|
||||
a.respond(w, p, err)
|
||||
})
|
||||
mux.HandleFunc("GET /api/v1/share/{token}/pages/{pageId}", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-Robots-Tag", "noindex")
|
||||
p, err := a.dir.GetSharedPage(r.Context(), r.PathValue("token"), r.PathValue("pageId"))
|
||||
a.respond(w, p, err)
|
||||
})
|
||||
mux.HandleFunc("GET /api/v1/share/{token}/files/{fileId}", func(w http.ResponseWriter, r *http.Request) {
|
||||
f, err := a.dir.OpenSharedFile(r.Context(), r.PathValue("token"), r.PathValue("fileId"), r.Header)
|
||||
if err != nil {
|
||||
a.writeError(w, err)
|
||||
return
|
||||
}
|
||||
w.Header().Set("X-Robots-Tag", "noindex")
|
||||
serveFile(w, f)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ApiError,
|
||||
type Page,
|
||||
type ShareLink,
|
||||
type Space,
|
||||
type SpaceGroup,
|
||||
type SpaceMember,
|
||||
} from "@docwell/api-client";
|
||||
import { DwButton, DwCallout, DwIcon } from "@docwell/ui";
|
||||
import { computed, nextTick, ref, watch } from "vue";
|
||||
import { useApi } from "../api";
|
||||
import { useFormErrors } from "../composables/useFormErrors";
|
||||
import { spaceAtLeast } from "../stores/spaces";
|
||||
|
||||
// Who can open a page, and its public link. Access comes from the space;
|
||||
// changing it is done in the space settings.
|
||||
const open = defineModel<boolean>({ default: false });
|
||||
const props = defineProps<{ page: Page }>();
|
||||
const api = useApi();
|
||||
const errors = useFormErrors();
|
||||
|
||||
const space = ref<Space | null>(null);
|
||||
const members = ref<SpaceMember[]>([]);
|
||||
const groups = ref<SpaceGroup[]>([]);
|
||||
const link = ref<ShareLink | null>(null);
|
||||
const busy = ref(false);
|
||||
const copied = ref("");
|
||||
const dialog = ref<HTMLElement | null>(null);
|
||||
|
||||
const canEdit = computed(() => spaceAtLeast(props.page.role, "editor") && !props.page.inTrash);
|
||||
const pageUrl = computed(() => `${location.origin}/p/${props.page.id}`);
|
||||
|
||||
watch(open, async (v) => {
|
||||
if (!v) return;
|
||||
errors.reset();
|
||||
copied.value = "";
|
||||
await nextTick();
|
||||
dialog.value?.focus();
|
||||
try {
|
||||
const [s, m, g] = await Promise.all([
|
||||
api.spaces.get(props.page.space),
|
||||
api.spaces.members(props.page.space),
|
||||
api.spaces.groups(props.page.space),
|
||||
]);
|
||||
space.value = s;
|
||||
members.value = m;
|
||||
groups.value = g;
|
||||
link.value = await api.pages.shareLink(props.page.id).catch((e) => {
|
||||
if (e instanceof ApiError && e.status === 404) return null;
|
||||
throw e;
|
||||
});
|
||||
} catch (e) {
|
||||
errors.show(e);
|
||||
}
|
||||
});
|
||||
|
||||
async function run(action: () => Promise<void>) {
|
||||
busy.value = true;
|
||||
errors.reset();
|
||||
try {
|
||||
await action();
|
||||
} catch (e) {
|
||||
errors.show(e);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const setPublic = (on: boolean) =>
|
||||
run(async () => {
|
||||
if (on) link.value = await api.pages.setShareLink(props.page.id, link.value?.includeSubpages ?? false);
|
||||
else {
|
||||
await api.pages.deleteShareLink(props.page.id);
|
||||
link.value = null;
|
||||
}
|
||||
});
|
||||
const setSubpages = (on: boolean) =>
|
||||
run(async () => {
|
||||
link.value = await api.pages.setShareLink(props.page.id, on);
|
||||
});
|
||||
|
||||
async function copy(which: "page" | "public", text: string) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
copied.value = which;
|
||||
setTimeout(() => (copied.value = ""), 2000);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex items-start justify-center bg-black/40 px-4 pt-[10vh]"
|
||||
@mousedown.self="open = false"
|
||||
@keydown.esc="open = false"
|
||||
>
|
||||
<div
|
||||
ref="dialog"
|
||||
tabindex="-1"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="share-title"
|
||||
class="w-full max-w-lg rounded-md border border-line bg-surface-raised p-5 shadow-dialog outline-none"
|
||||
data-testid="share-dialog"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<h2 id="share-title" class="text-ui-lg">{{ $t("share.title") }}</h2>
|
||||
<DwButton
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="close"
|
||||
:aria-label="$t('page.history.close')"
|
||||
@click="open = false"
|
||||
/>
|
||||
</div>
|
||||
<DwCallout v-if="errors.message.value" tone="danger" size="ui" class="mt-3">{{
|
||||
errors.message.value
|
||||
}}</DwCallout>
|
||||
|
||||
<section class="mt-4">
|
||||
<h3 class="dw-label">{{ $t("share.access") }}</h3>
|
||||
<p class="mt-2 flex items-start gap-2 text-ui-md">
|
||||
<DwIcon
|
||||
:name="space?.visibility === 'private' ? 'lock' : 'users'"
|
||||
:size="18"
|
||||
class="mt-0.5 text-ink-muted"
|
||||
/>
|
||||
<span v-if="space">
|
||||
{{
|
||||
space.visibility === "private"
|
||||
? $t("share.privateSpace", { space: space.name })
|
||||
: $t("share.openSpace", { space: space.name, role: $t(`space.roles.${space.defaultRole}`) })
|
||||
}}
|
||||
</span>
|
||||
</p>
|
||||
<ul v-if="members.length || groups.length" class="mt-2 space-y-1 text-ui-sm text-ink-muted">
|
||||
<li v-for="g in groups" :key="g.group.id">{{ g.group.name }} · {{ $t(`space.roles.${g.role}`) }}</li>
|
||||
<li v-for="m in members" :key="m.user.id">
|
||||
{{ m.user.name }} ({{ m.user.email }}) · {{ $t(`space.roles.${m.role}`) }}
|
||||
</li>
|
||||
</ul>
|
||||
<div class="mt-3 flex flex-wrap items-center gap-2">
|
||||
<RouterLink
|
||||
v-if="space && spaceAtLeast(space.role, 'admin')"
|
||||
:to="{ name: 'space-settings', params: { id: space.id } }"
|
||||
class="dw-link text-ui-md"
|
||||
@click="open = false"
|
||||
>{{ $t("share.manageAccess") }}</RouterLink
|
||||
>
|
||||
<button class="dw-link text-ui-md" @click="copy('page', pageUrl)">
|
||||
{{ copied === "page" ? $t("workspace.copied") : $t("share.copyPageLink") }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="mt-6 border-t border-line pt-4">
|
||||
<h3 class="dw-label">{{ $t("share.public") }}</h3>
|
||||
<label class="mt-2 flex items-start gap-3 text-ui-md">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mt-1 accent-primary"
|
||||
:checked="!!link"
|
||||
:disabled="busy || !canEdit"
|
||||
data-testid="share-public"
|
||||
@change="setPublic(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
<span>
|
||||
<span class="font-medium">{{ $t("share.publicToggle") }}</span>
|
||||
<span class="block text-ui-sm text-ink-muted">{{ $t("share.publicHint") }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<template v-if="link">
|
||||
<label class="mt-3 flex items-center gap-3 text-ui-md">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="accent-primary"
|
||||
:checked="link.includeSubpages"
|
||||
:disabled="busy || !canEdit"
|
||||
@change="setSubpages(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
{{ $t("share.subpages") }}
|
||||
</label>
|
||||
<div class="mt-3 flex gap-2">
|
||||
<input
|
||||
:value="link.url"
|
||||
readonly
|
||||
class="dw-input min-w-0 flex-1 font-mono text-ui-sm"
|
||||
:aria-label="$t('share.public')"
|
||||
@focus="($event.target as HTMLInputElement).select()"
|
||||
/>
|
||||
<DwButton icon="link" @click="copy('public', link.url)">
|
||||
{{ copied === "public" ? $t("workspace.copied") : $t("workspace.copyLink") }}
|
||||
</DwButton>
|
||||
</div>
|
||||
</template>
|
||||
<p v-if="!canEdit" class="mt-2 text-ui-sm text-ink-muted">{{ $t("share.editorsOnly") }}</p>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
@@ -278,5 +278,21 @@
|
||||
"search": {
|
||||
"placeholder": "Search pages…",
|
||||
"none": "Nothing found for \"{q}\"."
|
||||
},
|
||||
"share": {
|
||||
"button": "Share",
|
||||
"title": "Share this page",
|
||||
"access": "Who can open it",
|
||||
"privateSpace": "Only the people and groups added to {space}, plus workspace admins.",
|
||||
"openSpace": "Everyone in the workspace, as {role} in {space}, plus the people and groups below.",
|
||||
"manageAccess": "Change access in the space settings",
|
||||
"copyPageLink": "Copy page link",
|
||||
"public": "Public link",
|
||||
"publicToggle": "Anyone with the link can read",
|
||||
"publicHint": "No account needed. Turning it off makes the link stop working.",
|
||||
"subpages": "Include the pages inside it",
|
||||
"editorsOnly": "Editors of this space can turn the public link on or off.",
|
||||
"readOnly": "Shared page · read only",
|
||||
"gone": "This link does not work any more. Ask the person who shared it for a new one."
|
||||
}
|
||||
}
|
||||
@@ -278,5 +278,21 @@
|
||||
"search": {
|
||||
"placeholder": "Szukaj stron…",
|
||||
"none": "Nic nie znaleziono dla „{q}”."
|
||||
},
|
||||
"share": {
|
||||
"button": "Udostępnij",
|
||||
"title": "Udostępnij tę stronę",
|
||||
"access": "Kto może ją otworzyć",
|
||||
"privateSpace": "Tylko osoby i grupy dodane do {space} oraz administratorzy obszaru roboczego.",
|
||||
"openSpace": "Każdy w obszarze roboczym, z rolą {role} w {space}, oraz osoby i grupy poniżej.",
|
||||
"manageAccess": "Zmień dostęp w ustawieniach przestrzeni",
|
||||
"copyPageLink": "Kopiuj link do strony",
|
||||
"public": "Link publiczny",
|
||||
"publicToggle": "Każdy z linkiem może czytać",
|
||||
"publicHint": "Konto nie jest potrzebne. Wyłączenie sprawia, że link przestaje działać.",
|
||||
"subpages": "Uwzględnij strony wewnątrz",
|
||||
"editorsOnly": "Edytorzy tej przestrzeni mogą włączać i wyłączać link publiczny.",
|
||||
"readOnly": "Udostępniona strona · tylko do odczytu",
|
||||
"gone": "Ten link już nie działa. Poproś osobę, która go udostępniła, o nowy."
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,21 @@ export function createDocwellRouter(platform: Platform) {
|
||||
component: () => import("./views/auth/VerifyEmailView.vue"),
|
||||
meta: { public: true },
|
||||
},
|
||||
// Pages shared by public link; readable without an account.
|
||||
{
|
||||
path: "/share/:token",
|
||||
name: "share",
|
||||
component: () => import("./views/ShareView.vue"),
|
||||
props: true,
|
||||
meta: { public: true },
|
||||
},
|
||||
{
|
||||
path: "/share/:token/p/:page",
|
||||
name: "share-page",
|
||||
component: () => import("./views/ShareView.vue"),
|
||||
props: true,
|
||||
meta: { public: true },
|
||||
},
|
||||
// Linked from invite and sign-in emails sent by docwell-server and PocketBase.
|
||||
{
|
||||
path: "/invite",
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
||||
<script setup lang="ts">
|
||||
import type { SharedPage } from "@docwell/api-client";
|
||||
import { DocwellEditor, type FileHost } from "@docwell/editor";
|
||||
import { DwCallout, DwIcon, DwLogo } from "@docwell/ui";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { useApi } from "../api";
|
||||
import { useRuntimeConfig } from "../platform";
|
||||
|
||||
// A page shared by public link: read-only, no account needed. With subpages,
|
||||
// a small tree on the side moves between them.
|
||||
const props = defineProps<{ token: string; page?: string }>();
|
||||
const api = useApi();
|
||||
const config = useRuntimeConfig();
|
||||
|
||||
const shared = ref<SharedPage | null>(null);
|
||||
const failed = ref(false);
|
||||
|
||||
const files: FileHost = {
|
||||
resolve(src) {
|
||||
const m = /^\/api\/v1\/files\/([A-Za-z0-9_-]+)$/.exec(src);
|
||||
return m ? `${config.apiUrl}/api/v1/share/${encodeURIComponent(props.token)}/files/${m[1]}` : src;
|
||||
},
|
||||
};
|
||||
|
||||
async function load() {
|
||||
failed.value = false;
|
||||
try {
|
||||
shared.value = await api.share.get(props.token, props.page);
|
||||
document.title = shared.value.title || "Docwell";
|
||||
} catch {
|
||||
shared.value = null;
|
||||
failed.value = true;
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
// Shared pages are for the people who got the link, not for search engines.
|
||||
const meta = document.createElement("meta");
|
||||
meta.name = "robots";
|
||||
meta.content = "noindex";
|
||||
document.head.append(meta);
|
||||
});
|
||||
watch(() => [props.token, props.page], load, { immediate: true });
|
||||
|
||||
// Depth of each subpage, for indenting the tree.
|
||||
const tree = computed(() => {
|
||||
const s = shared.value;
|
||||
if (!s) return [];
|
||||
const depth = new Map<string, number>([[s.root.id, 0]]);
|
||||
return s.pages.map((p) => {
|
||||
const d = (depth.get(p.parent) ?? 0) + 1;
|
||||
depth.set(p.id, d);
|
||||
return { ...p, depth: d };
|
||||
});
|
||||
});
|
||||
const link = (id: string) =>
|
||||
id === shared.value?.root.id
|
||||
? { name: "share", params: { token: props.token } }
|
||||
: { name: "share-page", params: { token: props.token, page: id } };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-dvh bg-surface">
|
||||
<header class="flex h-12 items-center gap-3 border-b border-line px-4">
|
||||
<DwLogo class="h-6" />
|
||||
<span class="truncate text-ui-sm text-ink-muted">{{ $t("share.readOnly") }}</span>
|
||||
</header>
|
||||
|
||||
<div class="mx-auto flex max-w-doc-wide gap-8 px-4 sm:px-8">
|
||||
<nav v-if="tree.length" class="hidden w-56 shrink-0 pt-10 md:block" :aria-label="$t('page.subpages')">
|
||||
<RouterLink
|
||||
:to="link(shared!.root.id)"
|
||||
class="flex items-center gap-2 rounded-sm px-2 py-1 text-ui-md font-medium hover:bg-surface-hover"
|
||||
:class="{ 'bg-surface-hover': shared!.id === shared!.root.id }"
|
||||
>
|
||||
<span class="truncate">{{ shared!.root.title || $t("home.untitled") }}</span>
|
||||
</RouterLink>
|
||||
<RouterLink
|
||||
v-for="p in tree"
|
||||
:key="p.id"
|
||||
:to="link(p.id)"
|
||||
class="flex items-center gap-2 rounded-sm py-1 pr-2 text-ui-md text-ink-muted hover:bg-surface-hover hover:text-ink"
|
||||
:class="{ 'bg-surface-hover text-ink': shared!.id === p.id }"
|
||||
:style="{ paddingLeft: `${8 + p.depth * 12}px` }"
|
||||
>
|
||||
<DwIcon name="page" :size="14" class="shrink-0" />
|
||||
<span class="truncate">{{ p.title || $t("home.untitled") }}</span>
|
||||
</RouterLink>
|
||||
</nav>
|
||||
|
||||
<article class="min-w-0 flex-1 pt-6 pb-16 sm:pt-10">
|
||||
<DwCallout v-if="failed" tone="info" size="ui">{{ $t("share.gone") }}</DwCallout>
|
||||
<template v-if="shared">
|
||||
<h1 class="font-serif text-doc-title text-ink">
|
||||
{{ shared.icon ? `${shared.icon} ` : "" }}{{ shared.title || $t("home.untitled") }}
|
||||
</h1>
|
||||
<DocwellEditor
|
||||
:key="shared.id"
|
||||
:content="shared.content ?? undefined"
|
||||
:editable="false"
|
||||
:files="files"
|
||||
placeholder=""
|
||||
class="mt-4"
|
||||
data-testid="shared-content"
|
||||
/>
|
||||
</template>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -9,6 +9,7 @@ import { useRouter } from "vue-router";
|
||||
import { useApi, useToken } from "../../api";
|
||||
import PageHistory from "../../components/PageHistory.vue";
|
||||
import PageList from "../../components/PageList.vue";
|
||||
import ShareDialog from "../../components/ShareDialog.vue";
|
||||
import { useFileHost } from "../../composables/useFiles";
|
||||
import { saveBlob } from "../../lib/download";
|
||||
import { useRuntimeConfig } from "../../platform";
|
||||
@@ -34,6 +35,7 @@ const notFound = ref(false);
|
||||
const title = ref("");
|
||||
const busy = ref(false);
|
||||
const historyOpen = ref(false);
|
||||
const shareOpen = ref(false);
|
||||
|
||||
// Attachments: images and files load through a short-lived file token.
|
||||
const files = useFileHost(() => page.value?.id ?? props.id);
|
||||
@@ -284,8 +286,12 @@ const purge = () =>
|
||||
>
|
||||
{{ $t("page.history.title") }}
|
||||
</DwButton>
|
||||
<DwButton variant="ghost" size="sm" icon="share" data-testid="share-open" @click="shareOpen = true">
|
||||
{{ $t("share.button") }}
|
||||
</DwButton>
|
||||
<DwMenu :items="menu" :label="$t('page.more')" data-testid="page-menu" />
|
||||
</Teleport>
|
||||
<ShareDialog v-if="page" v-model="shareOpen" :page="page" />
|
||||
|
||||
<article class="mx-auto max-w-doc px-4 pt-6 pb-16 sm:px-16 sm:pt-10">
|
||||
<DwCallout v-if="notFound" tone="info" size="ui">{{ $t("page.notFound") }}</DwCallout>
|
||||
|
||||
@@ -1443,6 +1443,98 @@ paths:
|
||||
"400": { $ref: "#/components/responses/Error" }
|
||||
"403": { $ref: "#/components/responses/Error" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
# Public share links: read access for anyone with the link.
|
||||
/api/v1/pages/{id}/share:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: getShareLink
|
||||
tags: [sharing]
|
||||
summary: The page's public link (404 when sharing is off)
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/ShareLink" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
put:
|
||||
operationId: setShareLink
|
||||
tags: [sharing]
|
||||
summary: Turn the public link on, or change what it covers (editor)
|
||||
description: An existing link keeps its URL.
|
||||
security: [{ bearer: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
includeSubpages: { type: boolean }
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/ShareLink" }
|
||||
"400": { $ref: "#/components/responses/Error" }
|
||||
"403": { $ref: "#/components/responses/Error" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
delete:
|
||||
operationId: deleteShareLink
|
||||
tags: [sharing]
|
||||
summary: Turn the public link off; its URL stops working (editor)
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"204": { description: Off }
|
||||
"403": { $ref: "#/components/responses/Error" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/share/{token}:
|
||||
parameters:
|
||||
- { name: token, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: getSharedPage
|
||||
tags: [sharing]
|
||||
summary: Read a shared page (no account needed)
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/SharedPage" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/share/{token}/pages/{pageId}:
|
||||
parameters:
|
||||
- { name: token, in: path, required: true, schema: { type: string } }
|
||||
- { name: pageId, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: getSharedSubpage
|
||||
tags: [sharing]
|
||||
summary: Read a page under the shared page, when the link includes subpages
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/SharedPage" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/share/{token}/files/{fileId}:
|
||||
parameters:
|
||||
- { name: token, in: path, required: true, schema: { type: string } }
|
||||
- { name: fileId, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: downloadSharedFile
|
||||
tags: [sharing]
|
||||
summary: Download an attachment of a page readable through the link
|
||||
responses:
|
||||
"200":
|
||||
description: The file
|
||||
content:
|
||||
application/octet-stream:
|
||||
schema: { type: string, format: binary }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
components:
|
||||
securitySchemes:
|
||||
bearer:
|
||||
@@ -1885,3 +1977,24 @@ components:
|
||||
properties:
|
||||
items: { type: array, items: { $ref: "#/components/schemas/SearchHit" } }
|
||||
total: { type: integer }
|
||||
ShareLink:
|
||||
type: object
|
||||
required: [token, url, includeSubpages, created]
|
||||
properties:
|
||||
token: { type: string }
|
||||
url: { type: string, description: The link on docwell-web (DOCWELL_WEB_URL/share/<token>) }
|
||||
includeSubpages: { type: boolean }
|
||||
created: { type: string }
|
||||
SharedPage:
|
||||
type: object
|
||||
required: [id, title, icon, updated, content, root, pages]
|
||||
properties:
|
||||
id: { type: string }
|
||||
title: { type: string }
|
||||
icon: { type: string }
|
||||
updated: { type: string }
|
||||
content:
|
||||
oneOf: [{ type: object, additionalProperties: true }, { type: "null" }]
|
||||
description: Tiptap JSON; files load from /api/v1/share/{token}/files/{fileId}
|
||||
root: { $ref: "#/components/schemas/PageRef" }
|
||||
pages: { type: array, items: { $ref: "#/components/schemas/PageNode" }, description: Pages under the shared page, in tree order (only when the link includes subpages) }
|
||||
Reference in new issue
Block a user