-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: local HTTP API, quick capture, mermaid/math plugins + ASAR fix #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
51124ab
feat: local HTTP API, quick capture, mermaid, math, vim mode + fix AS…
tomymaritano ec02e67
fix: address all 23 PR #231 review findings
tomymaritano 52edc7b
fix: CI failures + all review findings for PR #231
tomymaritano d3162ed
fix: add git HTTPS rewrite to Vercel install command
tomymaritano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| /** | ||
| * Local HTTP API Server IPC Handlers | ||
| * | ||
| * Manages the local API server lifecycle and exposes status/token info | ||
| * to the renderer (settings UI). | ||
| */ | ||
|
|
||
| import { ipcMain, app } from 'electron'; | ||
| import { createNoteId, createNoteOperation, updateNoteOperation } from '@readied/core'; | ||
| import { | ||
| LocalServer, | ||
| getOrCreateApiToken, | ||
| type LocalServerHandlers, | ||
| } from '../services/localServer.js'; | ||
| import type { SQLiteNoteRepository, DataPaths } from './types.js'; | ||
|
|
||
| // ============================================================================ | ||
| // Types | ||
| // ============================================================================ | ||
|
|
||
| export interface LocalServerHandlerDeps { | ||
| noteRepository: SQLiteNoteRepository; | ||
| dataPaths: DataPaths; | ||
| noteToSnapshot: (note: { | ||
| id: string; | ||
| notebookId: string; | ||
| content: string; | ||
| title: string; | ||
| isPinned: boolean; | ||
| isDeleted: boolean; | ||
| status: import('@readied/core').NoteStatus; | ||
| metadata: { | ||
| createdAt: string; | ||
| updatedAt: string; | ||
| tags: readonly string[]; | ||
| wordCount: number; | ||
| archivedAt: string | null; | ||
| }; | ||
| }) => { | ||
| id: string; | ||
| notebookId: string; | ||
| content: string; | ||
| title: string; | ||
| createdAt: string; | ||
| updatedAt: string; | ||
| tags: string[]; | ||
| wordCount: number; | ||
| archivedAt: string | null; | ||
| isArchived: boolean; | ||
| isPinned: boolean; | ||
| isDeleted: boolean; | ||
| status: import('@readied/core').NoteStatus; | ||
| }; | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Module State | ||
| // ============================================================================ | ||
|
|
||
| const server = new LocalServer(); | ||
| let apiToken: string | null = null; | ||
|
tomymaritano marked this conversation as resolved.
|
||
|
|
||
| // ============================================================================ | ||
| // Registration | ||
| // ============================================================================ | ||
|
|
||
| export function registerLocalServerHandlers(deps: LocalServerHandlerDeps): void { | ||
| const { noteRepository: repo, dataPaths, noteToSnapshot } = deps; | ||
|
|
||
| // Build handler callbacks that bridge HTTP requests to the note repository | ||
| const handlers: LocalServerHandlers = { | ||
| async listNotes() { | ||
| const notes = await repo.list(); | ||
| return notes | ||
| .filter(n => !n.isDeleted) | ||
| .map(n => ({ | ||
| id: n.id, | ||
| title: n.title, | ||
| excerpt: n.content.slice(0, 200).replace(/\n/g, ' '), | ||
| updatedAt: n.metadata.updatedAt, | ||
| })); | ||
| }, | ||
|
|
||
| async getNote(id) { | ||
| const note = await repo.get(createNoteId(id)); | ||
| if (!note) return null; | ||
| const snap = noteToSnapshot(note); | ||
| return { | ||
| id: snap.id, | ||
| title: snap.title, | ||
| content: snap.content, | ||
| notebookId: snap.notebookId, | ||
| createdAt: snap.createdAt, | ||
| updatedAt: snap.updatedAt, | ||
| tags: snap.tags, | ||
| wordCount: snap.wordCount, | ||
| isPinned: snap.isPinned, | ||
| }; | ||
| }, | ||
|
|
||
| async createNote(input) { | ||
| const result = await createNoteOperation(input, repo); | ||
| if (result.ok) { | ||
| return { ok: true, data: { id: result.data.id } }; | ||
| } | ||
| return { ok: false, error: result.error }; | ||
| }, | ||
|
|
||
| async updateNote(id, content) { | ||
| const noteId = createNoteId(id); | ||
| const result = await updateNoteOperation({ id: noteId, content }, repo); | ||
| return { ok: result.ok, error: result.ok ? undefined : result.error }; | ||
| }, | ||
|
|
||
| async searchNotes(query) { | ||
| const notes = await repo.search(query, 50); | ||
| return notes.map(n => ({ | ||
| id: n.id, | ||
| title: n.title, | ||
| excerpt: n.content.slice(0, 200).replace(/\n/g, ' '), | ||
| updatedAt: n.metadata.updatedAt, | ||
| })); | ||
| }, | ||
|
|
||
| async getNoteCount() { | ||
| return repo.count(); | ||
| }, | ||
|
|
||
| getAppVersion() { | ||
| return app.getVersion(); | ||
| }, | ||
| }; | ||
|
|
||
| // IPC: Start the local server | ||
| ipcMain.handle('localServer:start', async (_event, port?: number) => { | ||
| try { | ||
| if (port !== undefined && (typeof port !== 'number' || port < 1 || port > 65535)) { | ||
| return { ok: false, error: 'Invalid port' }; | ||
| } | ||
| if (server.isRunning()) return { ok: true, port: server.getPort() }; | ||
| apiToken = await getOrCreateApiToken(dataPaths.root); | ||
| await server.start(port, apiToken, handlers); | ||
| return { ok: true, port: server.getPort() }; | ||
| } catch (err) { | ||
| return { ok: false, error: err instanceof Error ? err.message : String(err) }; | ||
| } | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // IPC: Stop the local server | ||
| ipcMain.handle('localServer:stop', async () => { | ||
| try { | ||
| await server.stop(); | ||
| return { ok: true }; | ||
| } catch (err) { | ||
| return { ok: false, error: err instanceof Error ? err.message : String(err) }; | ||
| } | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // IPC: Get server status | ||
| ipcMain.handle('localServer:status', () => { | ||
| return { | ||
| running: server.isRunning(), | ||
| port: server.getPort(), | ||
| }; | ||
| }); | ||
|
|
||
| // IPC: Get the bearer token (for displaying in settings) | ||
| ipcMain.handle('localServer:getToken', async () => { | ||
| try { | ||
| if (!apiToken) { | ||
| apiToken = await getOrCreateApiToken(dataPaths.root); | ||
| } | ||
| return { ok: true, value: apiToken }; | ||
| } catch (err) { | ||
| return { ok: false, error: err instanceof Error ? err.message : String(err) }; | ||
| } | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Pre-initialise the API bearer token (called from main index). | ||
| * The actual server start is controlled by settings — the renderer | ||
| * will call localServer:start if the setting is enabled. | ||
| */ | ||
| export async function initApiToken(dataPaths: DataPaths): Promise<void> { | ||
| apiToken = await getOrCreateApiToken(dataPaths.root); | ||
| } | ||
|
|
||
| /** Stop the server on app quit */ | ||
| export async function stopLocalServer(): Promise<void> { | ||
| await server.stop(); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.