29 lines
895 B
TypeScript
29 lines
895 B
TypeScript
import { Body, Controller, Get, Inject, Param, Post, Res } from '@nestjs/common';
|
|
import { ClientProxy } from '@nestjs/microservices';
|
|
import { Response } from 'express';
|
|
import { firstValueFrom } from 'rxjs';
|
|
import axios from 'axios';
|
|
|
|
@Controller('dicom')
|
|
export class DicomController {
|
|
constructor(@Inject('Client') private client: ClientProxy) {}
|
|
|
|
@Post('download')
|
|
async downloadDicom(@Body() body, @Res() res: Response) {
|
|
const { ID, Type } = body;
|
|
const url = await firstValueFrom(
|
|
this.client.send({ cmd: 'dicom.archive.url' }, { ID, Type }),
|
|
);
|
|
try {
|
|
const { data: dataStream } = await axios.get(url, {
|
|
responseType: 'stream',
|
|
});
|
|
res.setHeader('Content-Name', `${ID}.zip`);
|
|
res.setHeader('Content-Type', 'application/zip');
|
|
dataStream.pipe(res);
|
|
} catch (error) {
|
|
return { code: 1, msg: error };
|
|
}
|
|
}
|
|
}
|