mirror of
https://github.com/narrrl/narl-workspace.git
synced 2026-11-03 16:41:27 +01:00
feat: spaces, folder import, boards and mail; rename to narl-workspace
The diary grows into a workspace: a flat list of dated entries becomes a tree of spaces, and the app is renamed to match what it now is. Spaces and nodes One recursive `nodes` table replaces `entries`: a space is a root node, and folders and documents nest under it without limit. Entries keep their ids through the migration, so share tokens, media links and the drafts in localStorage all still resolve. Folder import A folder or a zip is uploaded as a document tree. Markdown becomes documents titled from their first heading, everything else becomes media, and relative links between the imported files are rewritten to the paths they landed at, so a set of cross-linked notes stays navigable after the upload. Boards A kanban board per space, with the space as the board: lists, cards, due dates and an optional link to a document. `diary` has none. Mail SMTP notifications through an outbox. A mail is enqueued under a key naming the occurrence it belongs to, so a restart cannot resend and a relay that refuses is retried with a widening backoff. Four kinds: the diary reminder, cards due and overdue, a weekly digest, and logins from a browser that has not been seen before or a burst of failures. All of it is dormant until WORKSPACE_SMTP_URL is set. Rename Everything user-visible says workspace; everything that already exists outside this repo keeps its name, because renaming it would break a running deployment for tidiness alone: the database file, the docker volume, the session cookie, the Proton device, the keyring entry and the localStorage keys. Configuration reads WORKSPACE_* first and falls back to DIARY_*, so the deployed .env keeps working untouched.
This commit is contained in:
1 parent
76f0887ac5
commit
49b2056215
50 files changed
+5487
-972
No files matched your search
+146
-25
@@ -1,32 +1,81 @@
|
||||
export interface EntrySummary {
|
||||
/** What a node is: a top-level space, a folder inside one, or a document. */
|
||||
export type NodeKind = 'space' | 'folder' | 'document'
|
||||
|
||||
export interface NodeSummary {
|
||||
id: number
|
||||
title: string
|
||||
parent_id: number | null
|
||||
kind: NodeKind
|
||||
name: string
|
||||
slug: string
|
||||
excerpt: string
|
||||
position: number
|
||||
has_board: boolean
|
||||
child_count: number
|
||||
created_at: number
|
||||
updated_at: number
|
||||
shared: boolean
|
||||
share_token: string | null
|
||||
}
|
||||
|
||||
export interface Entry {
|
||||
/** One step of a node's path, the space first and the node itself last. */
|
||||
export interface Crumb {
|
||||
id: number
|
||||
title: string
|
||||
kind: NodeKind
|
||||
name: string
|
||||
slug: string
|
||||
}
|
||||
|
||||
export interface WorkspaceNode extends NodeSummary {
|
||||
body: string
|
||||
excerpt: string
|
||||
created_at: number
|
||||
updated_at: number
|
||||
shared: boolean
|
||||
share_token: string | null
|
||||
path: Crumb[]
|
||||
}
|
||||
|
||||
export interface SharedEntry {
|
||||
title: string
|
||||
export interface SharedDocument {
|
||||
name: string
|
||||
body: string
|
||||
created_at: number
|
||||
updated_at: number
|
||||
token: string
|
||||
}
|
||||
|
||||
/** What an import did, as `POST /api/nodes/{id}/import` reports it. */
|
||||
export interface ImportReport {
|
||||
folders: number
|
||||
documents: number
|
||||
files: number
|
||||
links: number
|
||||
skipped: string[]
|
||||
}
|
||||
|
||||
/** A card on a space's board. `node_id` is the document it is about, if any. */
|
||||
export interface Card {
|
||||
id: number
|
||||
list_id: number
|
||||
title: string
|
||||
body: string
|
||||
node_id: number | null
|
||||
node_name: string | null
|
||||
due_at: number | null
|
||||
done_at: number | null
|
||||
position: number
|
||||
created_at: number
|
||||
updated_at: number
|
||||
}
|
||||
|
||||
export interface BoardList {
|
||||
id: number
|
||||
name: string
|
||||
position: number
|
||||
cards: Card[]
|
||||
}
|
||||
|
||||
/** One space's board. There is one per space; the diary has none. */
|
||||
export interface Board {
|
||||
space_id: number
|
||||
space_name: string
|
||||
lists: BoardList[]
|
||||
}
|
||||
|
||||
export interface MediaFile {
|
||||
id: string
|
||||
filename: string
|
||||
@@ -34,8 +83,8 @@ export interface MediaFile {
|
||||
size: number
|
||||
created_at: number
|
||||
url: string
|
||||
/** Every entry that embeds this file — a file may be used by several. */
|
||||
entry_ids: number[]
|
||||
/** Every document that embeds this file — a file may be used by several. */
|
||||
node_ids: number[]
|
||||
}
|
||||
|
||||
/** The Proton Drive mirror, as `/api/backup` reports it. */
|
||||
@@ -92,24 +141,96 @@ export const api = {
|
||||
|
||||
logout: () => request<{ ok: true }>('/logout', { method: 'POST' }),
|
||||
|
||||
listEntries: (q = '') =>
|
||||
request<EntrySummary[]>(`/entries${q ? `?q=${encodeURIComponent(q)}` : ''}`),
|
||||
listSpaces: () => request<NodeSummary[]>('/spaces'),
|
||||
|
||||
getEntry: (id: number) => request<Entry>(`/entries/${id}`),
|
||||
createSpace: (name: string, has_board = true) =>
|
||||
request<WorkspaceNode>('/spaces', { method: 'POST', body: body({ name, has_board }) }),
|
||||
|
||||
createEntry: (input: { title: string; body: string; created_at?: number }) =>
|
||||
request<Entry>('/entries', { method: 'POST', body: body(input) }),
|
||||
/** The children of a node, or — with `q` — a search across the whole tree. */
|
||||
listNodes: (params: { parent?: number; q?: string; space?: number }) => {
|
||||
const query = new URLSearchParams()
|
||||
if (params.q) query.set('q', params.q)
|
||||
else if (params.parent !== undefined) query.set('parent', String(params.parent))
|
||||
if (params.q && params.space !== undefined) query.set('space', String(params.space))
|
||||
return request<NodeSummary[]>(`/nodes?${query}`)
|
||||
},
|
||||
|
||||
updateEntry: (id: number, input: { title: string; body: string; created_at?: number }) =>
|
||||
request<Entry>(`/entries/${id}`, { method: 'PUT', body: body(input) }),
|
||||
getNode: (id: number) => request<WorkspaceNode>(`/nodes/${id}`),
|
||||
|
||||
deleteEntry: (id: number) => request<{ ok: true }>(`/entries/${id}`, { method: 'DELETE' }),
|
||||
/** `work/einarbeiten/01-was-ist-eebus` — the node behind a `/n/...` address. */
|
||||
resolvePath: (path: string) => request<WorkspaceNode>(`/resolve?path=${encodeURIComponent(path)}`),
|
||||
|
||||
/** Publishes the entry, or mints a fresh key for one already published. */
|
||||
/**
|
||||
* Upload a folder into a node. The relative path is passed as each part's
|
||||
* file name, which is the only place a multipart body has to put it, and is
|
||||
* what the server rebuilds the directory tree from.
|
||||
*/
|
||||
importFolder: (id: number, files: File[]) => {
|
||||
const form = new FormData()
|
||||
for (const file of files) form.append('file', file, file.webkitRelativePath || file.name)
|
||||
return request<ImportReport>(`/nodes/${id}/import`, { method: 'POST', body: form })
|
||||
},
|
||||
|
||||
createNode: (input: {
|
||||
parent_id: number
|
||||
kind?: NodeKind
|
||||
name?: string
|
||||
body?: string
|
||||
created_at?: number
|
||||
}) => request<WorkspaceNode>('/nodes', { method: 'POST', body: body(input) }),
|
||||
|
||||
updateNode: (
|
||||
id: number,
|
||||
input: { name: string; body: string; created_at?: number; has_board?: boolean },
|
||||
) => request<WorkspaceNode>(`/nodes/${id}`, { method: 'PUT', body: body(input) }),
|
||||
|
||||
deleteNode: (id: number) =>
|
||||
request<{ ok: true; removed: number }>(`/nodes/${id}`, { method: 'DELETE' }),
|
||||
|
||||
moveNode: (id: number, parent_id: number, position?: number) =>
|
||||
request<WorkspaceNode>(`/nodes/${id}/move`, { method: 'POST', body: body({ parent_id, position }) }),
|
||||
|
||||
/** Publishes the document, or mints a fresh key for one already published. */
|
||||
share: (id: number) =>
|
||||
request<{ token: string; key: string; path: string }>(`/entries/${id}/share`, { method: 'POST' }),
|
||||
request<{ token: string; key: string; path: string }>(`/nodes/${id}/share`, { method: 'POST' }),
|
||||
|
||||
unshare: (id: number) => request<{ ok: true }>(`/entries/${id}/share`, { method: 'DELETE' }),
|
||||
unshare: (id: number) => request<{ ok: true }>(`/nodes/${id}/share`, { method: 'DELETE' }),
|
||||
|
||||
/** The board of a space. Fails for a space that has none, such as the diary. */
|
||||
board: (spaceId: number) => request<Board>(`/spaces/${spaceId}/board`),
|
||||
|
||||
createList: (spaceId: number, name: string) =>
|
||||
request<Board>(`/spaces/${spaceId}/lists`, { method: 'POST', body: body({ name }) }),
|
||||
|
||||
renameList: (listId: number, name: string) =>
|
||||
request<Board>(`/lists/${listId}`, { method: 'PUT', body: body({ name }) }),
|
||||
|
||||
deleteList: (listId: number) => request<Board>(`/lists/${listId}`, { method: 'DELETE' }),
|
||||
|
||||
createCard: (
|
||||
listId: number,
|
||||
input: { title: string; body?: string; node_id?: number | null; due_at?: number | null },
|
||||
) => request<Card>(`/lists/${listId}/cards`, { method: 'POST', body: body(input) }),
|
||||
|
||||
/*
|
||||
* Only what changed is sent. `due_at: null` clears the date while leaving it
|
||||
* out keeps it, which is why the server reads those fields as double options.
|
||||
*/
|
||||
updateCard: (
|
||||
id: number,
|
||||
patch: {
|
||||
title?: string
|
||||
body?: string
|
||||
node_id?: number | null
|
||||
due_at?: number | null
|
||||
done?: boolean
|
||||
},
|
||||
) => request<Card>(`/cards/${id}`, { method: 'PUT', body: body(patch) }),
|
||||
|
||||
deleteCard: (id: number) => request<{ ok: true }>(`/cards/${id}`, { method: 'DELETE' }),
|
||||
|
||||
moveCard: (id: number, list_id: number, position?: number) =>
|
||||
request<Card>(`/cards/${id}/move`, { method: 'POST', body: body({ list_id, position }) }),
|
||||
|
||||
listMedia: () => request<MediaFile[]>('/media'),
|
||||
|
||||
@@ -126,5 +247,5 @@ export const api = {
|
||||
backupNow: () => request<BackupStatus>('/backup', { method: 'POST' }),
|
||||
|
||||
readShared: (token: string, key: string) =>
|
||||
request<SharedEntry>(`/share/${encodeURIComponent(token)}/${encodeURIComponent(key)}`),
|
||||
request<SharedDocument>(`/share/${encodeURIComponent(token)}/${encodeURIComponent(key)}`),
|
||||
}
|
||||
Reference in new issue
Block a user