Skip to content

Commit 336a1ca

Browse files
authored
Merge pull request #32 from zh3036/fix-sync-issues
Fix sync issues: Add debug logging and switch to V1 API only
2 parents 8a30a6f + 8bb87ab commit 336a1ca

File tree

10 files changed

+512
-61
lines changed

10 files changed

+512
-61
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
dist
44
dist-ssr
55
*.local
6-
memos-sync-test-graph/
6+
memos-sync-test-graph/
7+
.env

CLAUDE.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Logseq plugin that syncs notes between Logseq and Memos (a self-hosted memo hub). The project is currently archived as the author no longer uses Memos, but the codebase remains functional.
8+
9+
## Development Commands
10+
11+
```bash
12+
# Install dependencies (enforces pnpm)
13+
pnpm install
14+
15+
# Start development server with hot reload
16+
pnpm dev
17+
18+
# Build the plugin for production
19+
pnpm build
20+
21+
# Run tests
22+
pnpm test
23+
24+
# Tests run automatically on pre-commit via Husky
25+
```
26+
27+
## Architecture
28+
29+
### Plugin Structure
30+
- **Entry Point**: `src/main.tsx` - Registers commands, sets up event handlers, and initializes the plugin
31+
- **Core Logic**: `src/memos.ts` - Handles sync operations between Logseq and Memos
32+
- **API Clients**: `src/memos/impls/` - Supports both Memos API v0 and v1 with abstracted interfaces
33+
- **Settings**: `src/settings.ts` - Defines plugin configuration schema using Logseq's settings system
34+
35+
### Key Patterns
36+
1. **API Version Abstraction**: The plugin uses a factory pattern to create the appropriate API client based on the Memos server version
37+
2. **Sync Modes**:
38+
- Journal: Syncs to daily journal pages
39+
- Custom Page: Syncs to a user-defined page
40+
- Journal Grouped: Groups memos by date in journal
41+
3. **Event-Driven**: Uses Logseq's event system for settings changes and user commands
42+
43+
### Important Files
44+
- `src/memos/client.ts`: Abstract base class for Memos API clients
45+
- `src/memos/type.ts`: TypeScript definitions for Memos data structures
46+
- `src/utils.ts` & `src/memos/utils.ts`: Utility functions for content generation and formatting
47+
48+
## Testing
49+
50+
Tests are located in `src/memos/__tests__/` and focus on content generation logic. The test suite runs automatically before commits.
51+
52+
## Build Process
53+
54+
The plugin uses Vite with a specialized Logseq plugin (`vite-plugin-logseq`) that:
55+
- Bundles the plugin code
56+
- Generates proper module exports for Logseq
57+
- Creates the distribution package
58+
59+
## Release Process
60+
61+
Uses semantic-release with GitHub Actions for automated versioning and releases. The release creates a zip file containing:
62+
- `dist/` folder with built assets
63+
- `readme.md`
64+
- `logo.svg`
65+
- `LICENSE`
66+
- `package.json`
67+
68+
## Important Considerations
69+
70+
1. **Memos API Compatibility**: The plugin supports both v0 and v1 of the Memos API. When making changes, ensure compatibility with both versions.
71+
2. **Logseq API**: Uses `@logseq/libs` v0.0.10. Check Logseq documentation for API usage.
72+
3. **Date Handling**: Uses date-fns for date manipulation. All dates should be handled consistently.
73+
4. **Error Handling**: The plugin includes user-friendly error messages. Maintain clear error reporting for sync failures.
74+
5. **Settings Validation**: Settings changes trigger immediate validation and re-initialization of the Memos client.

V1_API_FIXES.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Memos V1 API Fixes
2+
3+
This document summarizes the fixes made to support the Memos V1 API in the Logseq plugin.
4+
5+
## Issues Fixed
6+
7+
1. **Incorrect API endpoints**:
8+
- Changed `/api/v1/memo` to `/api/v1/memos` for listing memos
9+
- Changed `/api/v1/memo/{id}` to `/api/v1/memos/{id}` for updates
10+
- Changed `/api/v1/user/me` to `/api/v1/users/me` for user info
11+
12+
2. **Response format transformation**:
13+
- V1 API returns different field names than expected by the plugin
14+
- Added transformation from V1 format (name, createTime, etc.) to V0 format (id, createdTs, etc.)
15+
- Properly extract memo ID from the `name` field (e.g., "memos/123" → 123)
16+
17+
3. **Request parameters**:
18+
- Changed from `limit`/`offset` to `pageSize`/`pageToken`
19+
- Removed incorrect `rowStatus` filter (V1 API doesn't support it)
20+
- Added client-side filtering for archived memos
21+
22+
4. **HTTP headers**:
23+
- Added proper Accept and Content-Type headers
24+
- Ensured proper JSON response handling
25+
26+
## Files Modified
27+
28+
- `src/memos/impls/clientV1.ts`: Main V1 client implementation
29+
- `src/memos.ts`: Fixed typo "fitler" → "filter"
30+
31+
## Testing
32+
33+
The plugin has been tested and can now:
34+
- ✅ Connect to Memos V1 API
35+
- ✅ Fetch memos list
36+
- ✅ Create new memos
37+
- ✅ Update existing memos
38+
- ✅ Get user information
39+
40+
## Build
41+
42+
Run `pnpm build` to build the plugin with these fixes.

0 commit comments

Comments
 (0)