@tomei/media 0.8.11-dev.1 → 0.10.1-test.1

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.
Files changed (41) hide show
  1. package/.gitlab-ci.yml +231 -13
  2. package/.husky/commit-msg +1 -1
  3. package/.husky/pre-commit +0 -0
  4. package/.vscode/settings.json +3 -0
  5. package/dist/__tests__/common.service.spec.d.ts +1 -0
  6. package/dist/__tests__/common.service.spec.js +160 -0
  7. package/dist/__tests__/common.service.spec.js.map +1 -0
  8. package/dist/__tests__/medias.repository.spec.d.ts +1 -0
  9. package/dist/__tests__/medias.repository.spec.js +140 -0
  10. package/dist/__tests__/medias.repository.spec.js.map +1 -0
  11. package/dist/__tests__/medias.spec.d.ts +1 -0
  12. package/dist/__tests__/medias.spec.js +347 -0
  13. package/dist/__tests__/medias.spec.js.map +1 -0
  14. package/dist/__tests__/pipes.spec.d.ts +1 -0
  15. package/dist/__tests__/pipes.spec.js +130 -0
  16. package/dist/__tests__/pipes.spec.js.map +1 -0
  17. package/dist/base/base.medias.js +2 -2
  18. package/dist/base/base.medias.js.map +1 -1
  19. package/dist/common/common.service.js +2 -2
  20. package/dist/common/common.service.js.map +1 -1
  21. package/dist/medias.d.ts +2 -2
  22. package/dist/medias.js +16 -10
  23. package/dist/medias.js.map +1 -1
  24. package/dist/medias.repository.js.map +1 -1
  25. package/dist/pipe/append-id.pipe.js +2 -2
  26. package/dist/pipe/append-id.pipe.js.map +1 -1
  27. package/dist/pipe/validate-id.pipe.js +2 -2
  28. package/dist/pipe/validate-id.pipe.js.map +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/jest.config.js +26 -0
  31. package/package.json +38 -34
  32. package/src/__tests__/common.service.spec.ts +203 -0
  33. package/src/__tests__/medias.repository.spec.ts +158 -0
  34. package/src/__tests__/medias.spec.ts +468 -0
  35. package/src/__tests__/pipes.spec.ts +154 -0
  36. package/src/base/base.medias.ts +2 -2
  37. package/src/common/common.service.ts +2 -2
  38. package/src/medias.repository.ts +9 -3
  39. package/src/medias.ts +20 -15
  40. package/src/pipe/append-id.pipe.ts +2 -2
  41. package/src/pipe/validate-id.pipe.ts +2 -2
package/src/medias.ts CHANGED
@@ -10,7 +10,7 @@ import { IBaseMediasAttr } from './interfaces/base.medias-attr.interface';
10
10
  import { Readable } from 'stream';
11
11
  import { InternalMediaDto } from './dto/internal-medias.dto';
12
12
  import { ExternalMediaDto } from './dto/external-media.dto';
13
- import * as cuid from 'cuid';
13
+ import { createId } from '@paralleldrive/cuid2';
14
14
  import { Op } from 'sequelize';
15
15
  import { ActionEnum, Activity } from '@tomei/activity-history';
16
16
  import { MediasRepository } from './medias.repository';
