Skip to content

Commit

Permalink
fix: determine File.contentType from File.value
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Dec 12, 2023
1 parent efc8bcb commit 75b27ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions projects/aas-server/src/app/packages/json-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Logger } from '../logging/logger.js';
import { AASReader } from './aas-reader.js';
import { aas, determineType, isIdentifiable } from 'common';
import { aas, determineType, extensionToMimeType, isIdentifiable } from 'common';
import { cloneDeep } from 'lodash-es';
import { encodeBase64Url } from '../convert.js';

Expand Down Expand Up @@ -388,8 +388,18 @@ export class JsonReader extends AASReader {
}

private readFile(source: aas.File, ancestors?: aas.Referable[]): aas.File {
if (!source.contentType) {
throw new Error('File.contentType');
if (!source.contentType && source.value) {
let contentType: string | undefined;
const i = source.value.lastIndexOf('.');
if (i >= 0) {
contentType = extensionToMimeType(source.value.substring(i));
}

if (!contentType) {
throw new Error('File.contentType');
}

source.contentType = contentType;
}

const file: aas.File = {
Expand Down

0 comments on commit 75b27ba

Please sign in to comment.