@directus/api 13.1.1 → 14.0.0
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/dist/__utils__/snapshots.js +9 -0
- package/dist/app.js +6 -4
- package/dist/auth/drivers/ldap.js +3 -2
- package/dist/auth/drivers/local.js +1 -1
- package/dist/auth/drivers/oauth2.js +1 -1
- package/dist/auth/drivers/openid.js +1 -1
- package/dist/auth/drivers/saml.js +1 -1
- package/dist/auth.js +1 -1
- package/dist/cli/index.js +7 -4
- package/dist/controllers/activity.js +1 -1
- package/dist/controllers/assets.js +2 -2
- package/dist/controllers/auth.js +1 -1
- package/dist/controllers/collections.js +1 -1
- package/dist/controllers/dashboards.js +1 -1
- package/dist/controllers/extensions.js +29 -16
- package/dist/controllers/fields.js +1 -1
- package/dist/controllers/files.js +1 -1
- package/dist/controllers/flows.js +1 -1
- package/dist/controllers/folders.js +1 -1
- package/dist/controllers/items.js +1 -1
- package/dist/controllers/not-found.js +1 -1
- package/dist/controllers/notifications.js +1 -1
- package/dist/controllers/operations.js +1 -1
- package/dist/controllers/panels.js +1 -1
- package/dist/controllers/permissions.js +1 -1
- package/dist/controllers/presets.js +1 -1
- package/dist/controllers/relations.js +1 -1
- package/dist/controllers/roles.js +1 -1
- package/dist/controllers/schema.js +1 -1
- package/dist/controllers/server.js +1 -1
- package/dist/controllers/settings.js +1 -1
- package/dist/controllers/shares.js +1 -1
- package/dist/controllers/translations.js +1 -1
- package/dist/controllers/users.js +1 -1
- package/dist/controllers/utils.js +37 -18
- package/dist/controllers/versions.d.ts +2 -0
- package/dist/controllers/versions.js +188 -0
- package/dist/controllers/webhooks.js +1 -1
- package/dist/database/errors/dialects/mssql.js +1 -1
- package/dist/database/errors/dialects/mysql.js +1 -1
- package/dist/database/errors/dialects/oracle.js +1 -1
- package/dist/database/errors/dialects/postgres.js +1 -1
- package/dist/database/errors/dialects/sqlite.js +1 -1
- package/dist/database/helpers/schema/dialects/mysql.js +1 -1
- package/dist/database/helpers/sequence/dialects/postgres.d.ts +5 -2
- package/dist/database/helpers/sequence/dialects/postgres.js +6 -3
- package/dist/database/migrations/20230823A-add-content-versioning.d.ts +3 -0
- package/dist/database/migrations/20230823A-add-content-versioning.js +36 -0
- package/dist/database/migrations/20230927A-themes.d.ts +3 -0
- package/dist/database/migrations/20230927A-themes.js +49 -0
- package/dist/database/migrations/20231009A-update-csv-fields-to-text.d.ts +3 -0
- package/dist/database/migrations/20231009A-update-csv-fields-to-text.js +44 -0
- package/dist/database/migrations/20231009B-update-panel-options.d.ts +3 -0
- package/dist/database/migrations/20231009B-update-panel-options.js +77 -0
- package/dist/database/migrations/20231010A-add-extensions.d.ts +3 -0
- package/dist/database/migrations/20231010A-add-extensions.js +9 -0
- package/dist/database/run-ast.js +2 -2
- package/dist/database/seeds/run.js +1 -1
- package/dist/database/system-data/collections/collections.yaml +6 -0
- package/dist/database/system-data/fields/activity.yaml +4 -4
- package/dist/database/system-data/fields/collections.yaml +19 -0
- package/dist/database/system-data/fields/extensions.yaml +10 -0
- package/dist/database/system-data/fields/revisions.yaml +3 -0
- package/dist/database/system-data/fields/settings.yaml +73 -17
- package/dist/database/system-data/fields/users.yaml +48 -12
- package/dist/database/system-data/fields/versions.yaml +38 -0
- package/dist/database/system-data/fields/webhooks.yaml +9 -9
- package/dist/database/system-data/relations/relations.yaml +88 -20
- package/dist/env.js +4 -0
- package/dist/extensions/index.d.ts +2 -0
- package/dist/extensions/index.js +9 -0
- package/dist/extensions/lib/get-extensions-settings.d.ts +7 -0
- package/dist/extensions/lib/get-extensions-settings.js +39 -0
- package/dist/extensions/lib/get-extensions.d.ts +1 -0
- package/dist/extensions/lib/get-extensions.js +11 -0
- package/dist/extensions/lib/get-shared-deps-mapping.d.ts +1 -0
- package/dist/extensions/lib/get-shared-deps-mapping.js +26 -0
- package/dist/extensions/lib/sandbox/generate-api-extensions-sandbox-entrypoint.d.ts +31 -0
- package/dist/extensions/lib/sandbox/generate-api-extensions-sandbox-entrypoint.js +80 -0
- package/dist/extensions/lib/sandbox/generate-host-function-reference.d.ts +11 -0
- package/dist/extensions/lib/sandbox/generate-host-function-reference.js +28 -0
- package/dist/extensions/lib/sandbox/register/action.d.ts +6 -0
- package/dist/extensions/lib/sandbox/register/action.js +18 -0
- package/dist/extensions/lib/sandbox/register/call-reference.d.ts +5 -0
- package/dist/extensions/lib/sandbox/register/call-reference.js +20 -0
- package/dist/extensions/lib/sandbox/register/filter.d.ts +6 -0
- package/dist/extensions/lib/sandbox/register/filter.js +21 -0
- package/dist/extensions/lib/sandbox/register/index.d.ts +5 -0
- package/dist/extensions/lib/sandbox/register/index.js +5 -0
- package/dist/extensions/lib/sandbox/register/operation.d.ts +6 -0
- package/dist/extensions/lib/sandbox/register/operation.js +19 -0
- package/dist/extensions/lib/sandbox/register/route.d.ts +17 -0
- package/dist/extensions/lib/sandbox/register/route.js +44 -0
- package/dist/extensions/lib/sandbox/sdk/generators/index.d.ts +3 -0
- package/dist/extensions/lib/sandbox/sdk/generators/index.js +3 -0
- package/dist/extensions/lib/sandbox/sdk/generators/log.d.ts +3 -0
- package/dist/extensions/lib/sandbox/sdk/generators/log.js +11 -0
- package/dist/extensions/lib/sandbox/sdk/generators/request.d.ts +12 -0
- package/dist/extensions/lib/sandbox/sdk/generators/request.js +49 -0
- package/dist/extensions/lib/sandbox/sdk/generators/sleep.d.ts +3 -0
- package/dist/extensions/lib/sandbox/sdk/generators/sleep.js +11 -0
- package/dist/extensions/lib/sandbox/sdk/index.d.ts +2 -0
- package/dist/extensions/lib/sandbox/sdk/index.js +2 -0
- package/dist/extensions/lib/sandbox/sdk/instantiate.d.ts +11 -0
- package/dist/extensions/lib/sandbox/sdk/instantiate.js +28 -0
- package/dist/extensions/lib/sandbox/sdk/sdk.d.ts +20 -0
- package/dist/extensions/lib/sandbox/sdk/sdk.js +11 -0
- package/dist/extensions/lib/sandbox/sdk/utils/index.d.ts +1 -0
- package/dist/extensions/lib/sandbox/sdk/utils/index.js +1 -0
- package/dist/extensions/lib/sandbox/sdk/utils/wrap.d.ts +11 -0
- package/dist/extensions/lib/sandbox/sdk/utils/wrap.js +17 -0
- package/dist/extensions/lib/wrap-embeds.d.ts +4 -0
- package/dist/extensions/lib/wrap-embeds.js +8 -0
- package/dist/extensions/manager.d.ts +158 -0
- package/dist/extensions/manager.js +604 -0
- package/dist/extensions/types.d.ts +19 -0
- package/dist/flows.d.ts +2 -2
- package/dist/flows.js +7 -7
- package/dist/middleware/check-ip.js +1 -1
- package/dist/middleware/collection-exists.js +1 -1
- package/dist/middleware/error-handler.js +1 -1
- package/dist/middleware/graphql.js +1 -1
- package/dist/middleware/rate-limiter-global.js +1 -1
- package/dist/middleware/rate-limiter-ip.js +1 -1
- package/dist/middleware/respond.js +13 -1
- package/dist/middleware/validate-batch.js +1 -1
- package/dist/operations/condition/index.d.ts +1 -1
- package/dist/operations/condition/index.js +2 -1
- package/dist/operations/exec/index.d.ts +1 -1
- package/dist/operations/exec/index.js +1 -1
- package/dist/operations/item-create/index.d.ts +1 -1
- package/dist/operations/item-create/index.js +2 -1
- package/dist/operations/item-delete/index.d.ts +1 -1
- package/dist/operations/item-delete/index.js +2 -1
- package/dist/operations/item-read/index.d.ts +1 -1
- package/dist/operations/item-read/index.js +2 -1
- package/dist/operations/item-update/index.d.ts +1 -1
- package/dist/operations/item-update/index.js +2 -1
- package/dist/operations/json-web-token/index.d.ts +1 -1
- package/dist/operations/json-web-token/index.js +2 -1
- package/dist/operations/log/index.d.ts +1 -1
- package/dist/operations/log/index.js +2 -1
- package/dist/operations/mail/index.d.ts +1 -1
- package/dist/operations/mail/index.js +1 -1
- package/dist/operations/notification/index.d.ts +1 -1
- package/dist/operations/notification/index.js +2 -1
- package/dist/operations/request/index.d.ts +1 -1
- package/dist/operations/request/index.js +3 -2
- package/dist/operations/sleep/index.d.ts +1 -1
- package/dist/operations/sleep/index.js +1 -1
- package/dist/operations/transform/index.d.ts +1 -1
- package/dist/operations/transform/index.js +2 -1
- package/dist/operations/trigger/index.d.ts +1 -1
- package/dist/operations/trigger/index.js +2 -1
- package/dist/services/activity.js +1 -1
- package/dist/services/assets.d.ts +1 -1
- package/dist/services/assets.js +3 -3
- package/dist/services/authentication.js +2 -2
- package/dist/services/authorization.js +1 -1
- package/dist/services/collections.js +3 -3
- package/dist/services/extensions.d.ts +31 -0
- package/dist/services/extensions.js +121 -0
- package/dist/services/fields.d.ts +2 -2
- package/dist/services/fields.js +4 -4
- package/dist/services/files.d.ts +4 -1
- package/dist/services/files.js +5 -5
- package/dist/services/graphql/index.d.ts +1 -1
- package/dist/services/graphql/index.js +87 -24
- package/dist/services/graphql/subscription.js +3 -3
- package/dist/services/import-export/import-worker.d.ts +9 -0
- package/dist/services/import-export/import-worker.js +9 -0
- package/dist/services/{import-export.d.ts → import-export/index.d.ts} +2 -2
- package/dist/services/{import-export.js → import-export/index.js} +51 -42
- package/dist/services/index.d.ts +3 -1
- package/dist/services/index.js +3 -1
- package/dist/services/items.js +2 -2
- package/dist/services/mail/index.js +1 -1
- package/dist/services/meta.js +1 -1
- package/dist/services/payload.js +1 -1
- package/dist/services/permissions.d.ts +2 -2
- package/dist/services/permissions.js +1 -1
- package/dist/services/relations.js +1 -1
- package/dist/services/revisions.js +1 -1
- package/dist/services/roles.js +1 -1
- package/dist/services/schema.js +1 -1
- package/dist/services/server.js +3 -1
- package/dist/services/shares.js +1 -1
- package/dist/services/tfa.js +1 -1
- package/dist/services/translations.js +1 -1
- package/dist/services/users.js +4 -2
- package/dist/services/utils.d.ts +1 -0
- package/dist/services/utils.js +8 -2
- package/dist/services/versions.d.ts +21 -0
- package/dist/services/versions.js +232 -0
- package/dist/services/websocket.js +11 -1
- package/dist/types/collection.d.ts +1 -0
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/utils/apply-query.d.ts +1 -1
- package/dist/utils/apply-query.js +31 -3
- package/dist/utils/delete-from-require-cache.d.ts +1 -0
- package/dist/utils/delete-from-require-cache.js +5 -0
- package/dist/utils/get-accountability-for-token.js +1 -1
- package/dist/utils/get-ast-from-query.js +1 -1
- package/dist/utils/get-column-path.js +1 -1
- package/dist/utils/get-column.js +1 -1
- package/dist/utils/get-default-value.d.ts +1 -2
- package/dist/utils/get-permissions.js +1 -1
- package/dist/utils/get-service.js +3 -1
- package/dist/utils/import-file-url.d.ts +5 -0
- package/dist/utils/import-file-url.js +6 -0
- package/dist/utils/job-queue.d.ts +2 -3
- package/dist/utils/jwt.js +1 -1
- package/dist/utils/redact-object.js +9 -3
- package/dist/utils/sanitize-query.js +3 -0
- package/dist/utils/transformations.d.ts +2 -1
- package/dist/utils/validate-diff.js +1 -1
- package/dist/utils/validate-keys.js +1 -1
- package/dist/utils/validate-query.js +2 -1
- package/dist/utils/validate-snapshot.js +1 -1
- package/dist/websocket/controllers/base.js +1 -1
- package/dist/websocket/controllers/index.d.ts +1 -1
- package/dist/websocket/controllers/index.js +0 -7
- package/dist/websocket/handlers/heartbeat.js +6 -1
- package/dist/websocket/handlers/subscribe.js +11 -16
- package/dist/websocket/utils/items.d.ts +4 -14
- package/dist/websocket/utils/items.js +59 -64
- package/dist/worker-pool.d.ts +2 -0
- package/dist/worker-pool.js +11 -0
- package/package.json +34 -31
- package/dist/errors/codes.d.ts +0 -29
- package/dist/errors/codes.js +0 -30
- package/dist/errors/contains-null-values.d.ts +0 -7
- package/dist/errors/contains-null-values.js +0 -4
- package/dist/errors/content-too-large.d.ts +0 -1
- package/dist/errors/content-too-large.js +0 -3
- package/dist/errors/forbidden.d.ts +0 -1
- package/dist/errors/forbidden.js +0 -3
- package/dist/errors/hit-rate-limit.d.ts +0 -6
- package/dist/errors/hit-rate-limit.js +0 -8
- package/dist/errors/illegal-asset-transformation.d.ts +0 -4
- package/dist/errors/illegal-asset-transformation.js +0 -3
- package/dist/errors/index.d.ts +0 -28
- package/dist/errors/index.js +0 -28
- package/dist/errors/invalid-credentials.d.ts +0 -1
- package/dist/errors/invalid-credentials.js +0 -3
- package/dist/errors/invalid-foreign-key.d.ts +0 -6
- package/dist/errors/invalid-foreign-key.js +0 -14
- package/dist/errors/invalid-ip.d.ts +0 -1
- package/dist/errors/invalid-ip.js +0 -3
- package/dist/errors/invalid-otp.d.ts +0 -1
- package/dist/errors/invalid-otp.js +0 -3
- package/dist/errors/invalid-payload.d.ts +0 -5
- package/dist/errors/invalid-payload.js +0 -4
- package/dist/errors/invalid-provider-config.d.ts +0 -5
- package/dist/errors/invalid-provider-config.js +0 -3
- package/dist/errors/invalid-provider.d.ts +0 -1
- package/dist/errors/invalid-provider.js +0 -3
- package/dist/errors/invalid-query.d.ts +0 -5
- package/dist/errors/invalid-query.js +0 -4
- package/dist/errors/invalid-token.d.ts +0 -1
- package/dist/errors/invalid-token.js +0 -3
- package/dist/errors/method-not-allowed.d.ts +0 -6
- package/dist/errors/method-not-allowed.js +0 -6
- package/dist/errors/not-null-violation.d.ts +0 -6
- package/dist/errors/not-null-violation.js +0 -14
- package/dist/errors/range-not-satisfiable.d.ts +0 -7
- package/dist/errors/range-not-satisfiable.js +0 -7
- package/dist/errors/record-not-unique.d.ts +0 -6
- package/dist/errors/record-not-unique.js +0 -14
- package/dist/errors/route-not-found.d.ts +0 -5
- package/dist/errors/route-not-found.js +0 -4
- package/dist/errors/service-unavailable.d.ts +0 -7
- package/dist/errors/service-unavailable.js +0 -4
- package/dist/errors/token-expired.d.ts +0 -1
- package/dist/errors/token-expired.js +0 -3
- package/dist/errors/unexpected-response.d.ts +0 -1
- package/dist/errors/unexpected-response.js +0 -3
- package/dist/errors/unprocessable-content.d.ts +0 -5
- package/dist/errors/unprocessable-content.js +0 -4
- package/dist/errors/unsupported-media-type.d.ts +0 -6
- package/dist/errors/unsupported-media-type.js +0 -4
- package/dist/errors/user-suspended.d.ts +0 -1
- package/dist/errors/user-suspended.js +0 -3
- package/dist/errors/value-out-of-range.d.ts +0 -6
- package/dist/errors/value-out-of-range.js +0 -14
- package/dist/errors/value-too-long.d.ts +0 -6
- package/dist/errors/value-too-long.js +0 -14
- package/dist/extensions.d.ts +0 -51
- package/dist/extensions.js +0 -487
- package/dist/types/files.d.ts +0 -29
- /package/dist/{types/files.js → extensions/types.js} +0 -0
|
@@ -13,6 +13,7 @@ export const snapshotBeforeCreateCollection = {
|
|
|
13
13
|
item_duplication_fields: null,
|
|
14
14
|
note: null,
|
|
15
15
|
singleton: false,
|
|
16
|
+
versioning: false,
|
|
16
17
|
translations: {},
|
|
17
18
|
},
|
|
18
19
|
schema: {
|
|
@@ -86,6 +87,7 @@ export const snapshotCreateCollection = {
|
|
|
86
87
|
item_duplication_fields: null,
|
|
87
88
|
note: null,
|
|
88
89
|
singleton: false,
|
|
90
|
+
versioning: false,
|
|
89
91
|
translations: {},
|
|
90
92
|
},
|
|
91
93
|
schema: {
|
|
@@ -105,6 +107,7 @@ export const snapshotCreateCollection = {
|
|
|
105
107
|
item_duplication_fields: null,
|
|
106
108
|
note: null,
|
|
107
109
|
singleton: false,
|
|
110
|
+
versioning: false,
|
|
108
111
|
translations: {},
|
|
109
112
|
},
|
|
110
113
|
schema: {
|
|
@@ -124,6 +127,7 @@ export const snapshotCreateCollection = {
|
|
|
124
127
|
item_duplication_fields: null,
|
|
125
128
|
note: null,
|
|
126
129
|
singleton: false,
|
|
130
|
+
versioning: false,
|
|
127
131
|
translations: {},
|
|
128
132
|
},
|
|
129
133
|
schema: {
|
|
@@ -287,6 +291,7 @@ export const snapshotCreateCollectionNotNested = {
|
|
|
287
291
|
item_duplication_fields: null,
|
|
288
292
|
note: null,
|
|
289
293
|
singleton: false,
|
|
294
|
+
versioning: false,
|
|
290
295
|
translations: {},
|
|
291
296
|
},
|
|
292
297
|
schema: {
|
|
@@ -306,6 +311,7 @@ export const snapshotCreateCollectionNotNested = {
|
|
|
306
311
|
item_duplication_fields: null,
|
|
307
312
|
note: null,
|
|
308
313
|
singleton: false,
|
|
314
|
+
versioning: false,
|
|
309
315
|
translations: {},
|
|
310
316
|
},
|
|
311
317
|
schema: {
|
|
@@ -424,6 +430,7 @@ export const snapshotBeforeDeleteCollection = {
|
|
|
424
430
|
item_duplication_fields: null,
|
|
425
431
|
note: null,
|
|
426
432
|
singleton: false,
|
|
433
|
+
versioning: false,
|
|
427
434
|
translations: {},
|
|
428
435
|
},
|
|
429
436
|
schema: {
|
|
@@ -443,6 +450,7 @@ export const snapshotBeforeDeleteCollection = {
|
|
|
443
450
|
item_duplication_fields: null,
|
|
444
451
|
note: null,
|
|
445
452
|
singleton: false,
|
|
453
|
+
versioning: false,
|
|
446
454
|
translations: {},
|
|
447
455
|
},
|
|
448
456
|
schema: {
|
|
@@ -462,6 +470,7 @@ export const snapshotBeforeDeleteCollection = {
|
|
|
462
470
|
item_duplication_fields: null,
|
|
463
471
|
note: null,
|
|
464
472
|
singleton: false,
|
|
473
|
+
versioning: false,
|
|
465
474
|
translations: {},
|
|
466
475
|
},
|
|
467
476
|
schema: {
|
package/dist/app.js
CHANGED
|
@@ -35,12 +35,13 @@ import sharesRouter from './controllers/shares.js';
|
|
|
35
35
|
import translationsRouter from './controllers/translations.js';
|
|
36
36
|
import usersRouter from './controllers/users.js';
|
|
37
37
|
import utilsRouter from './controllers/utils.js';
|
|
38
|
+
import versionsRouter from './controllers/versions.js';
|
|
38
39
|
import webhooksRouter from './controllers/webhooks.js';
|
|
39
40
|
import { isInstalled, validateDatabaseConnection, validateDatabaseExtensions, validateMigrations, } from './database/index.js';
|
|
40
41
|
import emitter from './emitter.js';
|
|
41
42
|
import env from './env.js';
|
|
42
|
-
import { InvalidPayloadError, ServiceUnavailableError } from '
|
|
43
|
-
import { getExtensionManager } from './extensions.js';
|
|
43
|
+
import { InvalidPayloadError, ServiceUnavailableError } from '@directus/errors';
|
|
44
|
+
import { getExtensionManager } from './extensions/index.js';
|
|
44
45
|
import { getFlowManager } from './flows.js';
|
|
45
46
|
import logger, { expressLogger } from './logger.js';
|
|
46
47
|
import authenticate from './middleware/authenticate.js';
|
|
@@ -164,8 +165,8 @@ export default async function createApp() {
|
|
|
164
165
|
const html = await readFile(adminPath, 'utf8');
|
|
165
166
|
const htmlWithVars = html
|
|
166
167
|
.replace(/<base \/>/, `<base href="${adminUrl.toString({ rootRelative: true })}/" />`)
|
|
167
|
-
.replace(
|
|
168
|
-
.replace(
|
|
168
|
+
.replace('<!-- directus-embed-head -->', embeds.head)
|
|
169
|
+
.replace('<!-- directus-embed-body -->', embeds.body);
|
|
169
170
|
const sendHtml = (_req, res) => {
|
|
170
171
|
res.setHeader('Cache-Control', 'no-cache');
|
|
171
172
|
res.setHeader('Vary', 'Origin, Cache-Control');
|
|
@@ -222,6 +223,7 @@ export default async function createApp() {
|
|
|
222
223
|
app.use('/shares', sharesRouter);
|
|
223
224
|
app.use('/users', usersRouter);
|
|
224
225
|
app.use('/utils', utilsRouter);
|
|
226
|
+
app.use('/versions', versionsRouter);
|
|
225
227
|
app.use('/webhooks', webhooksRouter);
|
|
226
228
|
// Register custom endpoints
|
|
227
229
|
await emitter.emitInit('routes.custom.before', { app });
|
|
@@ -5,7 +5,7 @@ import ldap from 'ldapjs';
|
|
|
5
5
|
import getDatabase from '../../database/index.js';
|
|
6
6
|
import emitter from '../../emitter.js';
|
|
7
7
|
import env from '../../env.js';
|
|
8
|
-
import { ErrorCode, InvalidCredentialsError, InvalidPayloadError, InvalidProviderError, InvalidProviderConfigError, ServiceUnavailableError, UnexpectedResponseError, } from '
|
|
8
|
+
import { ErrorCode, InvalidCredentialsError, InvalidPayloadError, InvalidProviderError, InvalidProviderConfigError, ServiceUnavailableError, UnexpectedResponseError, } from '@directus/errors';
|
|
9
9
|
import logger from '../../logger.js';
|
|
10
10
|
import { respond } from '../../middleware/respond.js';
|
|
11
11
|
import { AuthenticationService } from '../../services/authentication.js';
|
|
@@ -73,7 +73,8 @@ export class LDAPAuthDriver extends AuthDriver {
|
|
|
73
73
|
});
|
|
74
74
|
res.on('end', (result) => {
|
|
75
75
|
// Handle edge case where authenticated bind user cannot read their own DN
|
|
76
|
-
|
|
76
|
+
// Status `0` is success
|
|
77
|
+
if (result?.status !== 0) {
|
|
77
78
|
logger.warn('[LDAP] Failed to find bind user record');
|
|
78
79
|
reject(new UnexpectedResponseError());
|
|
79
80
|
}
|
|
@@ -4,7 +4,7 @@ import Joi from 'joi';
|
|
|
4
4
|
import { performance } from 'perf_hooks';
|
|
5
5
|
import { COOKIE_OPTIONS } from '../../constants.js';
|
|
6
6
|
import env from '../../env.js';
|
|
7
|
-
import { InvalidCredentialsError, InvalidPayloadError } from '
|
|
7
|
+
import { InvalidCredentialsError, InvalidPayloadError } from '@directus/errors';
|
|
8
8
|
import { respond } from '../../middleware/respond.js';
|
|
9
9
|
import { AuthenticationService } from '../../services/authentication.js';
|
|
10
10
|
import asyncHandler from '../../utils/async-handler.js';
|
|
@@ -8,7 +8,7 @@ import { getAuthProvider } from '../../auth.js';
|
|
|
8
8
|
import getDatabase from '../../database/index.js';
|
|
9
9
|
import emitter from '../../emitter.js';
|
|
10
10
|
import env from '../../env.js';
|
|
11
|
-
import { ErrorCode, InvalidCredentialsError, InvalidProviderError, InvalidProviderConfigError, InvalidTokenError, ServiceUnavailableError, } from '
|
|
11
|
+
import { ErrorCode, InvalidCredentialsError, InvalidProviderError, InvalidProviderConfigError, InvalidTokenError, ServiceUnavailableError, } from '@directus/errors';
|
|
12
12
|
import logger from '../../logger.js';
|
|
13
13
|
import { respond } from '../../middleware/respond.js';
|
|
14
14
|
import { AuthenticationService } from '../../services/authentication.js';
|
|
@@ -8,7 +8,7 @@ import { getAuthProvider } from '../../auth.js';
|
|
|
8
8
|
import getDatabase from '../../database/index.js';
|
|
9
9
|
import emitter from '../../emitter.js';
|
|
10
10
|
import env from '../../env.js';
|
|
11
|
-
import { ErrorCode, InvalidCredentialsError, InvalidProviderError, InvalidProviderConfigError, InvalidTokenError, ServiceUnavailableError, } from '
|
|
11
|
+
import { ErrorCode, InvalidCredentialsError, InvalidProviderError, InvalidProviderConfigError, InvalidTokenError, ServiceUnavailableError, } from '@directus/errors';
|
|
12
12
|
import logger from '../../logger.js';
|
|
13
13
|
import { respond } from '../../middleware/respond.js';
|
|
14
14
|
import { AuthenticationService } from '../../services/authentication.js';
|
|
@@ -7,7 +7,7 @@ import { COOKIE_OPTIONS } from '../../constants.js';
|
|
|
7
7
|
import getDatabase from '../../database/index.js';
|
|
8
8
|
import emitter from '../../emitter.js';
|
|
9
9
|
import env from '../../env.js';
|
|
10
|
-
import { ErrorCode, InvalidCredentialsError, InvalidProviderError } from '
|
|
10
|
+
import { ErrorCode, InvalidCredentialsError, InvalidProviderError } from '@directus/errors';
|
|
11
11
|
import logger from '../../logger.js';
|
|
12
12
|
import { respond } from '../../middleware/respond.js';
|
|
13
13
|
import { AuthenticationService } from '../../services/authentication.js';
|
package/dist/auth.js
CHANGED
|
@@ -3,7 +3,7 @@ import { LDAPAuthDriver, LocalAuthDriver, OAuth2AuthDriver, OpenIDAuthDriver, SA
|
|
|
3
3
|
import { DEFAULT_AUTH_PROVIDER } from './constants.js';
|
|
4
4
|
import getDatabase from './database/index.js';
|
|
5
5
|
import env from './env.js';
|
|
6
|
-
import { InvalidProviderConfigError } from '
|
|
6
|
+
import { InvalidProviderConfigError } from '@directus/errors';
|
|
7
7
|
import logger from './logger.js';
|
|
8
8
|
import { getConfigFromEnv } from './utils/get-config-from-env.js';
|
|
9
9
|
import { getSchema } from './utils/get-schema.js';
|
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Command, Option } from 'commander';
|
|
2
|
+
import { isInstalled } from '../database/index.js';
|
|
2
3
|
import emitter from '../emitter.js';
|
|
3
|
-
import { getExtensionManager } from '../extensions.js';
|
|
4
|
+
import { getExtensionManager } from '../extensions/index.js';
|
|
4
5
|
import { startServer } from '../server.js';
|
|
6
|
+
import * as pkg from '../utils/package.js';
|
|
5
7
|
import bootstrap from './commands/bootstrap/index.js';
|
|
6
8
|
import count from './commands/count/index.js';
|
|
7
9
|
import dbInstall from './commands/database/install.js';
|
|
@@ -14,11 +16,12 @@ import keyGenerate from './commands/security/key.js';
|
|
|
14
16
|
import secretGenerate from './commands/security/secret.js';
|
|
15
17
|
import usersCreate from './commands/users/create.js';
|
|
16
18
|
import usersPasswd from './commands/users/passwd.js';
|
|
17
|
-
import * as pkg from '../utils/package.js';
|
|
18
19
|
export async function createCli() {
|
|
19
20
|
const program = new Command();
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if ((await isInstalled()) === true) {
|
|
22
|
+
const extensionManager = getExtensionManager();
|
|
23
|
+
await extensionManager.initialize({ schedule: false, watch: false });
|
|
24
|
+
}
|
|
22
25
|
await emitter.emitInit('cli.before', { program });
|
|
23
26
|
program.name('directus').usage('[command] [options]');
|
|
24
27
|
program.version(pkg.version, '-v, --version');
|
|
@@ -2,7 +2,7 @@ import { Action } from '@directus/constants';
|
|
|
2
2
|
import { isDirectusError } from '@directus/errors';
|
|
3
3
|
import express from 'express';
|
|
4
4
|
import Joi from 'joi';
|
|
5
|
-
import { ErrorCode, ForbiddenError, InvalidPayloadError } from '
|
|
5
|
+
import { ErrorCode, ForbiddenError, InvalidPayloadError } from '@directus/errors';
|
|
6
6
|
import { respond } from '../middleware/respond.js';
|
|
7
7
|
import useCollection from '../middleware/use-collection.js';
|
|
8
8
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -5,7 +5,7 @@ import { merge, pick } from 'lodash-es';
|
|
|
5
5
|
import { ASSET_TRANSFORM_QUERY_KEYS, SYSTEM_ASSET_ALLOW_LIST } from '../constants.js';
|
|
6
6
|
import getDatabase from '../database/index.js';
|
|
7
7
|
import env from '../env.js';
|
|
8
|
-
import { InvalidQueryError, RangeNotSatisfiableError } from '
|
|
8
|
+
import { InvalidQueryError, RangeNotSatisfiableError } from '@directus/errors';
|
|
9
9
|
import logger from '../logger.js';
|
|
10
10
|
import useCollection from '../middleware/use-collection.js';
|
|
11
11
|
import { AssetsService } from '../services/assets.js';
|
|
@@ -130,7 +130,7 @@ asyncHandler(async (req, res) => {
|
|
|
130
130
|
vary.push('Accept');
|
|
131
131
|
}
|
|
132
132
|
let range = undefined;
|
|
133
|
-
if (req.headers.range) {
|
|
133
|
+
if (req.headers.range && Object.keys(transformationParams).length === 0) {
|
|
134
134
|
const rangeParts = /bytes=([0-9]*)-([0-9]*)/.exec(req.headers.range);
|
|
135
135
|
if (rangeParts && rangeParts.length > 1) {
|
|
136
136
|
range = {
|
package/dist/controllers/auth.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Router } from 'express';
|
|
|
3
3
|
import { createLDAPAuthRouter, createLocalAuthRouter, createOAuth2AuthRouter, createOpenIDAuthRouter, createSAMLAuthRouter, } from '../auth/drivers/index.js';
|
|
4
4
|
import { COOKIE_OPTIONS, DEFAULT_AUTH_PROVIDER } from '../constants.js';
|
|
5
5
|
import env from '../env.js';
|
|
6
|
-
import { ErrorCode, InvalidPayloadError } from '
|
|
6
|
+
import { ErrorCode, InvalidPayloadError } from '@directus/errors';
|
|
7
7
|
import logger from '../logger.js';
|
|
8
8
|
import { respond } from '../middleware/respond.js';
|
|
9
9
|
import { AuthenticationService } from '../services/authentication.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import { Router } from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
6
6
|
import { CollectionsService } from '../services/collections.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { Router } from 'express';
|
|
1
|
+
import { ForbiddenError, RouteNotFoundError } from '@directus/errors';
|
|
2
|
+
import express from 'express';
|
|
4
3
|
import env from '../env.js';
|
|
5
|
-
import {
|
|
6
|
-
import { getExtensionManager } from '../extensions.js';
|
|
4
|
+
import { getExtensionManager } from '../extensions/index.js';
|
|
7
5
|
import { respond } from '../middleware/respond.js';
|
|
6
|
+
import useCollection from '../middleware/use-collection.js';
|
|
7
|
+
import { ExtensionsService } from '../services/extensions.js';
|
|
8
8
|
import asyncHandler from '../utils/async-handler.js';
|
|
9
9
|
import { getCacheControlHeader } from '../utils/get-cache-headers.js';
|
|
10
10
|
import { getMilliseconds } from '../utils/get-milliseconds.js';
|
|
11
|
-
const router = Router();
|
|
12
|
-
router.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const router = express.Router();
|
|
12
|
+
router.use(useCollection('directus_extensions'));
|
|
13
|
+
router.get('/', asyncHandler(async (req, res, next) => {
|
|
14
|
+
const service = new ExtensionsService({
|
|
15
|
+
accountability: req.accountability,
|
|
16
|
+
schema: req.schema,
|
|
17
|
+
});
|
|
18
|
+
const extensions = await service.readAll();
|
|
19
|
+
res.locals['payload'] = { data: extensions || null };
|
|
20
|
+
return next();
|
|
21
|
+
}), respond);
|
|
22
|
+
router.patch('/:bundleOrName/:name?', asyncHandler(async (req, res, next) => {
|
|
23
|
+
const service = new ExtensionsService({
|
|
24
|
+
accountability: req.accountability,
|
|
25
|
+
schema: req.schema,
|
|
26
|
+
});
|
|
27
|
+
const bundle = req.params['name'] ? req.params['bundleOrName'] : null;
|
|
28
|
+
const name = req.params['name'] ? req.params['name'] : req.params['bundleOrName'];
|
|
29
|
+
if (bundle === undefined || !name) {
|
|
30
|
+
throw new ForbiddenError();
|
|
16
31
|
}
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
res.locals['payload'] = {
|
|
20
|
-
data: extensions,
|
|
21
|
-
};
|
|
32
|
+
await service.updateOne(bundle, name, req.body);
|
|
33
|
+
const updated = await service.readOne(bundle, name);
|
|
34
|
+
res.locals['payload'] = { data: updated || null };
|
|
22
35
|
return next();
|
|
23
36
|
}), respond);
|
|
24
37
|
router.get('/sources/:chunk', asyncHandler(async (req, res) => {
|
|
@@ -26,7 +39,7 @@ router.get('/sources/:chunk', asyncHandler(async (req, res) => {
|
|
|
26
39
|
const extensionManager = getExtensionManager();
|
|
27
40
|
let source;
|
|
28
41
|
if (chunk === 'index.js') {
|
|
29
|
-
source = extensionManager.
|
|
42
|
+
source = extensionManager.getAppExtensionsBundle();
|
|
30
43
|
}
|
|
31
44
|
else {
|
|
32
45
|
source = extensionManager.getAppExtensionChunk(chunk);
|
|
@@ -3,7 +3,7 @@ import { isDirectusError } from '@directus/errors';
|
|
|
3
3
|
import { Router } from 'express';
|
|
4
4
|
import Joi from 'joi';
|
|
5
5
|
import { ALIAS_TYPES } from '../constants.js';
|
|
6
|
-
import { ErrorCode, InvalidPayloadError } from '
|
|
6
|
+
import { ErrorCode, InvalidPayloadError } from '@directus/errors';
|
|
7
7
|
import validateCollection from '../middleware/collection-exists.js';
|
|
8
8
|
import { respond } from '../middleware/respond.js';
|
|
9
9
|
import useCollection from '../middleware/use-collection.js';
|
|
@@ -8,7 +8,7 @@ import Joi from 'joi';
|
|
|
8
8
|
import { minimatch } from 'minimatch';
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import env from '../env.js';
|
|
11
|
-
import { ContentTooLargeError, ErrorCode, InvalidPayloadError } from '
|
|
11
|
+
import { ContentTooLargeError, ErrorCode, InvalidPayloadError } from '@directus/errors';
|
|
12
12
|
import { respond } from '../middleware/respond.js';
|
|
13
13
|
import useCollection from '../middleware/use-collection.js';
|
|
14
14
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { UUID_REGEX } from '../constants.js';
|
|
4
|
-
import { ErrorCode } from '
|
|
4
|
+
import { ErrorCode } from '@directus/errors';
|
|
5
5
|
import { getFlowManager } from '../flows.js';
|
|
6
6
|
import { respond } from '../middleware/respond.js';
|
|
7
7
|
import useCollection from '../middleware/use-collection.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode, ForbiddenError, RouteNotFoundError } from '
|
|
3
|
+
import { ErrorCode, ForbiddenError, RouteNotFoundError } from '@directus/errors';
|
|
4
4
|
import collectionExists from '../middleware/collection-exists.js';
|
|
5
5
|
import { respond } from '../middleware/respond.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { isDirectusError } from '@directus/errors';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import Joi from 'joi';
|
|
4
|
-
import { ErrorCode, InvalidPayloadError } from '
|
|
4
|
+
import { ErrorCode, InvalidPayloadError } from '@directus/errors';
|
|
5
5
|
import validateCollection from '../middleware/collection-exists.js';
|
|
6
6
|
import { respond } from '../middleware/respond.js';
|
|
7
7
|
import useCollection from '../middleware/use-collection.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -2,7 +2,7 @@ import { parseJSON } from '@directus/utils';
|
|
|
2
2
|
import Busboy from 'busboy';
|
|
3
3
|
import express from 'express';
|
|
4
4
|
import { load as loadYaml } from 'js-yaml';
|
|
5
|
-
import { InvalidPayloadError, UnsupportedMediaTypeError } from '
|
|
5
|
+
import { InvalidPayloadError, UnsupportedMediaTypeError } from '@directus/errors';
|
|
6
6
|
import logger from '../logger.js';
|
|
7
7
|
import { respond } from '../middleware/respond.js';
|
|
8
8
|
import { SchemaService } from '../services/schema.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { format } from 'date-fns';
|
|
2
2
|
import { Router } from 'express';
|
|
3
|
-
import { RouteNotFoundError } from '
|
|
3
|
+
import { RouteNotFoundError } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import { ServerService } from '../services/server.js';
|
|
6
6
|
import { SpecificationService } from '../services/specifications.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { SettingsService } from '../services/settings.js';
|
|
@@ -3,7 +3,7 @@ import express from 'express';
|
|
|
3
3
|
import Joi from 'joi';
|
|
4
4
|
import { COOKIE_OPTIONS, UUID_REGEX } from '../constants.js';
|
|
5
5
|
import env from '../env.js';
|
|
6
|
-
import { ErrorCode, InvalidPayloadError } from '
|
|
6
|
+
import { ErrorCode, InvalidPayloadError } from '@directus/errors';
|
|
7
7
|
import { respond } from '../middleware/respond.js';
|
|
8
8
|
import useCollection from '../middleware/use-collection.js';
|
|
9
9
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { ErrorCode } from '
|
|
3
|
+
import { ErrorCode } from '@directus/errors';
|
|
4
4
|
import { respond } from '../middleware/respond.js';
|
|
5
5
|
import useCollection from '../middleware/use-collection.js';
|
|
6
6
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isDirectusError } from '@directus/errors';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import Joi from 'joi';
|
|
4
|
-
import { ErrorCode, ForbiddenError, InvalidCredentialsError, InvalidPayloadError } from '
|
|
4
|
+
import { ErrorCode, ForbiddenError, InvalidCredentialsError, InvalidPayloadError } from '@directus/errors';
|
|
5
5
|
import { respond } from '../middleware/respond.js';
|
|
6
6
|
import useCollection from '../middleware/use-collection.js';
|
|
7
7
|
import { validateBatch } from '../middleware/validate-batch.js';
|
|
@@ -2,11 +2,12 @@ import argon2 from 'argon2';
|
|
|
2
2
|
import Busboy from 'busboy';
|
|
3
3
|
import { Router } from 'express';
|
|
4
4
|
import Joi from 'joi';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { InvalidPayloadError, InvalidQueryError, UnsupportedMediaTypeError } from '@directus/errors';
|
|
7
8
|
import collectionExists from '../middleware/collection-exists.js';
|
|
8
9
|
import { respond } from '../middleware/respond.js';
|
|
9
|
-
import { ExportService
|
|
10
|
+
import { ExportService } from '../services/import-export/index.js';
|
|
10
11
|
import { RevisionsService } from '../services/revisions.js';
|
|
11
12
|
import { UtilsService } from '../services/utils.js';
|
|
12
13
|
import asyncHandler from '../utils/async-handler.js';
|
|
@@ -65,10 +66,6 @@ router.post('/import/:collection', collectionExists, asyncHandler(async (req, re
|
|
|
65
66
|
if (req.is('multipart/form-data') === false) {
|
|
66
67
|
throw new UnsupportedMediaTypeError({ mediaType: req.headers['content-type'], where: 'Content-Type header' });
|
|
67
68
|
}
|
|
68
|
-
const service = new ImportService({
|
|
69
|
-
accountability: req.accountability,
|
|
70
|
-
schema: req.schema,
|
|
71
|
-
});
|
|
72
69
|
let headers;
|
|
73
70
|
if (req.headers['content-type']) {
|
|
74
71
|
headers = req.headers;
|
|
@@ -81,13 +78,34 @@ router.post('/import/:collection', collectionExists, asyncHandler(async (req, re
|
|
|
81
78
|
}
|
|
82
79
|
const busboy = Busboy({ headers });
|
|
83
80
|
busboy.on('file', async (_fieldname, fileStream, { mimeType }) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
const { createTmpFile } = await import('@directus/utils/node');
|
|
82
|
+
const { getWorkerPool } = await import('../worker-pool.js');
|
|
83
|
+
const tmpFile = await createTmpFile().catch(() => null);
|
|
84
|
+
if (!tmpFile)
|
|
85
|
+
throw new Error('Failed to create temporary file for import');
|
|
86
|
+
fileStream.pipe(fs.createWriteStream(tmpFile.path));
|
|
87
|
+
fileStream.on('end', async () => {
|
|
88
|
+
const workerPool = getWorkerPool();
|
|
89
|
+
const require = createRequire(import.meta.url);
|
|
90
|
+
const filename = require.resolve('../services/import-export/import-worker');
|
|
91
|
+
const workerData = {
|
|
92
|
+
collection: req.params['collection'],
|
|
93
|
+
mimeType,
|
|
94
|
+
filePath: tmpFile.path,
|
|
95
|
+
accountability: req.accountability,
|
|
96
|
+
schema: req.schema,
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
await workerPool.run(workerData, { filename });
|
|
100
|
+
res.status(200).end();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
next(error);
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
await tmpFile.cleanup();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
91
109
|
});
|
|
92
110
|
busboy.on('error', (err) => next(err));
|
|
93
111
|
req.pipe(busboy);
|
|
@@ -111,10 +129,11 @@ router.post('/export/:collection', collectionExists, asyncHandler(async (req, _r
|
|
|
111
129
|
return next();
|
|
112
130
|
}), respond);
|
|
113
131
|
router.post('/cache/clear', asyncHandler(async (req, res) => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
132
|
+
const service = new UtilsService({
|
|
133
|
+
accountability: req.accountability,
|
|
134
|
+
schema: req.schema,
|
|
135
|
+
});
|
|
136
|
+
await service.clearCache();
|
|
118
137
|
res.status(200).end();
|
|
119
138
|
}));
|
|
120
139
|
export default router;
|