@directus/api 28.0.1 → 28.0.3

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/flows.js CHANGED
@@ -206,7 +206,7 @@ class FlowManager {
206
206
  logger.warn(`Specified collection must be one of: ${enabledCollections.join(', ')}.`);
207
207
  throw new ForbiddenError();
208
208
  }
209
- if (!targetKeys || !Array.isArray(targetKeys)) {
209
+ if (requireSelection && (!targetKeys || !Array.isArray(targetKeys))) {
210
210
  logger.warn(`Manual trigger requires "keys" to be specified in the payload`);
211
211
  throw new ForbiddenError();
212
212
  }
@@ -233,15 +233,17 @@ class FlowManager {
233
233
  logger.warn(`Triggering ${targetCollection} is not allowed`);
234
234
  throw new ForbiddenError();
235
235
  }
236
- const service = getService(targetCollection, { schema, accountability, knex: database });
237
- const primaryField = schema.collections[targetCollection].primary;
238
- let keys = await service.readMany(targetKeys, { fields: [primaryField] }, {
239
- emitEvents: false,
240
- });
241
- keys = keys.map((key) => key[primaryField]);
242
- if (targetKeys.some((key) => !keys.includes(key))) {
243
- logger.warn(`Triggering keys ${targetKeys} is not allowed`);
244
- throw new ForbiddenError();
236
+ if (Array.isArray(targetKeys) && targetKeys.length > 0) {
237
+ const service = getService(targetCollection, { schema, accountability, knex: database });
238
+ const primaryField = schema.collections[targetCollection].primary;
239
+ const keys = await service.readMany(targetKeys, { fields: [primaryField] }, {
240
+ emitEvents: false,
241
+ });
242
+ const allowedKeys = keys.map((key) => String(key[primaryField]));
243
+ if (targetKeys.some((key) => !allowedKeys.includes(String(key)))) {
244
+ logger.warn(`Triggering keys ${targetKeys} is not allowed`);
245
+ throw new ForbiddenError();
246
+ }
245
247
  }
246
248
  }
247
249
  if (flow.options['async']) {
@@ -56,14 +56,15 @@ export class FilesService extends ItemsService {
56
56
  primaryKey = await this.createOne(payload, { emitEvents: false });
57
57
  }
58
58
  const fileExtension = path.extname(payload.filename_download) || (payload.type && '.' + extension(payload.type)) || '';
59
+ const filenameDisk = primaryKey + (fileExtension || '');
59
60
  // The filename_disk is the FINAL filename on disk
60
- payload.filename_disk ||= primaryKey + (fileExtension || '');
61
+ payload.filename_disk ||= filenameDisk;
61
62
  // If the filename_disk extension doesn't match the new mimetype, update it
62
63
  if (isReplacement === true && path.extname(payload.filename_disk) !== fileExtension) {
63
- payload.filename_disk = primaryKey + (fileExtension || '');
64
+ payload.filename_disk = filenameDisk;
64
65
  }
65
66
  // Temp filename is used for replacements
66
- const tempFilenameDisk = 'temp_' + payload.filename_disk;
67
+ const tempFilenameDisk = 'temp_' + filenameDisk;
67
68
  if (!payload.type) {
68
69
  payload.type = 'application/octet-stream';
69
70
  }
@@ -119,13 +120,19 @@ export class FilesService extends ItemsService {
119
120
  }
120
121
  // If the file is a replacement, we need to update the DB record with the new payload, delete the old files, and upgrade the temp file
121
122
  if (isReplacement === true) {
122
- await this.updateOne(primaryKey, payload, { emitEvents: false });
123
- // delete the previously saved file and thumbnails to ensure they're generated fresh
124
- for await (const filepath of disk.list(String(primaryKey))) {
125
- await disk.delete(filepath);
123
+ try {
124
+ await this.updateOne(primaryKey, payload, { emitEvents: false });
125
+ // delete the previously saved file and thumbnails to ensure they're generated fresh
126
+ for await (const filepath of disk.list(String(primaryKey))) {
127
+ await disk.delete(filepath);
128
+ }
129
+ // Upgrade the temp file to the final filename
130
+ await disk.move(tempFilenameDisk, payload.filename_disk);
131
+ }
132
+ catch (err) {
133
+ await cleanUp();
134
+ throw err;
126
135
  }
127
- // Upgrade the temp file to the final filename
128
- await disk.move(tempFilenameDisk, payload.filename_disk);
129
136
  }
130
137
  const { size } = await storage.location(data.storage).stat(payload.filename_disk);
131
138
  payload.filesize = size;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/api",
3
- "version": "28.0.1",
3
+ "version": "28.0.3",
4
4
  "description": "Directus is a real-time API and App dashboard for managing SQL database content",
5
5
  "keywords": [
6
6
  "directus",
@@ -152,15 +152,15 @@
152
152
  "ws": "8.18.1",
153
153
  "zod": "3.24.2",
154
154
  "zod-validation-error": "3.4.0",
155
- "@directus/app": "13.11.1",
155
+ "@directus/app": "13.11.3",
156
156
  "@directus/env": "5.1.0",
157
157
  "@directus/constants": "13.0.1",
158
158
  "@directus/errors": "2.0.2",
159
159
  "@directus/extensions": "3.0.7",
160
160
  "@directus/extensions-registry": "3.0.7",
161
+ "@directus/format-title": "12.0.1",
161
162
  "@directus/extensions-sdk": "14.0.0",
162
163
  "@directus/memory": "3.0.6",
163
- "@directus/format-title": "12.0.1",
164
164
  "@directus/pressure": "3.0.6",
165
165
  "@directus/schema": "13.0.1",
166
166
  "@directus/schema-builder": "0.0.3",
@@ -169,13 +169,13 @@
169
169
  "@directus/storage-driver-azure": "12.0.6",
170
170
  "@directus/storage-driver-cloudinary": "12.0.6",
171
171
  "@directus/storage-driver-gcs": "12.0.6",
172
- "@directus/storage-driver-s3": "12.0.6",
173
172
  "@directus/storage-driver-local": "12.0.0",
174
- "@directus/utils": "13.0.7",
175
- "@directus/system-data": "3.1.1",
176
173
  "@directus/storage-driver-supabase": "3.0.6",
177
- "@directus/validation": "2.0.6",
178
- "directus": "11.9.1"
174
+ "@directus/system-data": "3.1.1",
175
+ "@directus/utils": "13.0.7",
176
+ "@directus/storage-driver-s3": "12.0.6",
177
+ "directus": "11.9.3",
178
+ "@directus/validation": "2.0.6"
179
179
  },
180
180
  "devDependencies": {
181
181
  "@directus/tsconfig": "3.0.0",