@dnax/core 0.42.0 → 0.43.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/app/hono.ts CHANGED
@@ -412,16 +412,35 @@ function HonoInstance(): typeof app {
412
412
  if (col?.slug && col?.media?.enabled) {
413
413
  let data = JSON.parse(parseBody?.data) || {};
414
414
  // rest.startTransaction();
415
+
416
+ let files = [];
417
+ if (Array.isArray(parseBody.file)) {
418
+ files = parseBody.file;
419
+ } else {
420
+ files.push(parseBody.file);
421
+ }
422
+
423
+ if (col?.hooks?.beforeUpload) {
424
+ await col?.hooks?.beforeUpload({
425
+ io: Cfg.io,
426
+ data: data,
427
+ c: c,
428
+ rest: rest,
429
+ action: "upload",
430
+ session: sessionStorage(),
431
+ error: fn.error,
432
+ files: files,
433
+ });
434
+ }
415
435
  const drive = new MediaDrive({
416
436
  location: col?.media?.overwriteFolderName ?? col?.slug,
417
437
  visibility: col?.media?.visibility ?? "public",
418
438
  });
419
439
 
420
- if (Array.isArray(parseBody?.file)) {
440
+ if (Array.isArray(files)) {
421
441
  let insertedFiles = [];
422
-
423
442
  let indexedData = 0;
424
- let allFiles = parseBody?.file;
443
+ let allFiles = files;
425
444
  for await (let file of allFiles) {
426
445
  let d;
427
446
  if (Array.isArray(data) && data.length) {
@@ -430,13 +449,28 @@ function HonoInstance(): typeof app {
430
449
  d = data;
431
450
  }
432
451
  let insertedFile = await drive.write(file.name, file);
452
+
433
453
  insertedFiles.push({
434
454
  ...d,
435
455
  _file: insertedFile,
436
456
  });
437
457
  indexedData++;
438
458
  }
459
+
439
460
  response = await rest.insertMany(col?.slug, insertedFiles);
461
+ if (col?.hooks?.afterUpload) {
462
+ await col?.hooks?.afterUpload({
463
+ io: Cfg.io,
464
+ data: data,
465
+ c: c,
466
+ rest: rest,
467
+ action: "upload",
468
+ session: sessionStorage(),
469
+ error: fn.error,
470
+ files: files,
471
+ result: response,
472
+ });
473
+ }
440
474
  } else if (typeof parseBody?.file == "object") {
441
475
  let insertedFile = await drive.write(
442
476
  parseBody.file?.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -53,7 +53,8 @@ export type Actions =
53
53
  | "deleteOne"
54
54
  | "deleteMany"
55
55
  | "authCollection"
56
- | "aggregate";
56
+ | "aggregate"
57
+ | "upload";
57
58
 
58
59
  export type Field = {
59
60
  name: string;
@@ -212,6 +213,7 @@ export type hooksCtx = (ctx: {
212
213
  rest: InstanceType<typeof useRest>;
213
214
  session?: sessionCtx;
214
215
  io: socketIoType;
216
+ files: Array<any> | Object;
215
217
  error: typeof fn.error;
216
218
  }) => any;
217
219
 
@@ -334,6 +336,8 @@ export type Collection = {
334
336
  afterAggregate?: hooksCtx;
335
337
  beforeCount?: hooksCtx;
336
338
  afterCount?: hooksCtx;
339
+ beforeUpload?: hooksCtx;
340
+ afterUpload?: hooksCtx;
337
341
  };
338
342
  access?: {
339
343
  "*"?: accessCtx;