@@ -33,9 +33,17 @@ export class Medias extends BaseMedias {
33
33
  ObjectId: string;
34
34
  ObjectType = 'Media';
35
35
 
36
- blobServiceClient = BlobServiceClient.fromConnectionString(
37
- process.env.AZURE_STORAGE_CONNECTION_STRING,
38
- );
36
+ private _blobServiceClient: BlobServiceClient | null = null;
37
+
38
+ private get blobServiceClient(): BlobServiceClient {
39
+ if (!this._blobServiceClient) {
40
+ this._blobServiceClient = BlobServiceClient.fromConnectionString(
41
+ process.env.AZURE_STORAGE_CONNECTION_STRING,
42
+ );
43
+ }
44
+ return this._blobServiceClient;
45
+ }
46
+
39
47
  container: string;
40
48
  algorithm = 'aes-256-cbc';
41
49
  commonService: CommonService;
@@ -74,7 +82,7 @@ export class Medias extends BaseMedias {
74
82
 
75
83
  if (media) {
76
84
  const activity = new Activity();
77
- activity.ActivityId = cuid();
85
+ activity.ActivityId = createId();
78
86
  activity.Action = ActionEnum.CREATE;
79
87
  activity.Description = 'Add New Media';
80
88
  activity.EntityType = 'Media';
@@ -113,7 +121,7 @@ export class Medias extends BaseMedias {
113
121
  }
114
122
  if (media) {
115
123
  const activity = new Activity();
116
- activity.ActivityId = cuid();
124
+ activity.ActivityId = createId();
117
125
  activity.Action = ActionEnum.UPDATE;
118
126
  activity.Description = 'Update Media';
119
127
  activity.EntityType = 'Media';
@@ -382,7 +390,7 @@ export class Medias extends BaseMedias {
382
390
  try {
383
391
  fileBuffer = await this.getFileFromLocal(this.FilePath);
384
392
  } catch (error) {
385
- if (error.includes('ENOENT')) {
393
+ if (error instanceof Error && error.message.includes('ENOENT')) {
386
394
  console.warn(
387
395
  `Local file missing: ${this.FilePath}, fetching from Azure.`,
388
396
  );
@@ -421,7 +429,7 @@ export class Medias extends BaseMedias {
421
429
  file.iv = await this.getFileFromLocal(this.getIvPath());
422
430
  }
423
431
  } catch (error) {
424
- if (error.includes('ENOENT')) {
432
+ if (error instanceof Error && error.message.includes('ENOENT')) {
425
433
  console.warn(
426
434
  `IV file missing: ${this.getIvPath()}, fetching from Azure.`,
427
435
  );
@@ -547,14 +555,11 @@ export class Medias extends BaseMedias {
547
555
  this.IsEncryptedYN,
548
556
  );
549
557
  } else {
550
- await this.deleteUploadedFileFromLocal(
551
- this.FilePath,
552
- this.IsEncryptedYN,
553
- );
558
+ await this.deleteUploadedFileFromLocal(this.URL, this.IsEncryptedYN);
554
559
  }
555
560
  }
556
561
  const activity = new Activity();
557
- activity.ActivityId = cuid();
562
+ activity.ActivityId = createId();
558
563
  activity.Action = ActionEnum.DELETE;
559
564
  activity.Description = 'Deleted media (ID: ${this.MediaId})';
560
565
  activity.EntityType = 'Media';
@@ -577,7 +582,7 @@ export class Medias extends BaseMedias {
577
582
  try {
578
583
  const mediaAttr: IBaseMediasAttr = {
579
584
  ...createMediaDto,
580
- MediaId: cuid(),
585
+ MediaId: createId(),
581
586
  IsExternalYN: 'N',
582
587
  ExternalSource: '',
583
588
  URL: '',
@@ -604,7 +609,7 @@ export class Medias extends BaseMedias {
604
609
  async postExternal(createMediaDto: ExternalMediaDto, loginUser: LoginUser) {
605
610
  const mediaAttr: IBaseMediasAttr = {
606
611
  ...createMediaDto,
607
- MediaId: cuid(),
612
+ MediaId: createId(),
608
613
  IsExternalYN: 'Y',
609
614
  CreatedAt: new Date(),
610
615
  UpdatedAt: new Date(),
@@ -1,5 +1,5 @@
1
1
  import { Injectable, PipeTransform } from '@nestjs/common';
2
- import * as cuid from 'cuid';
2
+ import { createId } from '@paralleldrive/cuid2';
3
3
 
4
4
  @Injectable()
5
5
  export class AppendIdPipe implements PipeTransform {
@@ -10,6 +10,6 @@ export class AppendIdPipe implements PipeTransform {
10
10
  }
11
11
 
12
12
  transform(value: any) {
13
- return { ...value, [this.idName]: cuid() };
13
+ return { ...value, [this.idName]: createId() };
14
14
  }
15
15
  }
@@ -1,5 +1,5 @@
1
1
  import { BadRequestException, Injectable, PipeTransform } from '@nestjs/common';
2
- import * as cuid from 'cuid';
2
+ import { isCuid } from '@paralleldrive/cuid2';
3
3
 
4
4
  @Injectable()
5
5
  export class ValidateIdPipe implements PipeTransform {
@@ -10,7 +10,7 @@ export class ValidateIdPipe implements PipeTransform {
10
10
  }
11
11
 
12
12
  transform(value: string) {
13
- if (value && !cuid.isCuid(value)) {
13
+ if (value && !isCuid(value)) {
14
14
  throw new BadRequestException(this.errorMessage);
15
15
  }
16
16
  return value;