mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Keep track of last modified date of resources
This commit is contained in:
@@ -3,8 +3,9 @@ import { BasicRepresentation } from '../ldp/representation/BasicRepresentation';
|
||||
import type { Representation } from '../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata';
|
||||
import { guardedStreamFrom } from './StreamUtil';
|
||||
import { toLiteral } from './TermUtil';
|
||||
|
||||
import { LDP, RDF } from './Vocabularies';
|
||||
import { DC, LDP, RDF, XSD } from './Vocabularies';
|
||||
|
||||
/**
|
||||
* Helper function to generate type quads for a Container or Resource.
|
||||
@@ -21,6 +22,18 @@ export function addResourceMetadata(metadata: RepresentationMetadata, isContaine
|
||||
metadata.add(RDF.terms.type, LDP.terms.Resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the dc:modified time to the given time.
|
||||
* @param metadata - Metadata to update.
|
||||
* @param date - Last modified date. Defaults to current time.
|
||||
*/
|
||||
export function updateModifiedDate(metadata: RepresentationMetadata, date = new Date()): void {
|
||||
// Milliseconds get lost in some serializations, potentially causing mismatches
|
||||
const lastModified = new Date(date);
|
||||
lastModified.setMilliseconds(0);
|
||||
metadata.set(DC.terms.modified, toLiteral(lastModified.toISOString(), XSD.terms.dateTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to clone a representation, the original representation can still be used.
|
||||
* This function loads the entire stream in memory.
|
||||
|
||||
Reference in New Issue
Block a user