[PR #466] [MERGED] feat(extensions): server-side storage for cross-device sync #4631

Closed
opened 2026-10-22 04:09:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/466
Author: @Romuromylus
Created: 5/6/2026
Status: ✅ Merged
Merged: 5/6/2026
Merged by: @Romuromylus

Base: main ← Head: feat/extensions-server-storage


📝 Commits (5)

  • ee142e3 feat(extensions): server-side storage for cross-device sync
  • 8a9884c Merge branch 'main' into feat/extensions-server-storage
  • bd0e1c3 fix(extensions): address review feedback + restore swipe-nav toggles
  • 44b1a5a docs(changelog): note cross-device extension sync under 1.5.8
  • bb00a57 Revert "docs(changelog): note cross-device extension sync under 1.5.8"

📊 Changes

17 files changed (+499 additions, -59 deletions)

View changed files

📝 packages/client/src/App.tsx (+2 -0)
📝 packages/client/src/components/layout/CustomThemeInjector.tsx (+33 -4)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+41 -36)
➕ packages/client/src/hooks/use-extensions.ts (+148 -0)
📝 packages/client/src/stores/ui.store.ts (+27 -19)
📝 packages/server/drizzle.config.cts (+1 -0)
📝 packages/server/src/db/file-backed-store.ts (+1 -0)
📝 packages/server/src/db/migrate.ts (+11 -0)
➕ packages/server/src/db/schema/extensions.ts (+16 -0)
📝 packages/server/src/db/schema/index.ts (+1 -0)
📝 packages/server/src/middleware/rate-limit.ts (+4 -0)
➕ packages/server/src/routes/extensions.routes.ts (+46 -0)
📝 packages/server/src/routes/index.ts (+2 -0)
➕ packages/server/src/services/storage/extensions.storage.ts (+77 -0)
📝 packages/shared/src/index.ts (+2 -0)
➕ packages/shared/src/schemas/extension.schema.ts (+60 -0)
➕ packages/shared/src/types/extension.ts (+27 -0)

📄 Description

Linked issue

Closes #465

Why this change

Extensions in Marinara are stored in browser localStorage, so they're per-device + per-browser. A user on desktop + phone has to import each extension twice and toggle each one's enabled state separately on every device. Custom themes already solve this with server-side storage + useLegacyThemeMigration — extensions should follow the same pattern.

This is the storage slice of @kolacheee's earlier proposal in #431. This PR keeps the loader exactly as-is and only changes where the extension list lives.

What changed

New (server):

  • installed_extensions table — both file-backed (FILE_BACKED_TABLES) and legacy SQLite (migrate.ts CREATE TABLE).
  • /api/extensions CRUD route (GET /, POST /, PATCH /:id, DELETE /:id). No script-serving endpoint.
  • Drizzle schema, storage adapter, drizzle-kit config entry, route registration, schema barrel re-export.

New (shared):

  • InstalledExtension type + createExtensionSchema / updateExtensionSchema zod schemas, with .max() size caps on css (256 KiB) and js (1 MiB).

New (client):

  • useExtensions() / useCreateExtension() / useUpdateExtension() / useDeleteExtension() React Query hooks. useExtensions() mirrors useThemes() exactly: staleTime: 0, refetchOnWindowFocus: true, refetchOnReconnect: true, refetchInterval: 15s.
  • useLegacyExtensionMigration() — one-shot replay of pre-migration localStorage entries against /api/extensions, dedupe by name + css + js, then flip a hasMigratedExtensionsToServer flag.

