@@ -11,13 +11,12 @@ import { Injectable, OnModuleInit } from '@nestjs/common';
1111import { MaterialType } from '@prisma/client' ;
1212import ffmpeg from 'fluent-ffmpeg' ;
1313import path , { join } from 'node:path' ;
14- import { readFileSync } from 'node:fs' ;
1514import { promisify } from 'node:util' ;
15+ import { getFileHash } from '../common/helper/file.helper' ;
1616import { PrismaService } from '../common/prisma/prisma.service' ;
17- import { MaterialNotFoundError , MetaDataParseError } from './materials.error' ;
18- import { materialDto } from './DTO/material.dto' ;
1917import { UsersService } from '../users/users.service' ;
20- import md5 from 'md5' ;
18+ import { materialDto } from './DTO/material.dto' ;
19+ import { MaterialNotFoundError , MetaDataParseError } from './materials.error' ;
2120@Injectable ( )
2221export class MaterialsService implements OnModuleInit {
2322 private ffprobeAsync : ( file : string ) => Promise < ffmpeg . FfprobeData > ;
@@ -101,8 +100,7 @@ export class MaterialsService implements OnModuleInit {
101100 ) : Promise < PrismaJson . metaType > {
102101 let meta : PrismaJson . metaType ;
103102
104- const buf = readFileSync ( file . path ) ;
105- const hash = md5 ( buf ) ;
103+ const hash = await getFileHash ( file . path ) ;
106104
107105 if ( type === MaterialType . image ) {
108106 const metadata = await this . getImageMetadata ( file . path ) ;
0 commit comments