mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Prevent generated metadata from being stored
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { namedNode } from '@rdfjs/data-model';
|
||||
import { SOLID_META } from '../../util/Vocabularies';
|
||||
import type { RepresentationMetadata } from '../representation/RepresentationMetadata';
|
||||
import type { AuxiliaryIdentifierStrategy } from './AuxiliaryIdentifierStrategy';
|
||||
import { MetadataGenerator } from './MetadataGenerator';
|
||||
@@ -22,7 +23,9 @@ export class LinkMetadataGenerator extends MetadataGenerator {
|
||||
public async handle(metadata: RepresentationMetadata): Promise<void> {
|
||||
const identifier = { path: metadata.identifier.value };
|
||||
if (!this.identifierStrategy.isAuxiliaryIdentifier(identifier)) {
|
||||
metadata.add(this.link, namedNode(this.identifierStrategy.getAuxiliaryIdentifier(identifier).path));
|
||||
metadata.add(this.link,
|
||||
namedNode(this.identifierStrategy.getAuxiliaryIdentifier(identifier).path),
|
||||
SOLID_META.terms.ResponseMetadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,18 @@ import {
|
||||
} from '../util/PathUtil';
|
||||
import { parseQuads } from '../util/QuadUtil';
|
||||
import { addResourceMetadata } from '../util/ResourceUtil';
|
||||
import { CONTENT_TYPE, DC, SOLID_HTTP, LDP, POSIX, PIM, RDF, VANN, XSD } from '../util/Vocabularies';
|
||||
import {
|
||||
CONTENT_TYPE,
|
||||
DC,
|
||||
SOLID_HTTP,
|
||||
LDP,
|
||||
POSIX,
|
||||
PIM,
|
||||
RDF,
|
||||
XSD,
|
||||
SOLID_META,
|
||||
PREFERRED_PREFIX_TERM,
|
||||
} from '../util/Vocabularies';
|
||||
import type { DataAccessor } from './accessors/DataAccessor';
|
||||
import type { ResourceStore } from './ResourceStore';
|
||||
|
||||
@@ -98,16 +109,23 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
for await (const child of this.accessor.getChildren(identifier)) {
|
||||
if (!this.auxiliaryStrategy.isAuxiliaryIdentifier({ path: child.identifier.value })) {
|
||||
metadata.addQuads(child.quads());
|
||||
metadata.add(LDP.terms.contains, child.identifier as NamedNode);
|
||||
metadata.add(LDP.terms.contains, child.identifier as NamedNode, SOLID_META.terms.ResponseMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a container representation from the metadata
|
||||
const data = metadata.quads();
|
||||
metadata.addQuad(DC.terms.namespace, VANN.terms.preferredNamespacePrefix, 'dc');
|
||||
metadata.addQuad(LDP.terms.namespace, VANN.terms.preferredNamespacePrefix, 'ldp');
|
||||
metadata.addQuad(POSIX.terms.namespace, VANN.terms.preferredNamespacePrefix, 'posix');
|
||||
metadata.addQuad(XSD.terms.namespace, VANN.terms.preferredNamespacePrefix, 'xsd');
|
||||
// All triples should be in the same graph for the data representation
|
||||
const data = metadata.quads().map((triple): Quad => {
|
||||
if (triple.graph.termType === 'DefaultGraph') {
|
||||
return triple;
|
||||
}
|
||||
return DataFactory.quad(triple.subject, triple.predicate, triple.object);
|
||||
});
|
||||
|
||||
metadata.addQuad(DC.terms.namespace, PREFERRED_PREFIX_TERM, 'dc', SOLID_META.terms.ResponseMetadata);
|
||||
metadata.addQuad(LDP.terms.namespace, PREFERRED_PREFIX_TERM, 'ldp', SOLID_META.terms.ResponseMetadata);
|
||||
metadata.addQuad(POSIX.terms.namespace, PREFERRED_PREFIX_TERM, 'posix', SOLID_META.terms.ResponseMetadata);
|
||||
metadata.addQuad(XSD.terms.namespace, PREFERRED_PREFIX_TERM, 'xsd', SOLID_META.terms.ResponseMetadata);
|
||||
representation = new BasicRepresentation(data, metadata, INTERNAL_QUADS);
|
||||
} else {
|
||||
// Retrieve a document representation from the accessor
|
||||
@@ -317,6 +335,11 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all generated metadata to prevent it from being stored permanently
|
||||
representation.metadata.removeQuads(
|
||||
representation.metadata.quads(null, null, null, SOLID_META.terms.ResponseMetadata),
|
||||
);
|
||||
|
||||
await (isContainer ?
|
||||
this.accessor.writeContainer(identifier, representation.metadata) :
|
||||
this.accessor.writeDocument(identifier, representation.data, representation.metadata));
|
||||
|
||||
@@ -15,7 +15,7 @@ import { joinFilePath, isContainerIdentifier } from '../../util/PathUtil';
|
||||
import { parseQuads, serializeQuads } from '../../util/QuadUtil';
|
||||
import { addResourceMetadata } from '../../util/ResourceUtil';
|
||||
import { toLiteral } from '../../util/TermUtil';
|
||||
import { CONTENT_TYPE, DC, LDP, POSIX, RDF, XSD } from '../../util/Vocabularies';
|
||||
import { CONTENT_TYPE, DC, LDP, POSIX, RDF, SOLID_META, XSD } from '../../util/Vocabularies';
|
||||
import type { FileIdentifierMapper, ResourceLink } from '../mapping/FileIdentifierMapper';
|
||||
import type { DataAccessor } from './DataAccessor';
|
||||
|
||||
@@ -319,10 +319,14 @@ export class FileDataAccessor implements DataAccessor {
|
||||
* @param stats - Stats of the file/directory corresponding to the resource.
|
||||
*/
|
||||
private addPosixMetadata(metadata: RepresentationMetadata, stats: Stats): void {
|
||||
metadata.add(DC.terms.modified, toLiteral(stats.mtime.toISOString(), XSD.terms.dateTime));
|
||||
metadata.add(POSIX.terms.mtime, toLiteral(Math.floor(stats.mtime.getTime() / 1000), XSD.terms.integer));
|
||||
metadata.add(DC.terms.modified,
|
||||
toLiteral(stats.mtime.toISOString(), XSD.terms.dateTime),
|
||||
SOLID_META.terms.ResponseMetadata);
|
||||
metadata.add(POSIX.terms.mtime,
|
||||
toLiteral(Math.floor(stats.mtime.getTime() / 1000), XSD.terms.integer),
|
||||
SOLID_META.terms.ResponseMetadata);
|
||||
if (!stats.isDirectory()) {
|
||||
metadata.add(POSIX.terms.size, toLiteral(stats.size, XSD.terms.integer));
|
||||
metadata.add(POSIX.terms.size, toLiteral(stats.size, XSD.terms.integer), SOLID_META.terms.ResponseMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,11 @@ export const SOLID_HTTP = createUriAndTermNamespace('urn:npm:solid:community-ser
|
||||
'slug',
|
||||
);
|
||||
|
||||
export const SOLID_META = createUriAndTermNamespace('urn:npm:solid:community-server:meta:',
|
||||
// This identifier is used as graph for all metadata that is generated on the fly and should not be stored
|
||||
'ResponseMetadata',
|
||||
);
|
||||
|
||||
export const VANN = createUriAndTermNamespace('http://purl.org/vocab/vann/',
|
||||
'preferredNamespacePrefix',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user