image-optimize.service.ts 938 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { InjectQueue } from '@nestjs/bull';
  2. import { Injectable } from '@nestjs/common';
  3. import { Queue } from 'bull';
  4. import { randomUUID } from 'crypto';
  5. import { join } from 'path';
  6. import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
  7. import { AuthUserDto } from '../../decorators/auth-user.decorator';
  8. @Injectable()
  9. export class AssetOptimizeService {
  10. constructor(@InjectQueue('optimize') private optimizeQueue: Queue) {}
  11. public async resizeImage(savedAsset: AssetEntity) {
  12. const job = await this.optimizeQueue.add(
  13. 'resize-image',
  14. {
  15. savedAsset,
  16. },
  17. { jobId: randomUUID() },
  18. );
  19. return {
  20. jobId: job.id,
  21. };
  22. }
  23. public async resizeVideo(savedAsset: AssetEntity) {
  24. const job = await this.optimizeQueue.add(
  25. 'resize-video',
  26. {
  27. savedAsset,
  28. },
  29. { jobId: randomUUID() },
  30. );
  31. return {
  32. jobId: job.id,
  33. };
  34. }
  35. }