@lenne.tech/nest-server 11.32.2 → 11.32.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/rules/configurable-features.md +1 -1
- package/FRAMEWORK-API.md +3 -1
- package/bin/migrate.js +13 -3
- package/dist/core/common/helpers/file.helper.d.ts +14 -2
- package/dist/core/common/helpers/file.helper.js +48 -9
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +2 -0
- package/dist/core/modules/ai/inputs/core-ai-connection.input.js +2 -0
- package/dist/core/modules/ai/inputs/core-ai-connection.input.js.map +1 -1
- package/dist/core/modules/ai/services/core-ai-connection.service.d.ts +1 -0
- package/dist/core/modules/ai/services/core-ai-connection.service.js +68 -0
- package/dist/core/modules/ai/services/core-ai-connection.service.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.d.ts +4 -1
- package/dist/core/modules/file/core-file.controller.js +39 -6
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/migrate/cli/migrate-cli.d.ts +3 -1
- package/dist/core/modules/migrate/cli/migrate-cli.js +29 -4
- package/dist/core/modules/migrate/cli/migrate-cli.js.map +1 -1
- package/dist/core/modules/migrate/helpers/migration.helper.d.ts +1 -0
- package/dist/core/modules/migrate/helpers/migration.helper.js +51 -4
- package/dist/core/modules/migrate/helpers/migration.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/security-overrides.md +9 -2
- package/migration-guides/11.32.2-to-11.32.3.md +129 -0
- package/migration-guides/11.32.3-to-11.32.4.md +323 -0
- package/package.json +1 -1
- package/src/core/common/helpers/file.helper.spec.ts +145 -0
- package/src/core/common/helpers/file.helper.ts +148 -10
- package/src/core/common/interfaces/server-options.interface.ts +23 -0
- package/src/core/modules/ai/README.md +6 -0
- package/src/core/modules/ai/inputs/core-ai-connection.input.ts +2 -0
- package/src/core/modules/ai/interfaces/ai-tool.interface.ts +18 -3
- package/src/core/modules/ai/services/core-ai-connection.service.ts +135 -0
- package/src/core/modules/file/README.md +59 -0
- package/src/core/modules/file/core-file.controller.spec.ts +164 -0
- package/src/core/modules/file/core-file.controller.ts +100 -8
- package/src/core/modules/migrate/README.md +35 -0
- package/src/core/modules/migrate/cli/migrate-cli.ts +69 -6
- package/src/core/modules/migrate/helpers/migration.helper.spec.ts +85 -0
- package/src/core/modules/migrate/helpers/migration.helper.ts +131 -4
|
@@ -271,7 +271,7 @@ This pattern is currently applied to:
|
|
|
271
271
|
| JSONTransport Production Guard | `email.smtp` with `jsonTransport` | Runtime Guard | Throws `Error` when `email.smtp` has a truthy `jsonTransport` property in `production` or `staging` environments (read from config `env` field). JSONTransport silently discards all outgoing mail — the guard prevents accidental misconfiguration that causes password-reset, 2FA, and verification emails to vanish. Use `{ jsonTransport: true }` only in CI/e2e/local environments |
|
|
272
272
|
| Cookies | `cookies` | Boolean Shorthand (default true) | `true` (enabled), `exposeTokenInBody: false`. When enabled: loads `cookie-parser`, sets CORS `credentials: true`, sets signed httpOnly session cookies. When `exposeTokenInBody: true`: token stays in response body alongside cookies (for hybrid JWT+Cookie auth). JWT via `Authorization: Bearer` always works independently. **BetterAuth cookie name (since v11.27.6):** `createBetterAuthInstance()` pins `advanced.useSecureCookies: false` so BetterAuth's native handlers read the same UNPREFIXED `<cookiePrefix>.session_token` the helper writes (fixes a `401` split-brain on 2FA/passkey/`/token`); the `Secure` attribute is still applied on an `https://` baseURL via `advanced.defaultCookieAttributes`. Opt back into the `__Secure-` prefix with `betterAuth.options.advanced.useSecureCookies: true` only when BetterAuth manages cookies entirely |
|
|
273
273
|
| CORS | `cors` | Boolean Shorthand | `enabled: true`, `allowAll: false`, `deriveAppUrl: true`. Origins come from `appUrl`/`baseUrl`, resolved by the shared `resolveServerUrls()` helper (`cookies.helper.ts`) that ALL three CORS layers use (GraphQL, REST, BetterAuth `trustedOrigins`) — they can no longer drift. `appUrl` resolution: explicit → derived from a **host-split** localhost `baseUrl` (its `api.` label strips to a sibling host: `https://api.crm.localhost` → `https://crm.localhost`, as served by `lt dev up`; the port is preserved) → localhost default (`http://localhost:3001`, only for `env: local`/`ci`/`e2e` with a **port-split** localhost `baseUrl` — one host, API `:3000`, app `:3001`; `https://api.localhost` strips to the bare `localhost` the API already answers on and is therefore a port split, not a host split) → derived from `baseUrl` by stripping a leading `api.` label (`https://api.example.com` → `https://example.com`). **Security:** the derived origin receives credentialed CORS; set `deriveAppUrl: false` when the apex domain is not trusted, then list the frontend origin via `appUrl`/`allowedOrigins` (a host-split localhost `baseUrl` then falls back to the localhost default). The derivation never yields a bare TLD (`https://api.dev` unchanged) and never emits the opaque `null` origin (non-http(s) `baseUrl` passes through verbatim). `allowAll: true` mirrors the request origin for REST/GraphQL, but BetterAuth's `trustedOrigins` still resolve to `[appUrl]` (+ passkey origins) — an origin check has no "allow everything" mode, so a separately hosted frontend must appear in `appUrl`/`allowedOrigins` (or set `betterAuth.trustedOrigins` explicitly). `enabled: false` disables CORS on all layers including BetterAuth (`trustedOrigins: []`, which still trusts BetterAuth's own `baseURL`). Explicit `betterAuth.trustedOrigins` always takes precedence |
|
|
274
|
-
| AI Assistant | `ai` | Presence Implies Enabled | Core: `maxIterations: 5`, `defaultMode: 'auto'` (or `'plan'`), `rateLimit` (presence implies enabled: `max: 20`, `windowSeconds: 60`), `systemPrompt`, `documentation` (injected into the system prompt), `encryptionSecret`. **DB-backed LLM connections** (`aiConnections`, admin CRUD) with AES-256-GCM-encrypted API keys (`AiCryptoService`, secret from `ai.encryptionSecret` / `NSC__AI__ENCRYPTION_SECRET` / `SECRETS_ENCRYPTION_KEY`; `apiKeyEncrypted` is a global `secretFields` entry, never returned — only `hasApiKey`); optional `defaultConnection` one-time seed. **Provider abstraction** (`ILlmProvider`, default `OpenAiCompatibleProvider` for any OpenAI-compatible endpoint via `fetch`; per-connection `supportsNativeTools`/`supportsJsonResponse` capabilities, emulated tool calling when native tools are unavailable). **Tool registry** (`AiToolRegistry`, tools self-register, role-filtered; tools may be `mutating`/`destructive` and define `authorize()` for pre-flight data-level checks). **Plan mode** (`input.mode: 'plan'`): full plan → pre-flight authorize ALL steps → all-or-nothing execution with a translated (de/en) error when any step is not permitted. **Confirmation policy**: `confirmation.mutating: { default, enforced }` + client `input.requireConfirmation` (ignored when enforced); `destructive` always confirms. **Client metadata** (`input.metadata`: URL/nav/console logs, untrusted+capped). **Multi-turn conversations** (`aiConversations`, owner-scoped). **SSE streaming** (`POST /ai/stream`). **Audit** (`audit: false` → persist to `aiInteractions`, admin-readable). **Token budgets** (`budget: { period: 'day'|'month'|'none', user: { maxTokens?, maxPrompts? }, tenant: { maxTokens?, maxPrompts? } }`, requires audit): per-user AND per-tenant limits with config defaults; admins override per user/tenant at runtime (`aiBudgetLimits`, `CoreAiBudgetService`). Resolution: override → default → unlimited (missing/0 = unlimited). Enforced before the run (HTTP 429 + translated). Each response carries a compact `budget` summary (promptTokens, usedTokens, remainingTokens, resetAt); full breakdown via `aiUsage` query / `GET /ai/usage`. **Self-optimizing prompts**: the system prompt is assembled from keyed fragments (`CoreAiPromptBuilderService` ships built-in defaults; works with zero rows). Admin-editable overrides per slot (`aiSlots`, admin CRUD, `/ai/slots`) scoped by `key`/`locale`/`capability`/`tenantId`, with tenant override/reset semantics and placeholder tokens resolved at run time via the placeholder registry. **Governed learning loop** (`promptLearning: { enabled: true, autoApply: false }`): tool errors record `suggested` hints (`aiPromptHints`, admin CRUD, `/ai/prompt-hints`) that only reach the prompt once admin-approved (or auto-approved when `autoApply`); hints only ADD guidance, never relax permissions. **Context window** (`contextWindow`, default 8192; auto-detected per connection via `ILlmProvider.detectContextWindow()` — Ollama `/api/show` probe / known-model table / Claude alias — and persisted): per-user/session history is trimmed (oldest non-system turns dropped, last truncated) and tool-results capped to `maxToolResultChars` (default 12000) so a session never overflows the model. **Deferred tool schemas** (`deferToolSchemas`, default `false`): the system-prompt tool catalog then lists only tool NAMES + descriptions instead of full JSON schemas, and the model fetches a schema on demand via the built-in `search_tools` meta-tool — with a large registry the schemas alone can dominate a small context window. `deferToolSummaryChars` (default `0` = untruncated) additionally caps each description in that DEFERRED catalog: whole sentences up to the cap (always at least the first), word-boundary cut when the first sentence already exceeds it, and a `…` marker appended ON TOP of the cap. The default of `0` keeps the saving opt-in, so enabling `deferToolSchemas` alone never changes what a description says; set roughly 200–400 alongside it to actually reclaim the context. Both apply to EMULATED providers only — a connection with `supportsNativeTools: true` receives every full description + schema via `buildToolSchemas()` regardless, so truncation and the banner are skipped there rather than asserting a cut the tool payload contradicts. The omitted tail is where preconditions and role restrictions usually live — the catalog banner tells the model to fetch the full text via `search_tools` first, but this is model GUIDANCE only: authorization is enforced server-side by the registry's role filter (`forUser()`), the execution-time re-check, and the `mutating`/`destructive` flags read by the confirmation gate — never by what the catalog shows. (`AiTool.authorize()` runs in PLAN MODE only; in auto mode and over MCP, data-level checks must live inside `execute()`.) **MCP server** (`mcp: false` → `/ai/mcp` Streamable HTTP, Bearer auth, lazy `@modelcontextprotocol/sdk`; `mcp: { oauth: true, oauthSecret }` adds OAuth 2.1 — HMAC tokens + PKCE S256 + dynamic registration via `mountAiMcpOAuth(app)` in main.ts). Overrides via `CoreModule.forRoot(env, { ai: { budgetService, connectionResolver, connectionService, controller, conversationService, interactionService, mcpClientService, modeService, placeholderRegistry, preferenceService, promptBuilder, promptHintService, promptService, resolver, service, slotService, toolGrantService, toolPolicyService } })` |
|
|
274
|
+
| AI Assistant | `ai` | Presence Implies Enabled | Core: `maxIterations: 5`, `defaultMode: 'auto'` (or `'plan'`), `rateLimit` (presence implies enabled: `max: 20`, `windowSeconds: 60`), `systemPrompt`, `documentation` (injected into the system prompt), `encryptionSecret`. **DB-backed LLM connections** (`aiConnections`, admin CRUD) with AES-256-GCM-encrypted API keys (`AiCryptoService`, secret from `ai.encryptionSecret` / `NSC__AI__ENCRYPTION_SECRET` / `SECRETS_ENCRYPTION_KEY`; `apiKeyEncrypted` is a global `secretFields` entry, never returned — only `hasApiKey`); optional `defaultConnection` one-time seed. **Provider abstraction** (`ILlmProvider`, default `OpenAiCompatibleProvider` for any OpenAI-compatible endpoint via `fetch`; per-connection `supportsNativeTools`/`supportsJsonResponse` capabilities, emulated tool calling when native tools are unavailable). **Tool registry** (`AiToolRegistry`, tools self-register, role-filtered; tools may be `mutating`/`destructive` and define `authorize()` for pre-flight data-level checks). **Plan mode** (`input.mode: 'plan'`): full plan → pre-flight authorize ALL steps → all-or-nothing execution with a translated (de/en) error when any step is not permitted. **Confirmation policy**: `confirmation.mutating: { default, enforced }` + client `input.requireConfirmation` (ignored when enforced); `destructive` always confirms. **Client metadata** (`input.metadata`: URL/nav/console logs, untrusted+capped). **Multi-turn conversations** (`aiConversations`, owner-scoped). **SSE streaming** (`POST /ai/stream`). **Audit** (`audit: false` → persist to `aiInteractions`, admin-readable). **Token budgets** (`budget: { period: 'day'|'month'|'none', user: { maxTokens?, maxPrompts? }, tenant: { maxTokens?, maxPrompts? } }`, requires audit): per-user AND per-tenant limits with config defaults; admins override per user/tenant at runtime (`aiBudgetLimits`, `CoreAiBudgetService`). Resolution: override → default → unlimited (missing/0 = unlimited). Enforced before the run (HTTP 429 + translated). Each response carries a compact `budget` summary (promptTokens, usedTokens, remainingTokens, resetAt); full breakdown via `aiUsage` query / `GET /ai/usage`. **Self-optimizing prompts**: the system prompt is assembled from keyed fragments (`CoreAiPromptBuilderService` ships built-in defaults; works with zero rows). Admin-editable overrides per slot (`aiSlots`, admin CRUD, `/ai/slots`) scoped by `key`/`locale`/`capability`/`tenantId`, with tenant override/reset semantics and placeholder tokens resolved at run time via the placeholder registry. **Governed learning loop** (`promptLearning: { enabled: true, autoApply: false }`): tool errors record `suggested` hints (`aiPromptHints`, admin CRUD, `/ai/prompt-hints`) that only reach the prompt once admin-approved (or auto-approved when `autoApply`); hints only ADD guidance, never relax permissions. **Context window** (`contextWindow`, default 8192; auto-detected per connection via `ILlmProvider.detectContextWindow()` — Ollama `/api/show` probe / known-model table / Claude alias — and persisted): per-user/session history is trimmed (oldest non-system turns dropped, last truncated) and tool-results capped to `maxToolResultChars` (default 12000) so a session never overflows the model. A connection's window can be seeded via `ai.defaultConnection.contextWindow` (validated: a non-positive/non-integer value is dropped with a warning). **Capability drift check** (`capabilityDriftCheck`, default `false`): opt-in boot self-check that probes each enabled connection with an EXPLICIT `supportsNativeTools`/`supportsJsonResponse` (built with those flags cleared so the endpoint is actually re-probed) and logs a warning on mismatch — the stored value is never changed. OFF by default because it makes outbound calls to the LLM endpoints on every boot; also skipped in the ci/e2e runners. **Deferred tool schemas** (`deferToolSchemas`, default `false`): the system-prompt tool catalog then lists only tool NAMES + descriptions instead of full JSON schemas, and the model fetches a schema on demand via the built-in `search_tools` meta-tool — with a large registry the schemas alone can dominate a small context window. `deferToolSummaryChars` (default `0` = untruncated) additionally caps each description in that DEFERRED catalog: whole sentences up to the cap (always at least the first), word-boundary cut when the first sentence already exceeds it, and a `…` marker appended ON TOP of the cap. The default of `0` keeps the saving opt-in, so enabling `deferToolSchemas` alone never changes what a description says; set roughly 200–400 alongside it to actually reclaim the context. Both apply to EMULATED providers only — a connection with `supportsNativeTools: true` receives every full description + schema via `buildToolSchemas()` regardless, so truncation and the banner are skipped there rather than asserting a cut the tool payload contradicts. The omitted tail is where preconditions and role restrictions usually live — the catalog banner tells the model to fetch the full text via `search_tools` first, but this is model GUIDANCE only: authorization is enforced server-side by the registry's role filter (`forUser()`), the execution-time re-check, and the `mutating`/`destructive` flags read by the confirmation gate — never by what the catalog shows. (`AiTool.authorize()` runs in PLAN MODE only; in auto mode and over MCP, data-level checks must live inside `execute()`.) **MCP server** (`mcp: false` → `/ai/mcp` Streamable HTTP, Bearer auth, lazy `@modelcontextprotocol/sdk`; `mcp: { oauth: true, oauthSecret }` adds OAuth 2.1 — HMAC tokens + PKCE S256 + dynamic registration via `mountAiMcpOAuth(app)` in main.ts). Overrides via `CoreModule.forRoot(env, { ai: { budgetService, connectionResolver, connectionService, controller, conversationService, interactionService, mcpClientService, modeService, placeholderRegistry, preferenceService, promptBuilder, promptHintService, promptService, resolver, service, slotService, toolGrantService, toolPolicyService } })` |
|
|
275
275
|
|
|
276
276
|
## Module Override Pattern (via `ICoreModuleOverrides`)
|
|
277
277
|
|
package/FRAMEWORK-API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @lenne.tech/nest-server — Framework API Reference
|
|
2
2
|
|
|
3
|
-
> Auto-generated from source code on 2026-07-
|
|
3
|
+
> Auto-generated from source code on 2026-07-30 (v11.32.4)
|
|
4
4
|
> File: `FRAMEWORK-API.md` — compact, machine-readable API surface for Claude Code
|
|
5
5
|
|
|
6
6
|
## CoreModule.forRoot()
|
|
@@ -103,6 +103,7 @@ When `passkey` is enabled, `trustedOrigins` is required (compile-time enforcemen
|
|
|
103
103
|
- `allowedBaseUrlHosts?`: `string[] | undefined` — Optional SSRF allowlist for connection base URLs. When set (non-empty), the
|
|
104
104
|
- `audit?`: `boolean | undefined` (default: `false`) — Persist an audit record (`aiInteractions`) for every prompt run (admin-readable).
|
|
105
105
|
- `budget?`: `{ period?: "day" | "month" | "none"; tenant?: { maxPrompts?: number; maxToken...` — Token/prompt budgets for AI prompts, enforced before a run (HTTP 429 + translated
|
|
106
|
+
- `capabilityDriftCheck?`: `boolean | undefined` (default: `false`) — Opt-in boot self-check: after startup, probe each enabled connection that declares
|
|
106
107
|
- `confirmation?`: `{ mutating?: { default?: boolean; enforced?: boolean; }; } | undefined` — Confirmation policy for mutating tool actions (create/update/delete).
|
|
107
108
|
- `documentation?`: `string | undefined` — System documentation injected into the system prompt to inform the LLM
|
|
108
109
|
- `defaultConnection?`: `IAiDefaultConnection | undefined` — Optional one-time seed for a default connection (see {@link IAiDefaultConnection}).
|
|
@@ -133,6 +134,7 @@ When `passkey` is enabled, `trustedOrigins` is required (compile-time enforcemen
|
|
|
133
134
|
- `apiKeyEnv?`: `string | undefined` — Name of an environment variable holding the API key (e.g. 'AI_API_KEY').
|
|
134
135
|
- `baseUrl`: `string` — Base URL of the OpenAI-compatible endpoint.
|
|
135
136
|
- `capabilities?`: `string[] | undefined` — Capability tags (free-form, e.g. 'analysis', 'vision').
|
|
137
|
+
- `contextWindow?`: `number | undefined` — Total context window (input + output tokens) the model supports. Drives the
|
|
136
138
|
- `defaultMaxTokens?`: `number | undefined` — Default maximum number of tokens for completions.
|
|
137
139
|
- `defaultTemperature?`: `number | undefined` — Default sampling temperature.
|
|
138
140
|
- `description?`: `string | undefined` — Human-readable description.
|
package/bin/migrate.js
CHANGED
|
@@ -93,7 +93,17 @@ if (require.main === module) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
// Load and run the CLI
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
// Load and run the CLI.
|
|
97
|
+
//
|
|
98
|
+
// Prefer runCli(): it drains stdout and then exits explicitly, so a handle left
|
|
99
|
+
// behind by MongoDB/GridFS cannot keep the process alive after the work is done
|
|
100
|
+
// (a migration step that never returns blocks the container before the server
|
|
101
|
+
// ever starts). main() is the fallback for a dist built before runCli existed —
|
|
102
|
+
// it resolves normally but relies on the event loop draining by itself.
|
|
103
|
+
const cli = require(cliPath);
|
|
104
|
+
const run = cli.runCli || cli.main;
|
|
105
|
+
Promise.resolve(run()).catch((error) => {
|
|
106
|
+
console.error('Fatal error:', error);
|
|
107
|
+
process.exitCode = 1;
|
|
108
|
+
});
|
|
99
109
|
}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
|
|
2
|
+
export interface UploadAllowList {
|
|
3
|
+
extensions: readonly string[];
|
|
4
|
+
mimeTypes: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export declare const IMAGE_UPLOAD_ALLOW_LIST: UploadAllowList;
|
|
7
|
+
export declare const SCRIPTABLE_UPLOAD_MIME_TYPES: readonly string[];
|
|
8
|
+
export declare const SCRIPTABLE_UPLOAD_EXTENSIONS: readonly string[];
|
|
9
|
+
export interface MulterFileFilterOptions {
|
|
10
|
+
allowScriptableTypes?: boolean;
|
|
11
|
+
}
|
|
2
12
|
export default class FileHelper {
|
|
3
13
|
static multerRandomFileName(numberOfDigits?: number): (req: any, file: any, cb: any) => void;
|
|
4
|
-
static multerFileFilter(
|
|
14
|
+
static multerFileFilter(accept?: RegExp | UploadAllowList, options?: MulterFileFilterOptions): (req: any, file: any, cb: any) => any;
|
|
5
15
|
static multerOptionsForImageUpload(options: {
|
|
16
|
+
allowList?: UploadAllowList;
|
|
6
17
|
destination?: string;
|
|
7
18
|
fileSize?: number;
|
|
8
19
|
fileTypeRegex?: RegExp;
|
|
9
20
|
}): MulterOptions;
|
|
10
21
|
}
|
|
11
|
-
export declare function multerFileFilter(
|
|
22
|
+
export declare function multerFileFilter(accept?: RegExp | UploadAllowList, options?: MulterFileFilterOptions): (req: any, file: any, cb: any) => any;
|
|
12
23
|
export declare function multerOptionsForImageUpload(options: {
|
|
24
|
+
allowList?: UploadAllowList;
|
|
13
25
|
destination?: string;
|
|
14
26
|
fileSize?: number;
|
|
15
27
|
fileTypeRegex?: RegExp;
|
|
@@ -1,40 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCRIPTABLE_UPLOAD_EXTENSIONS = exports.SCRIPTABLE_UPLOAD_MIME_TYPES = exports.IMAGE_UPLOAD_ALLOW_LIST = void 0;
|
|
3
4
|
exports.multerFileFilter = multerFileFilter;
|
|
4
5
|
exports.multerOptionsForImageUpload = multerOptionsForImageUpload;
|
|
5
6
|
exports.multerRandomFileName = multerRandomFileName;
|
|
6
7
|
const multer_1 = require("multer");
|
|
7
8
|
const path_1 = require("path");
|
|
9
|
+
exports.IMAGE_UPLOAD_ALLOW_LIST = {
|
|
10
|
+
extensions: ['.jpeg', '.jpg', '.png'],
|
|
11
|
+
mimeTypes: ['image/jpeg', 'image/png'],
|
|
12
|
+
};
|
|
13
|
+
exports.SCRIPTABLE_UPLOAD_MIME_TYPES = [
|
|
14
|
+
'application/javascript',
|
|
15
|
+
'application/xhtml+xml',
|
|
16
|
+
'application/xml',
|
|
17
|
+
'image/svg+xml',
|
|
18
|
+
'text/html',
|
|
19
|
+
'text/javascript',
|
|
20
|
+
'text/xml',
|
|
21
|
+
];
|
|
22
|
+
exports.SCRIPTABLE_UPLOAD_EXTENSIONS = [
|
|
23
|
+
'.htm',
|
|
24
|
+
'.html',
|
|
25
|
+
'.js',
|
|
26
|
+
'.mjs',
|
|
27
|
+
'.svg',
|
|
28
|
+
'.xhtml',
|
|
29
|
+
'.xml',
|
|
30
|
+
];
|
|
8
31
|
class FileHelper {
|
|
9
32
|
static multerRandomFileName(numberOfDigits = 32) {
|
|
10
33
|
return multerRandomFileName(numberOfDigits);
|
|
11
34
|
}
|
|
12
|
-
static multerFileFilter(
|
|
13
|
-
return multerFileFilter(
|
|
35
|
+
static multerFileFilter(accept = exports.IMAGE_UPLOAD_ALLOW_LIST, options) {
|
|
36
|
+
return multerFileFilter(accept, options);
|
|
14
37
|
}
|
|
15
38
|
static multerOptionsForImageUpload(options) {
|
|
16
39
|
return multerOptionsForImageUpload(options);
|
|
17
40
|
}
|
|
18
41
|
}
|
|
19
42
|
exports.default = FileHelper;
|
|
20
|
-
function
|
|
43
|
+
function normalizeMimeType(value) {
|
|
44
|
+
return String(value || '')
|
|
45
|
+
.split(';')[0]
|
|
46
|
+
.trim()
|
|
47
|
+
.toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
function multerFileFilter(accept = exports.IMAGE_UPLOAD_ALLOW_LIST, options) {
|
|
21
50
|
return (req, file, cb) => {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
51
|
+
const mimeType = normalizeMimeType(file?.mimetype);
|
|
52
|
+
const extension = (0, path_1.extname)(String(file?.originalname || '')).toLowerCase();
|
|
53
|
+
if (!options?.allowScriptableTypes &&
|
|
54
|
+
(exports.SCRIPTABLE_UPLOAD_MIME_TYPES.includes(mimeType) || exports.SCRIPTABLE_UPLOAD_EXTENSIONS.includes(extension))) {
|
|
55
|
+
return cb(new Error(`File upload rejected: ${mimeType || 'unknown type'} may execute as script`));
|
|
56
|
+
}
|
|
57
|
+
const accepted = accept instanceof RegExp
|
|
58
|
+
? accept.test(mimeType) && accept.test(extension)
|
|
59
|
+
: accept.mimeTypes.includes(mimeType) && accept.extensions.includes(extension);
|
|
60
|
+
if (accepted) {
|
|
25
61
|
return cb(null, true);
|
|
26
62
|
}
|
|
27
|
-
cb(`
|
|
63
|
+
cb(new Error(`File upload only supports the following filetypes - ${describeAccept(accept)}`));
|
|
28
64
|
};
|
|
29
65
|
}
|
|
66
|
+
function describeAccept(accept) {
|
|
67
|
+
return accept instanceof RegExp ? String(accept) : accept.extensions.join(', ');
|
|
68
|
+
}
|
|
30
69
|
function multerOptionsForImageUpload(options) {
|
|
31
70
|
const config = {
|
|
32
71
|
fileSize: 1024 * 1024,
|
|
33
|
-
fileTypeRegex: /jpeg|jpg|png/,
|
|
34
72
|
...options,
|
|
35
73
|
};
|
|
74
|
+
const accept = config.fileTypeRegex ?? config.allowList ?? exports.IMAGE_UPLOAD_ALLOW_LIST;
|
|
36
75
|
return {
|
|
37
|
-
fileFilter:
|
|
76
|
+
fileFilter: multerFileFilter(accept),
|
|
38
77
|
limits: {
|
|
39
78
|
fileSize: config.fileSize ? config.fileSize : undefined,
|
|
40
79
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/file.helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/file.helper.ts"],"names":[],"mappings":";;;AAqJA,4CAyBC;AAcD,kEAsCC;AAMD,oDAYC;AAnPD,mCAAqC;AACrC,+BAA+B;AA4BlB,QAAA,uBAAuB,GAAoB;IACtD,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,M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C,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACxD;QAID,OAAO,EAAE,IAAA,oBAAW,EAAC;YAInB,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;YAGhE,QAAQ,EAAE,oBAAoB,EAAE;SACjC,CAAC;KACH,CAAC;AACJ,CAAC;AAMD,SAAgB,oBAAoB,CAAC,cAAc,GAAG,EAAE;IACtD,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;QAEvB,MAAM,UAAU,GAAG,KAAK,CAAC,cAAc,CAAC;aACrC,IAAI,CAAC,IAAI,CAAC;aACV,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACtD,IAAI,CAAC,EAAE,CAAC,CAAC;QAIZ,EAAE,CAAC,IAAI,EAAE,GAAG,UAAU,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -140,6 +140,7 @@ export interface IAiDefaultConnection {
|
|
|
140
140
|
apiKeyEnv?: string;
|
|
141
141
|
baseUrl: string;
|
|
142
142
|
capabilities?: string[];
|
|
143
|
+
contextWindow?: number;
|
|
143
144
|
defaultMaxTokens?: number;
|
|
144
145
|
defaultTemperature?: number;
|
|
145
146
|
description?: string;
|
|
@@ -169,6 +170,7 @@ export interface IAi {
|
|
|
169
170
|
maxTokens?: number;
|
|
170
171
|
};
|
|
171
172
|
};
|
|
173
|
+
capabilityDriftCheck?: boolean;
|
|
172
174
|
confirmation?: {
|
|
173
175
|
mutating?: {
|
|
174
176
|
default?: boolean;
|
|
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CoreAiConnectionInput = void 0;
|
|
13
13
|
const graphql_1 = require("@nestjs/graphql");
|
|
14
|
+
const class_validator_1 = require("class-validator");
|
|
14
15
|
const restricted_decorator_1 = require("../../../common/decorators/restricted.decorator");
|
|
15
16
|
const unified_field_decorator_1 = require("../../../common/decorators/unified-field.decorator");
|
|
16
17
|
const role_enum_1 = require("../../../common/enums/role.enum");
|
|
@@ -87,6 +88,7 @@ __decorate([
|
|
|
87
88
|
isOptional: true,
|
|
88
89
|
roles: role_enum_1.RoleEnum.ADMIN,
|
|
89
90
|
type: () => Number,
|
|
91
|
+
validator: (options) => [(0, class_validator_1.IsInt)(options), (0, class_validator_1.Min)(1, options)],
|
|
90
92
|
}),
|
|
91
93
|
__metadata("design:type", Number)
|
|
92
94
|
], CoreAiConnectionInput.prototype, "contextWindow", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-ai-connection.input.js","sourceRoot":"","sources":["../../../../../src/core/modules/ai/inputs/core-ai-connection.input.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA4C;
|
|
1
|
+
{"version":3,"file":"core-ai-connection.input.js","sourceRoot":"","sources":["../../../../../src/core/modules/ai/inputs/core-ai-connection.input.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA4C;AAC5C,qDAA6C;AAE7C,0FAA6E;AAC7E,gGAAkF;AAClF,+DAA2D;AAUpD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAUhC,MAAM,GAAY,SAAS,CAAC;IAU5B,SAAS,GAAY,SAAS,CAAC;IAU/B,OAAO,GAAY,SAAS,CAAC;IAY7B,YAAY,GAAc,SAAS,CAAC;IAWpC,gBAAgB,GAAY,SAAS,CAAC;IAStC,aAAa,GAAY,SAAS,CAAC;IAWnC,kBAAkB,GAAY,SAAS,CAAC;IASxC,oBAAoB,GAAY,SAAS,CAAC;IAQ1C,oBAAoB,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AAQ,CAAC,KAAK;QACrB,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO;KACpB,CAAC;;kEACwC;AAW1C;IANC,IAAA,sCAAY,EAAC;QACZ,WAAW,EAAE,iDAAiD;QAC9D,UAAU,EAAE,IAAI;QAChB,KAAK,EAAE,oBAAQ,CAAC,KAAK;QACrB,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO;KACpB,CAAC;;6DACmC;AAYrC;IAPC,IAAA,sCAAY,EAAC;QACZ,WAAW,EAAE,kEAAkE;QAC/E,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,IAAI;QAChB,KAAK,EAAE,oBAAQ,CAAC,KAAK;QACrB,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM;KACnB,CAAC;;wDAC+B;gCA5NtB,qBAAqB;IAFjC,IAAA,mBAAS,EAAC,EAAE,WAAW,EAAE,kCAAkC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAChF,IAAA,iCAAU,EAAC,oBAAQ,CAAC,KAAK,CAAC;GACd,qBAAqB,CA6NjC"}
|
|
@@ -22,6 +22,7 @@ export declare class CoreAiConnectionService extends CrudService<CoreAiConnectio
|
|
|
22
22
|
onModuleInit(): Promise<void>;
|
|
23
23
|
protected seedDefaultConnection(): Promise<void>;
|
|
24
24
|
protected assertStoredKeysDecryptable(): Promise<void>;
|
|
25
|
+
protected warnOnCapabilityDrift(): Promise<void>;
|
|
25
26
|
create(input: CoreAiConnectionCreateInput, serviceOptions?: ServiceOptions): Promise<CoreAiConnection>;
|
|
26
27
|
update(id: string, input: CoreAiConnectionInput, serviceOptions?: ServiceOptions): Promise<CoreAiConnection>;
|
|
27
28
|
delete(id: string, serviceOptions?: ServiceOptions): Promise<CoreAiConnection>;
|
|
@@ -45,6 +45,7 @@ let CoreAiConnectionService = CoreAiConnectionService_1 = class CoreAiConnection
|
|
|
45
45
|
async onModuleInit() {
|
|
46
46
|
await this.seedDefaultConnection();
|
|
47
47
|
await this.assertStoredKeysDecryptable();
|
|
48
|
+
void this.warnOnCapabilityDrift();
|
|
48
49
|
}
|
|
49
50
|
async seedDefaultConnection() {
|
|
50
51
|
const seed = config_service_1.ConfigService.get('ai.defaultConnection');
|
|
@@ -94,6 +95,73 @@ let CoreAiConnectionService = CoreAiConnectionService_1 = class CoreAiConnection
|
|
|
94
95
|
this.logger.warn(`AI key decryptability self-check skipped: ${err.message}`);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
98
|
+
async warnOnCapabilityDrift() {
|
|
99
|
+
if (!config_service_1.ConfigService.get('ai.capabilityDriftCheck')) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!this.providerFactory || ['ci', 'e2e'].includes(process.env.NODE_ENV ?? '')) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const docs = (await this.mainDbModel
|
|
107
|
+
.find({ enabled: { $ne: false } })
|
|
108
|
+
.lean()
|
|
109
|
+
.exec());
|
|
110
|
+
for (const doc of docs) {
|
|
111
|
+
if (typeof doc.supportsNativeTools !== 'boolean' && typeof doc.supportsJsonResponse !== 'boolean') {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
let provider;
|
|
115
|
+
try {
|
|
116
|
+
const probeConnection = {
|
|
117
|
+
apiKey: this.resolveApiKeyFromDoc(doc) ?? '',
|
|
118
|
+
baseUrl: doc.baseUrl,
|
|
119
|
+
contextWindow: doc.contextWindow,
|
|
120
|
+
defaultMaxTokens: doc.defaultMaxTokens,
|
|
121
|
+
defaultTemperature: doc.defaultTemperature,
|
|
122
|
+
defaultUserMaxPeriod: doc.defaultUserMaxPeriod,
|
|
123
|
+
defaultUserMaxTokens: doc.defaultUserMaxTokens,
|
|
124
|
+
id: String(doc._id),
|
|
125
|
+
model: doc.model,
|
|
126
|
+
name: doc.name,
|
|
127
|
+
providerType: doc.providerType || 'openai-compatible',
|
|
128
|
+
supportsJsonResponse: undefined,
|
|
129
|
+
supportsNativeTools: undefined,
|
|
130
|
+
};
|
|
131
|
+
provider = this.providerFactory.create(probeConnection);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (typeof provider.detectCapabilities !== 'function') {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const detected = await provider.detectCapabilities().catch(() => undefined);
|
|
140
|
+
if (!detected) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const drift = [];
|
|
144
|
+
if (typeof doc.supportsNativeTools === 'boolean' &&
|
|
145
|
+
typeof detected.nativeTools === 'boolean' &&
|
|
146
|
+
doc.supportsNativeTools !== detected.nativeTools) {
|
|
147
|
+
drift.push(`supportsNativeTools declared ${doc.supportsNativeTools} but the endpoint reports ${detected.nativeTools}`);
|
|
148
|
+
}
|
|
149
|
+
if (typeof doc.supportsJsonResponse === 'boolean' &&
|
|
150
|
+
typeof detected.jsonResponse === 'boolean' &&
|
|
151
|
+
doc.supportsJsonResponse !== detected.jsonResponse) {
|
|
152
|
+
drift.push(`supportsJsonResponse declared ${doc.supportsJsonResponse} but the endpoint reports ${detected.jsonResponse}`);
|
|
153
|
+
}
|
|
154
|
+
if (drift.length) {
|
|
155
|
+
this.logger.warn(`AI connection "${doc.name || String(doc._id)}" capability drift: ${drift.join('; ')}. ` +
|
|
156
|
+
`The declared value is authoritative and was NOT changed — correct it in the admin UI, or clear it to ` +
|
|
157
|
+
`re-enable auto-detection, so the assistant uses the endpoint's real capabilities.`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
this.logger.warn(`AI capability drift check skipped: ${err.message}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
97
165
|
async create(input, serviceOptions) {
|
|
98
166
|
const { apiKey, ...rest } = input;
|
|
99
167
|
let created = await super.create(rest, serviceOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-ai-connection.service.js","sourceRoot":"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AI,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;iBAC1F,IAAI,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAMS,oBAAoB,CAAC,GAA4D;QACzF,IAAI,GAAG,EAAE,eAAe,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,GAAG,EAAE,SAAS,EAAE,CAAC;YACnB,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAKS,KAAK,CAAC,kBAAkB,CAAC,EAAU;QAC3C,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACjG,CAAC;CACF,CAAA;AA/UY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;IASR,WAAA,IAAA,sBAAW,EAAC,uCAAmB,CAAC,CAAA;IAChC,WAAA,IAAA,eAAM,EAAC,uCAAmB,CAAC,CAAA;IAG3B,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAEV,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCAPyB,mCAAe;QACwB,gBAAK,UAI7B,yEAAiC;QAEnC,yCAAkB;GAd1D,uBAAuB,CA+UnC"}
|
|
1
|
+
{"version":3,"file":"core-ai-connection.service.js","sourceRoot":"","sources":["../../../../../src/core/modules/ai/services/core-ai-connection.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,+CAA+C;AAC/C,uCAAiC;AAGjC,wEAAoE;AACpE,4EAAw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
|
|
1
|
-
import { Response } from 'express';
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import type { Readable } from 'stream';
|
|
2
3
|
import { CoreFileService } from './core-file.service';
|
|
4
|
+
export declare function pipeFileToResponse(stream: Readable, res: Response): Response;
|
|
3
5
|
export declare abstract class CoreFileController {
|
|
4
6
|
protected fileService: CoreFileService;
|
|
5
7
|
protected constructor(fileService: CoreFileService);
|
|
8
|
+
protected pipeFileToResponse(stream: Readable, res: Response): Response;
|
|
6
9
|
getFileById(id: string, res: Response): Promise<Response<any, Record<string, any>>>;
|
|
7
10
|
getFile(filename: string, res: Response): Promise<Response<any, Record<string, any>>>;
|
|
8
11
|
}
|
|
@@ -13,40 +13,73 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CoreFileController = void 0;
|
|
16
|
+
exports.pipeFileToResponse = pipeFileToResponse;
|
|
16
17
|
const common_1 = require("@nestjs/common");
|
|
17
18
|
const roles_decorator_1 = require("../../common/decorators/roles.decorator");
|
|
18
19
|
const role_enum_1 = require("../../common/enums/role.enum");
|
|
20
|
+
const error_codes_1 = require("../error-code/error-codes");
|
|
19
21
|
const core_file_service_1 = require("./core-file.service");
|
|
22
|
+
const fileStreamLogger = new common_1.Logger('CoreFileController');
|
|
23
|
+
const FILE_DELIVERY_HEADERS = ['Cache-Control', 'Content-Disposition', 'Content-Type', 'ETag'];
|
|
24
|
+
function pipeFileToResponse(stream, res) {
|
|
25
|
+
res.on('close', () => {
|
|
26
|
+
if (!stream.destroyed) {
|
|
27
|
+
stream.destroy();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
stream.on('error', (err) => {
|
|
31
|
+
fileStreamLogger.error(`GridFS download failed: ${err.message}`, err.stack);
|
|
32
|
+
if (res.headersSent) {
|
|
33
|
+
res.destroy();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const header of FILE_DELIVERY_HEADERS) {
|
|
37
|
+
res.removeHeader(header);
|
|
38
|
+
}
|
|
39
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
40
|
+
res.status(404).json({ error: 'Not Found', message: error_codes_1.ErrorCode.FILE_NOT_FOUND, statusCode: 404 });
|
|
41
|
+
});
|
|
42
|
+
return stream.pipe(res);
|
|
43
|
+
}
|
|
20
44
|
let CoreFileController = class CoreFileController {
|
|
21
45
|
fileService;
|
|
22
46
|
constructor(fileService) {
|
|
23
47
|
this.fileService = fileService;
|
|
24
48
|
}
|
|
49
|
+
pipeFileToResponse(stream, res) {
|
|
50
|
+
return pipeFileToResponse(stream, res);
|
|
51
|
+
}
|
|
25
52
|
async getFileById(id, res) {
|
|
26
53
|
if (!id) {
|
|
27
|
-
throw new common_1.BadRequestException(
|
|
54
|
+
throw new common_1.BadRequestException(error_codes_1.ErrorCode.REQUIRED_FIELD_MISSING);
|
|
28
55
|
}
|
|
29
56
|
const file = await this.fileService.getFileInfo(id);
|
|
30
57
|
if (!file) {
|
|
31
|
-
throw new common_1.NotFoundException(
|
|
58
|
+
throw new common_1.NotFoundException(error_codes_1.ErrorCode.FILE_NOT_FOUND);
|
|
32
59
|
}
|
|
33
60
|
const filestream = await this.fileService.getFileStream(id);
|
|
61
|
+
if (!filestream) {
|
|
62
|
+
throw new common_1.NotFoundException(error_codes_1.ErrorCode.FILE_NOT_FOUND);
|
|
63
|
+
}
|
|
34
64
|
res.header('Content-Type', file.contentType || 'application/octet-stream');
|
|
35
65
|
res.header('Content-Disposition', `attachment; filename=${file.filename}`);
|
|
36
|
-
return
|
|
66
|
+
return this.pipeFileToResponse(filestream, res);
|
|
37
67
|
}
|
|
38
68
|
async getFile(filename, res) {
|
|
39
69
|
if (!filename) {
|
|
40
|
-
throw new common_1.BadRequestException(
|
|
70
|
+
throw new common_1.BadRequestException(error_codes_1.ErrorCode.REQUIRED_FIELD_MISSING);
|
|
41
71
|
}
|
|
42
72
|
const file = await this.fileService.getFileInfoByName(filename);
|
|
43
73
|
if (!file) {
|
|
44
|
-
throw new common_1.NotFoundException(
|
|
74
|
+
throw new common_1.NotFoundException(error_codes_1.ErrorCode.FILE_NOT_FOUND);
|
|
45
75
|
}
|
|
46
76
|
const filestream = await this.fileService.getFileStream(file.id);
|
|
77
|
+
if (!filestream) {
|
|
78
|
+
throw new common_1.NotFoundException(error_codes_1.ErrorCode.FILE_NOT_FOUND);
|
|
79
|
+
}
|
|
47
80
|
res.header('Content-Type', file.contentType || 'application/octet-stream');
|
|
48
81
|
res.header('Content-Disposition', `attachment; filename=${file.filename}`);
|
|
49
|
-
return
|
|
82
|
+
return this.pipeFileToResponse(filestream, res);
|
|
50
83
|
}
|
|
51
84
|
};
|
|
52
85
|
exports.CoreFileController = CoreFileController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-file.controller.js","sourceRoot":"","sources":["../../../../src/core/modules/file/core-file.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"core-file.controller.js","sourceRoot":"","sources":["../../../../src/core/modules/file/core-file.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAiDA,gDA4BC;AA7ED,2CAA6G;AAI7G,6EAAgE;AAChE,4DAAwD;AACxD,2DAAsD;AACtD,2DAAsD;AAEtD,MAAM,gBAAgB,GAAG,IAAI,eAAM,CAAC,oBAAoB,CAAC,CAAC;AAe1D,MAAM,qBAAqB,GAAG,CAAC,eAAe,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;AAyB/F,SAAgB,kBAAkB,CAAC,MAAgB,EAAE,GAAa;IAChE,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACnB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,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QAC3E,OAAO,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC;CACF,CAAA;AAvEqB,gDAAkB;AA0BhC;IAFL,IAAA,YAAG,EAAC,QAAQ,CAAC;IACb,IAAA,uBAAK,EAAC,oBAAQ,CAAC,UAAU,CAAC;IACR,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,YAAG,GAAE,CAAA;;;;qDAkBhD;AAUK;IAFL,IAAA,YAAG,EAAC,WAAW,CAAC;IAChB,IAAA,uBAAK,EAAC,oBAAQ,CAAC,UAAU,CAAC;IACZ,WAAA,IAAA,cAAK,EAAC,UAAU,CAAC,CAAA;IAAoB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;iDAgBxD;6BAtEmB,kBAAkB;IAFvC,IAAA,mBAAU,EAAC,OAAO,CAAC;IACnB,IAAA,uBAAK,EAAC,oBAAQ,CAAC,KAAK,CAAC;qCAKyB,mCAAe;GAJxC,kBAAkB,CAuEvC"}
|
|
@@ -12,4 +12,6 @@ declare function parseArgs(): {
|
|
|
12
12
|
name?: string;
|
|
13
13
|
options: CliOptions;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
declare const flushAndExit: (code: number) => Promise<void>;
|
|
16
|
+
declare const runCli: () => Promise<void>;
|
|
17
|
+
export { flushAndExit, main, parseArgs, runCli };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.runCli = exports.flushAndExit = void 0;
|
|
4
5
|
exports.main = main;
|
|
5
6
|
exports.parseArgs = parseArgs;
|
|
6
7
|
const fs = require("fs");
|
|
@@ -227,10 +228,34 @@ Environment Variables:
|
|
|
227
228
|
NSC__MIGRATE__STRICT 1|true|yes → fail on a missing recorded migration file (default: tolerate)
|
|
228
229
|
`);
|
|
229
230
|
}
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
const flushAndExit = async (code) => {
|
|
232
|
+
process.exitCode = code;
|
|
233
|
+
const guard = setTimeout(() => process.exit(code), 5000);
|
|
234
|
+
guard.unref();
|
|
235
|
+
await Promise.all([process.stdout, process.stderr].map((stream) => new Promise((resolve) => {
|
|
236
|
+
if (!stream.writableLength) {
|
|
237
|
+
resolve();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
stream.write('', () => resolve());
|
|
241
|
+
})));
|
|
242
|
+
clearTimeout(guard);
|
|
243
|
+
process.exit(code);
|
|
244
|
+
};
|
|
245
|
+
exports.flushAndExit = flushAndExit;
|
|
246
|
+
const runCli = async () => {
|
|
247
|
+
try {
|
|
248
|
+
await main();
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
232
251
|
console.error('Fatal error:', error);
|
|
233
|
-
|
|
234
|
-
|
|
252
|
+
await flushAndExit(1);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
await flushAndExit(0);
|
|
256
|
+
};
|
|
257
|
+
exports.runCli = runCli;
|
|
258
|
+
if (require.main === module) {
|
|
259
|
+
void runCli();
|
|
235
260
|
}
|
|
236
261
|
//# sourceMappingURL=migrate-cli.js.map
|