@@ -19,6 +19,7 @@ import {
1919 Injectable ,
2020 NotFoundException ,
2121 OnModuleInit ,
22+ UnsupportedMediaTypeException ,
2223} from '@nestjs/common' ;
2324import { InjectRepository } from '@nestjs/typeorm' ;
2425import jwt from 'jsonwebtoken' ;
@@ -519,9 +520,9 @@ export class FileService implements OnModuleInit {
519520
520521 return await externalMinio . presignedUrl (
521522 'GET' ,
522- file . type === FileType . MCAP
523- ? env . MINIO_MCAP_BUCKET_NAME
524- : env . MINIO_BAG_BUCKET_NAME ,
523+ file . type === FileType . BAG
524+ ? env . MINIO_BAG_BUCKET_NAME
525+ : env . MINIO_MCAP_BUCKET_NAME ,
525526 file . uuid , // we use the uuid as the filename in Minio
526527 expires ? 4 * 60 * 60 : 604_800 , // 604800 seconds = 1 week
527528 {
@@ -792,15 +793,40 @@ export class FileService implements OnModuleInit {
792793
793794 logger . debug ( `Creating temporary access for file: ${ filename } ` ) ;
794795
795- // verify that file has ending .bag or .mcap
796- if ( ! filename . endsWith ( '.bag' ) && ! filename . endsWith ( '.mcap' ) ) {
796+ const fileExtensionToFileTypeMap : ReadonlyMap <
797+ string ,
798+ FileType
799+ > = new Map ( [
800+ [ '.bag' , FileType . BAG ] ,
801+ [ '.mcap' , FileType . MCAP ] ,
802+ [ '.yaml' , FileType . YAML ] ,
803+ [ '.svo2' , FileType . SVO2 ] ,
804+ [ '.tum' , FileType . TUM ] ,
805+ [ '.db3' , FileType . DB3 ] ,
806+ ] ) ;
807+
808+ const supported_file_endings = [
809+ ...fileExtensionToFileTypeMap . keys ( ) ,
810+ ] ;
811+
812+ if (
813+ ! supported_file_endings . some ( ( ending ) =>
814+ filename . endsWith ( ending ) ,
815+ )
816+ ) {
797817 emptyCredentials . error = 'Invalid file ending' ;
798818 return emptyCredentials ;
799819 }
800820
801- const fileType : FileType = filename . endsWith ( '.bag' )
802- ? FileType . BAG
803- : FileType . MCAP ;
821+ const matchingFileType = supported_file_endings . find ( ( ending ) =>
822+ filename . endsWith ( ending ) ,
823+ ) ;
824+ if ( matchingFileType === undefined )
825+ throw new UnsupportedMediaTypeException ( ) ;
826+ const fileType : FileType | undefined =
827+ fileExtensionToFileTypeMap . get ( matchingFileType ) ;
828+ if ( fileType === undefined )
829+ throw new UnsupportedMediaTypeException ( ) ;
804830
805831 // check if file already exists
806832 const existingFile = await this . fileRepository . exists ( {
0 commit comments