mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
Integrates two community contributions into release/v3.8.8 with security hardening and conflict resolution. - **Plugins framework** (#2913 — thanks @oyi77): hooks + registry unification, plugin SDK (`definePlugin`), worker-thread sandbox, per-plugin hook rate limiting, SHA-256 integrity verification, semver-gated upgrade, and execution analytics. Plugin routes are loopback-only (`isLocalOnlyPath`); `child_process` exec is opt-in via `OMNIROUTE_PLUGINS_ALLOW_EXEC` (default off). - **API key option: disable non-published models** (#3017 — thanks @androw): a per-key flag restricting the key to discovered public models (combos / `auto/*` / `qtSd/*` routing still allowed). Hardening applied during integration: migration renumber (089/090/091), `/api/plugins` LOCAL_ONLY route-guard classification (closes the plugin-RCE vector), atomic install/upgrade with path containment, `O_EXCL` tmp-file creation (TOCTOU), rate-limit-map eviction, `validatePluginConfig` on configure, `buildErrorBody` on all plugin error paths. 246/246 tests; typecheck / cycles / docs-sync clean. Co-authored-by: oyi77 <14921983+oyi77@users.noreply.github.com> Co-authored-by: Nicolas Lorin <androw95220@gmail.com>
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
/**
|
|
* Plugin dev mode — hot-reload on file changes.
|
|
*
|
|
* Watches plugin directory for changes and triggers deactivate+activate cycle.
|
|
*
|
|
* @module plugins/devMode
|
|
*/
|
|
|
|
import { watch, type FSWatcher } from "fs";
|
|
import { logger } from "../../../open-sse/utils/logger.ts";
|
|
|
|
const log = logger("PLUGIN_DEV_MODE");
|
|
|
|
let watcher: FSWatcher | null = null;
|
|
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
const DEBOUNCE_MS = 500;
|
|
|
|
type ReloadFn = (pluginName: string) => Promise<void>;
|
|
|
|
/**
|
|
* Start dev mode — watch plugin directory for changes.
|
|
*/
|
|
export function startDevMode(pluginDir: string, reloadFn: ReloadFn): void {
|
|
if (watcher) return;
|
|
|
|
watcher = watch(pluginDir, { recursive: true }, (_eventType, filename) => {
|
|
if (!filename) return;
|
|
|
|
// Extract plugin name from path (first segment)
|
|
const pluginName = filename.split("/")[0];
|
|
if (!pluginName || pluginName.startsWith(".")) return;
|
|
|
|
// Debounce rapid changes
|
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
debounceTimer = setTimeout(async () => {
|
|
log.info("devMode.file_changed", { pluginName, file: filename });
|
|
try {
|
|
await reloadFn(pluginName);
|
|
log.info("devMode.reloaded", { pluginName });
|
|
} catch (err: unknown) {
|
|
log.error("devMode.reload_failed", {
|
|
pluginName,
|
|
error: err instanceof Error ? err.message : String(err),
|
|
});
|
|
}
|
|
}, DEBOUNCE_MS);
|
|
});
|
|
|
|
log.info("devMode.started", { pluginDir });
|
|
}
|
|
|
|
/**
|
|
* Stop dev mode — clean up watcher and timers.
|
|
*/
|
|
export function stopDevMode(): void {
|
|
if (debounceTimer) {
|
|
clearTimeout(debounceTimer);
|
|
debounceTimer = null;
|
|
}
|
|
if (watcher) {
|
|
watcher.close();
|
|
watcher = null;
|
|
}
|
|
log.info("devMode.stopped");
|
|
}
|