fix: Add IANA type to child metadata in FileDataAccessor

This commit is contained in:
Joachim Van Herwegen
2022-03-22 11:28:36 +01:00
parent ad3edcf1a8
commit 7152897b89
3 changed files with 12 additions and 3 deletions

View File

@@ -13,8 +13,8 @@ import type { Guarded } from '../../util/GuardedStream';
import { joinFilePath, isContainerIdentifier } from '../../util/PathUtil';
import { parseQuads, serializeQuads } from '../../util/QuadUtil';
import { addResourceMetadata, updateModifiedDate } from '../../util/ResourceUtil';
import { toLiteral } from '../../util/TermUtil';
import { CONTENT_TYPE, DC, LDP, POSIX, RDF, SOLID_META, XSD } from '../../util/Vocabularies';
import { toLiteral, toNamedTerm } from '../../util/TermUtil';
import { CONTENT_TYPE, DC, IANA, LDP, POSIX, RDF, SOLID_META, XSD } from '../../util/Vocabularies';
import type { FileIdentifierMapper, ResourceLink } from '../mapping/FileIdentifierMapper';
import type { DataAccessor } from './DataAccessor';
@@ -297,10 +297,16 @@ export class FileDataAccessor implements DataAccessor {
continue;
}
// Generate metadata of this specific child
// Generate metadata of this specific child as described in
// https://solidproject.org/TR/2021/protocol-20211217#contained-resource-metadata
const metadata = new RepresentationMetadata(childLink.identifier);
addResourceMetadata(metadata, childStats.isDirectory());
this.addPosixMetadata(metadata, childStats);
// Containers will not have a content-type
if (childLink.contentType) {
metadata.add(RDF.terms.type, toNamedTerm(`${IANA.namespace}${childLink.contentType}#Resource`));
}
yield metadata;
}
}

View File

@@ -94,6 +94,8 @@ export const HTTP = createUriAndTermNamespace('http://www.w3.org/2011/http#',
'statusCodeNumber',
);
export const IANA = createUriAndTermNamespace('http://www.w3.org/ns/iana/media-types/');
export const LDP = createUriAndTermNamespace('http://www.w3.org/ns/ldp#',
'contains',

View File

@@ -176,6 +176,7 @@ describe('A FileDataAccessor', (): void => {
for (const child of children.filter(({ identifier }): boolean => !identifier.value.endsWith('/'))) {
const types = child.getAll(RDF.type).map((term): string => term.value);
expect(types).toContain(LDP.Resource);
expect(types).toContain('http://www.w3.org/ns/iana/media-types/application/octet-stream#Resource');
expect(types).not.toContain(LDP.Container);
expect(types).not.toContain(LDP.BasicContainer);
}