import { Controller , Post } from "@tsed/common" ; import { MultipartFile } from "@tsed/multipartfiles" ; import * as fs from 'fs' ; import { ChecksumCollisionService } from '../../services/ChecksumCollisionService' ; interface ICheckResponse { success : boolean ; flag : string ; } @ Controller ( "/md5" ) export class ChecksumCollisitonsController { @ Post ( "/checksum" ) public async checksum ( @ MultipartFile ( "file1" ) file1 , @ MultipartFile ( "file2" ) file2 ) { let success = false ; let flag = "" ; const md51 = await ( ChecksumCollisionService . getMd5FileChecksum ( file1 . path ) ) ; const md52 = await ( ChecksumCollisionService . getMd5FileChecksum ( file2 . path ) ) ; if ( md51 === md52 ) { const sha11 = await ( ChecksumCollisionService . getSha1FileChecksum ( file1 . path ) ) ; const sha12 = await ( ChecksumCollisionService . getSha1FileChecksum ( file2 . path ) ) ; if ( sha11 !== sha12 ) { success = true ; flag = ChecksumCollisionService . getFlag ( ) ; } } fs . unlink ( file1 . path , ( ) => { } ) ; fs . unlink ( file2 . path , ( ) => { } ) ; return { flag , success } ; } }