Skip to content

Commit 5435bc1

Browse files
committed
feat: add experimental support for additional file types (#1758)
1 parent 26b09b9 commit 5435bc1

File tree

6 files changed

+49
-10
lines changed

6 files changed

+49
-10
lines changed

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# ignore bag and mcap files
1616
**/*.mcap
1717
**/*.bag
18+
**/*.db3
19+
**/*.tum
20+
**/*.svo2
21+
**/*.yaml
1822

1923
# ignore build info file
2024
frontend/src/build.ts

backend/src/services/file.service.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ConflictException,
1919
Injectable,
2020
NotFoundException,
21-
OnModuleInit,
21+
OnModuleInit, UnsupportedMediaTypeException,
2222
} from '@nestjs/common';
2323
import { InjectRepository } from '@nestjs/typeorm';
2424
import jwt from 'jsonwebtoken';
@@ -519,9 +519,9 @@ export class FileService implements OnModuleInit {
519519

520520
return await externalMinio.presignedUrl(
521521
'GET',
522-
file.type === FileType.MCAP
523-
? env.MINIO_MCAP_BUCKET_NAME
524-
: env.MINIO_BAG_BUCKET_NAME,
522+
file.type === FileType.BAG
523+
? env.MINIO_BAG_BUCKET_NAME
524+
: env.MINIO_MCAP_BUCKET_NAME,
525525
file.uuid, // we use the uuid as the filename in Minio
526526
expires ? 4 * 60 * 60 : 604_800, // 604800 seconds = 1 week
527527
{
@@ -792,15 +792,26 @@ export class FileService implements OnModuleInit {
792792

793793
logger.debug(`Creating temporary access for file: ${filename}`);
794794

795-
// verify that file has ending .bag or .mcap
796-
if (!filename.endsWith('.bag') && !filename.endsWith('.mcap')) {
795+
const fileExtensionToFileTypeMap: ReadonlyMap<string, FileType> = new Map([
796+
['.bag', FileType.BAG],
797+
['.mcap', FileType.MCAP],
798+
['.yaml', FileType.YAML],
799+
['.svo2', FileType.SVO2],
800+
['.tum', FileType.TUM],
801+
['.db3', FileType.DB3],
802+
]);
803+
804+
const supported_file_endings = [...fileExtensionToFileTypeMap.keys()];
805+
806+
if (!supported_file_endings.some((ending) => filename.endsWith(ending))) {
797807
emptyCredentials.error = 'Invalid file ending';
798808
return emptyCredentials;
799809
}
800810

801-
const fileType: FileType = filename.endsWith('.bag')
802-
? FileType.BAG
803-
: FileType.MCAP;
811+
const matchingFileType = supported_file_endings.find(ending => filename.endsWith(ending));
812+
if (matchingFileType === undefined) throw new UnsupportedMediaTypeException();
813+
const fileType: FileType | undefined = fileExtensionToFileTypeMap.get(matchingFileType);
814+
if (fileType === undefined) throw new UnsupportedMediaTypeException();
804815

805816
// check if file already exists
806817
const existingFile = await this.fileRepository.exists({

backend/src/validation/validation-logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const MISSION_NAME_REGEX = /^[\w\-_]{3,50}$/;
22

33
export const PROJECT_NAME_REGEX = /^[\w\-_]{3,50}$/;
44

5-
export const FILE_NAME_REGEX = /^[\w\-.()]{3,50}.(bag|mcap)$/;
5+
export const FILE_NAME_REGEX = /^[\w\-.()]{3,50}.(bag|mcap|db3|yaml|svo2|tum)$/;
66

77
export const NON_UUID_REGEX =
88
/^(?![0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)/;

cli/kleinkram/cli/_upload.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def upload(
4444
False,
4545
help="fix filenames before upload, this does not change the filenames locally",
4646
),
47+
experimental_datatypes: bool = typer.Option(
48+
False,
49+
help="allow experimental datatypes (yaml, svo2, db3, tum)"
50+
),
4751
ignore_missing_tags: bool = typer.Option(False, help="ignore mission tags"),
4852
) -> None:
4953
# get filepaths
@@ -61,6 +65,18 @@ def upload(
6165

6266
if not fix_filenames:
6367
for file in file_paths:
68+
69+
# check for experimental datatypes and throw an exception if not allowed
70+
EXPERIMENTAL_DATATYPES = {".yaml", ".svo2", ".db3", ".tum"}
71+
72+
if not experimental_datatypes:
73+
if file.suffix.lower() in EXPERIMENTAL_DATATYPES:
74+
# NOTE: Assuming a 'DatatypeNotSupported' exception exists/is defined
75+
raise FileNameNotSupported(
76+
f"Datatype '{file.suffix}' for file {file} is not supported without the "
77+
f"`--experimental-datatypes` flag. "
78+
)
79+
6480
if not kleinkram.utils.check_filename_is_sanatized(file.stem):
6581
raise FileNameNotSupported(
6682
f"Only `{''.join(kleinkram.utils.INTERNAL_ALLOWED_CHARS)}` are "

cli/kleinkram/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
SUPPORT_FILE_TYPES = [
3232
".bag",
3333
".mcap",
34+
".db3",
35+
".svo2",
36+
".tum",
37+
".yaml"
3438
]
3539

3640

common/frontend_shared/enum.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export enum CookieNames {
100100
export enum FileType {
101101
BAG = 'BAG',
102102
MCAP = 'MCAP',
103+
YAML = 'YAML',
104+
SVO2 = 'SVO2',
105+
TUM = 'TUM',
106+
DB3 = 'DB3',
103107
ALL = 'ALL',
104108
}
105109

0 commit comments

Comments
 (0)