Modified (client, surgical):

  • CustomThemeInjector.tsx — data source switches from useUIStore((s) => s.installedExtensions) to useExtensions(). Loader code (the import(blob:URL) pipeline, IIFE wrapper, API map management) is unchanged. Plus an extension-side apiFetch denylist for /extensions/* and /admin/* (a malicious extension shouldn't be able to re-install itself after deletion or pivot to admin endpoints).
  • SettingsPanel.tsx — extension actions switch from Zustand mutators to React Query mutations.
  • App.tsx — wires useLegacyExtensionMigration() next to useLegacyThemeMigration().
  • ui.store.ts — renames InstalledExtension to LegacyInstalledExtension (kept solely for migration replay), removes addExtension / removeExtension / toggleExtension actions, adds migration helpers + flag, bumps persist version 17 → 18 with a one-line migration step.
  • rate-limit.ts — new entry: /api/extensions capped at 60 req/min/IP.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

What was verified by the contributor on a private staging instance:

  1. pnpm check — passes on this branch (TS + ESLint + production build).
  2. Container build — built via Docker autoDeploy on a private staging instance; container restarted healthy, basicAuth gate responding HTTP 401 as expected.
  3. Cross-device sync — installed an extension on desktop browser at the staging URL → opened the same URL on phone (separate browser, separate localStorage, same basicAuth) → after the 15s refetch interval, phone saw the extension. Toggled enabled state on phone → desktop reflected within a refetch cycle.
  4. Migration — fresh device with extensions in localStorage from a pre-PR build → on first load after upgrade, all extensions migrate to /api/extensions, localStorage is cleared, migration flag flips, no duplicates.
  5. No regression on the loader — installed @kolacheee's AIO extension on the staging deploy, all three columns of its UI render and operate, no console errors, loader behavior identical to before.
  6. Hardening — apiFetch denylist — an extension that calls marinara.apiFetch("/extensions", ...) (any method) is rejected with a denial error before any network request is made. /admin/* likewise denied. Allowed control: marinara.apiFetch("/themes") succeeds.
  7. Hardening — size cap — importing a 1.07 MiB JS extension via Settings → Import returns "Failed to import extension" (zod js.max() rejects server-side). 256 KiB CSS / 1 MiB JS caps confirmed enforced.
  8. Hardening — rate limit — 60 req/min on /api/extensions covers React Query polling + legacy migration of any reasonable extension count without affecting normal use.

Docs and release impact

  • No docs changes needed

Reviewer to decide whether CHANGELOG.md should mention this for the next minor release. Happy to add a one-liner if you want it noted.

UI evidence (if applicable)

The Settings → Extensions panel UI is unchanged in look and feel — same import button, same enable/disable/delete row controls. The only behavior difference is that mutations now hit the server instead of localStorage. Cross-device sync is invisible to the user except as "extensions appear on my other device."


Credit: storage layer + migration shape adapted from @kolacheee's earlier work in #431. Thanks to them for surfacing the cross-device gap.

Summary by CodeRabbit

  • New Features

    • Import extensions from .json/.css/.js files via the Settings panel.
    • Extension management is now server-backed with UI controls to enable/disable, update, and delete.
  • Chores

    • Local/browser extensions are automatically migrated to server storage.
    • Backend and database updated to store and serve installed extensions.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/466 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/6/2026 **Status:** ✅ Merged **Merged:** 5/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `feat/extensions-server-storage` --- ### 📝 Commits (5) - [`ee142e3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ee142e3a368e9c35676553ae54bdbebf51691dbb) feat(extensions): server-side storage for cross-device sync - [`8a9884c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8a9884c2f9c0b2e94f44bd98007d0f65c2ee5c86) Merge branch 'main' into feat/extensions-server-storage - [`bd0e1c3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bd0e1c3f94fbfc81630cb35eada2c66795ff62a5) fix(extensions): address review feedback + restore swipe-nav toggles - [`44b1a5a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/44b1a5ad045453152e509308b75ef23f091c12e0) docs(changelog): note cross-device extension sync under 1.5.8 - [`bb00a57`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bb00a57899338b3d1ac0f724a325a4a68a20ba83) Revert "docs(changelog): note cross-device extension sync under 1.5.8" ### 📊 Changes **17 files changed** (+499 additions, -59 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/App.tsx` (+2 -0) 📝 `packages/client/src/components/layout/CustomThemeInjector.tsx` (+33 -4) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+41 -36) ➕ `packages/client/src/hooks/use-extensions.ts` (+148 -0) 📝 `packages/client/src/stores/ui.store.ts` (+27 -19) 📝 `packages/server/drizzle.config.cts` (+1 -0) 📝 `packages/server/src/db/file-backed-store.ts` (+1 -0) 📝 `packages/server/src/db/migrate.ts` (+11 -0) ➕ `packages/server/src/db/schema/extensions.ts` (+16 -0) 📝 `packages/server/src/db/schema/index.ts` (+1 -0) 📝 `packages/server/src/middleware/rate-limit.ts` (+4 -0) ➕ `packages/server/src/routes/extensions.routes.ts` (+46 -0) 📝 `packages/server/src/routes/index.ts` (+2 -0) ➕ `packages/server/src/services/storage/extensions.storage.ts` (+77 -0) 📝 `packages/shared/src/index.ts` (+2 -0) ➕ `packages/shared/src/schemas/extension.schema.ts` (+60 -0) ➕ `packages/shared/src/types/extension.ts` (+27 -0) </details> ### 📄 Description ## Linked issue Closes #465 ## Why this change Extensions in Marinara are stored in browser `localStorage`, so they're per-device + per-browser. A user on desktop + phone has to import each extension twice and toggle each one's enabled state separately on every device. Custom themes already solve this with server-side storage + `useLegacyThemeMigration` — extensions should follow the same pattern. This is the *storage* slice of @kolacheee's earlier proposal in #431. This PR keeps the loader exactly as-is and only changes where the extension list lives. ## What changed **New (server):** - `installed_extensions` table — both file-backed (`FILE_BACKED_TABLES`) and legacy SQLite (`migrate.ts` `CREATE TABLE`). - `/api/extensions` CRUD route (`GET /`, `POST /`, `PATCH /:id`, `DELETE /:id`). No script-serving endpoint. - Drizzle schema, storage adapter, drizzle-kit config entry, route registration, schema barrel re-export. **New (shared):** - `InstalledExtension` type + `createExtensionSchema` / `updateExtensionSchema` zod schemas, with `.max()` size caps on `css` (256 KiB) and `js` (1 MiB). **New (client):** - `useExtensions()` / `useCreateExtension()` / `useUpdateExtension()` / `useDeleteExtension()` React Query hooks. `useExtensions()` mirrors `useThemes()` exactly: `staleTime: 0`, `refetchOnWindowFocus: true`, `refetchOnReconnect: true`, `refetchInterval: 15s`. - `useLegacyExtensionMigration()` — one-shot replay of pre-migration `localStorage` entries against `/api/extensions`, dedupe by `name + css + js`, then flip a `hasMigratedExtensionsToServer` flag. **Modified (client, surgical):** - `CustomThemeInjector.tsx` — data source switches from `useUIStore((s) => s.installedExtensions)` to `useExtensions()`. **Loader code (the `import(blob:URL)` pipeline, IIFE wrapper, API map management) is unchanged.** Plus an extension-side `apiFetch` denylist for `/extensions/*` and `/admin/*` (a malicious extension shouldn't be able to re-install itself after deletion or pivot to admin endpoints). - `SettingsPanel.tsx` — extension actions switch from Zustand mutators to React Query mutations. - `App.tsx` — wires `useLegacyExtensionMigration()` next to `useLegacyThemeMigration()`. - `ui.store.ts` — renames `InstalledExtension` to `LegacyInstalledExtension` (kept solely for migration replay), removes `addExtension` / `removeExtension` / `toggleExtension` actions, adds migration helpers + flag, bumps persist version `17 → 18` with a one-line migration step. - `rate-limit.ts` — new entry: `/api/extensions` capped at 60 req/min/IP. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes What was verified by the contributor on a private staging instance: 1. **`pnpm check`** — passes on this branch (TS + ESLint + production build). 2. **Container build** — built via Docker autoDeploy on a private staging instance; container restarted healthy, basicAuth gate responding HTTP 401 as expected. 3. **Cross-device sync** — installed an extension on desktop browser at the staging URL → opened the same URL on phone (separate browser, separate localStorage, same basicAuth) → after the 15s refetch interval, phone saw the extension. Toggled enabled state on phone → desktop reflected within a refetch cycle. 4. **Migration** — fresh device with extensions in `localStorage` from a pre-PR build → on first load after upgrade, all extensions migrate to `/api/extensions`, `localStorage` is cleared, migration flag flips, no duplicates. 5. **No regression on the loader** — installed [@kolacheee's AIO extension](https://github.com/kolacheee/Marinara-kolaches-aio-extension) on the staging deploy, all three columns of its UI render and operate, no console errors, loader behavior identical to before. 6. **Hardening — `apiFetch` denylist** — an extension that calls `marinara.apiFetch("/extensions", ...)` (any method) is rejected with a denial error before any network request is made. `/admin/*` likewise denied. Allowed control: `marinara.apiFetch("/themes")` succeeds. 7. **Hardening — size cap** — importing a 1.07 MiB JS extension via Settings → Import returns "Failed to import extension" (zod `js.max()` rejects server-side). 256 KiB CSS / 1 MiB JS caps confirmed enforced. 8. **Hardening — rate limit** — 60 req/min on `/api/extensions` covers React Query polling + legacy migration of any reasonable extension count without affecting normal use. ## Docs and release impact - [x] No docs changes needed Reviewer to decide whether `CHANGELOG.md` should mention this for the next minor release. Happy to add a one-liner if you want it noted. ## UI evidence (if applicable) The Settings → Extensions panel UI is unchanged in look and feel — same import button, same enable/disable/delete row controls. The only behavior difference is that mutations now hit the server instead of `localStorage`. Cross-device sync is invisible to the user except as "extensions appear on my other device." --- Credit: storage layer + migration shape adapted from @kolacheee's earlier work in #431. Thanks to them for surfacing the cross-device gap. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Import extensions from .json/.css/.js files via the Settings panel. * Extension management is now server-backed with UI controls to enable/disable, update, and delete. * **Chores** * Local/browser extensions are automatically migrated to server storage. * Backend and database updated to store and serve installed extensions. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:09:19 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4631
No description provided.