Skip to content

Commit

Permalink
fix(file): changed content type handling (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
bararchy authored Aug 7, 2024
1 parent 1847321 commit b968521
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
1 change: 0 additions & 1 deletion client/public/YllKENUJpD5wUohIiW.txt

This file was deleted.

19 changes: 6 additions & 13 deletions src/file/file.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ export class FileController {

constructor(private fileService: FileService) {}

private getContentType(contentType: string, acceptHeader: string) {
private getContentType(contentType: string) {
if (contentType) {
return contentType;
} else if (acceptHeader) {
return acceptHeader;
} else {
return 'application/octet-stream';
}
Expand Down Expand Up @@ -88,10 +86,9 @@ export class FileController {
@Query('path') path: string,
@Query('type') contentType: string,
@Res({ passthrough: true }) res: FastifyReply,
@Headers('accept') acceptHeader: string,
) {
const file: Stream = await this.fileService.getFile(path);
const type = this.getContentType(contentType, acceptHeader);
const type = this.getContentType(contentType);
res.type(type);

return file;
Expand Down Expand Up @@ -124,13 +121,12 @@ export class FileController {
@Query('path') path: string,
@Query('type') contentType: string,
@Res({ passthrough: true }) res: FastifyReply,
@Headers('accept') acceptHeader: string,
) {
const file: Stream = await this.loadCPFile(
CloudProvidersMetaData.GOOGLE,
path,
);
const type = this.getContentType(contentType, acceptHeader);
const type = this.getContentType(contentType);
res.type(type);

return file;
Expand Down Expand Up @@ -163,13 +159,12 @@ export class FileController {
@Query('path') path: string,
@Query('type') contentType: string,
@Res({ passthrough: true }) res: FastifyReply,
@Headers('accept') acceptHeader: string,
) {
const file: Stream = await this.loadCPFile(
CloudProvidersMetaData.AWS,
path,
);
const type = this.getContentType(contentType, acceptHeader);
const type = this.getContentType(contentType);
res.type(type);

return file;
Expand Down Expand Up @@ -202,13 +197,12 @@ export class FileController {
@Query('path') path: string,
@Query('type') contentType: string,
@Res({ passthrough: true }) res: FastifyReply,
@Headers('accept') acceptHeader: string,
) {
const file: Stream = await this.loadCPFile(
CloudProvidersMetaData.AZURE,
path,
);
const type = this.getContentType(contentType, acceptHeader);
const type = this.getContentType(contentType);
res.type(type);

return file;
Expand Down Expand Up @@ -241,13 +235,12 @@ export class FileController {
@Query('path') path: string,
@Query('type') contentType: string,
@Res({ passthrough: true }) res: FastifyReply,
@Headers('accept') acceptHeader: string,
) {
const file: Stream = await this.loadCPFile(
CloudProvidersMetaData.DIGITAL_OCEAN,
path,
);
const type = this.getContentType(contentType, acceptHeader);
const type = this.getContentType(contentType);
res.type(type);

return file;
Expand Down

0 comments on commit b968521

Please sign in to comment.