Skip to content

DO_NOT_MERGE - feat: templates service, APKG export, Node.js pipeline#1942

Draft
aalemayhu wants to merge 23 commits intomainfrom
fix/templates-integration
Draft

DO_NOT_MERGE - feat: templates service, APKG export, Node.js pipeline#1942
aalemayhu wants to merge 23 commits intomainfrom
fix/templates-integration

Conversation

@aalemayhu
Copy link
Copy Markdown
Contributor

@aalemayhu aalemayhu commented Apr 4, 2026

Scope

Template management + the supporting Node.js APKG pipeline. The marketplace publish/browse and AI-generate pieces are held for later (see below).

What's in

  • Node.js APKG pipeline via `sql.js` (+ `sql-wasm.js`) — src/lib/templates/exportNoteTypeToApkg.ts\. Replaces the Python `genanki` path for this export route.
  • POST /api/templates/export — generates an .apkg from a note type JSON, using `previewData` as the example card. Swagger-documented.
  • Template management endpoints for the Edit Templates UI:
    • GET `/api/templates/defaults` — hard-coded starter templates (Basic, Cloze, Vocabulary, Medical Term, Code Card, Math, …). TODO in-file to migrate these into the `2anki/templates` repo eventually.
    • GET `/api/templates/user` — current user's saved `{ templates, hiddenIds }`.
    • PUT `/api/templates/user` — save that payload.
  • `TEMPLATE_DIR` env var + deploy workflow clones `2anki/templates` and sets `TEMPLATE_DIR` before `pm2 restart`.
  • Modern Cloze contrast fix (navy gradient, blue highlights) on the template repo side — tracked via the `TEMPLATE_DIR` wiring here.
  • Logging / console cleanups in `TemplatesController`.
  • TemplateService / TemplatesController refactor — named-import, `findByOwner`, `getUserData` / `saveUserData` / `exportTemplate` handlers.

What's deliberately out (not deleted, just not merged)

  • Marketplace publish / browse — `public_templates` table + migrations, `PublicTemplatesController`, `PublicTemplatesRepository`, `POST /api/templates/publish`, `GET /api/templates/public`. Held until user signal asks for it.
  • AI template generation — `AITemplateController`, `AITemplateService`, `POST /api/templates/generate`, `express-rate-limit` dep. Parked on branch `feat/ai-template-generate` for separate scoping.

Test plan

  • Swagger coverage test passes (all three kept endpoints now documented).
  • Typecheck clean.
  • Manual: hit `POST /api/templates/export` with a sample note type + previewData — downloads a valid `.apkg` importable in Anki.
  • Manual: `GET /api/templates/defaults` returns the starter templates.

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 4, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e205e58-1374-437c-94bf-852188e0347c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/templates-integration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@aalemayhu aalemayhu changed the title fix: use named TemplateService import and remove console calls in Tem… feat: expose templates and marketplace Apr 5, 2026
aalemayhu and others added 10 commits April 5, 2026 13:48
- Add migration to add base_type column (default 'basic')
- Add baseType to PublicTemplateRow and CreatePublicTemplateInput
- Pass baseType through publish endpoint and include in list response
- Update Swagger docs with base_type enum description
Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com>
Splits the originally-combined PR down to just template management so
that piece can ship on its own. The marketplace publish/browse half is
held for later; the AI-generate endpoint moves to its own branch
(feat/ai-template-generate) since it's a distinct feature.

Removed:
- migrations: public_templates + its unique-owner-name + base_type
  additions, and the template_downloads tracking table
- PublicTemplatesController + PublicTemplatesRepository
- AITemplateController + AITemplateService + /api/templates/generate
  route + express-rate-limit dependency
- /api/templates/public and /api/templates/publish route registrations
  and their Swagger blocks
- update-server.js dev artifact that should never have been committed

Kept and now swagger-documented:
- /api/templates/export (Node.js sql.js APKG pipeline)
- /api/templates/defaults (hard-coded starter note types)
- /api/templates/user GET/PUT (Edit Templates payload)

Added a TODO at the top of DefaultTemplatesService noting the hardcoded
content should eventually migrate to the 2anki/templates repo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@aalemayhu aalemayhu changed the title feat: expose templates and marketplace feat: templates service, APKG export, Node.js pipeline Apr 19, 2026
Two changes driven by the new_security_hotspots_reviewed + new_duplicated
_lines_density failures on PR #1942:

- DefaultTemplatesService now builds its eight starter note types
  through tiny helpers — field(name, ord, font?, size?) and
  noteType({ id, name, type?, tmpls, flds, css, tags? }) — instead of
  repeating the same { sticky: false, rtl: false, font: 'Inter', size: 20 }
  shape 25× and { mod: 0, usn: -1, sortf: 0 } 8×. Net ~90 lines of
  duplicated boilerplate gone.

- exportNoteTypeToApkg swaps the Math.random()-based GUID for one
  built from crypto.randomBytes (S2245 was the remaining security
  hotspot on this PR's changeset).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@aalemayhu aalemayhu changed the title feat: templates service, APKG export, Node.js pipeline DO_NOT_MERG - feat: templates service, APKG export, Node.js pipeline Apr 20, 2026
@aalemayhu aalemayhu changed the title DO_NOT_MERG - feat: templates service, APKG export, Node.js pipeline DO_NOT_MERGE - feat: templates service, APKG export, Node.js pipeline Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant