1
1
import type { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata' ;
2
+ import { DC } from '../util/Vocabularies' ;
2
3
3
4
/**
4
5
* The conditions of an HTTP conditional request.
@@ -7,11 +8,11 @@ export interface Conditions {
7
8
/**
8
9
* Valid if matching any of the given ETags.
9
10
*/
10
- matchesEtag : string [ ] ;
11
+ matchesETag ? : string [ ] ;
11
12
/**
12
13
* Valid if not matching any of the given ETags.
13
14
*/
14
- notMatchesEtag : string [ ] ;
15
+ notMatchesETag ? : string [ ] ;
15
16
/**
16
17
* Valid if modified since the given date.
17
18
*/
@@ -27,9 +28,23 @@ export interface Conditions {
27
28
*/
28
29
matchesMetadata : ( metadata : RepresentationMetadata ) => boolean ;
29
30
/**
30
- * Checks validity based on the given ETag and/org date.
31
+ * Checks validity based on the given ETag and/or date.
31
32
* @param eTag - Condition based on ETag.
32
33
* @param lastModified - Condition based on last modified date.
33
34
*/
34
35
matches : ( eTag ?: string , lastModified ?: Date ) => boolean ;
35
36
}
37
+
38
+ /**
39
+ * Generates an ETag based on the last modified date of a resource.
40
+ * @param metadata - Metadata of the resource.
41
+ *
42
+ * @returns the generated ETag. Undefined if no last modified date was found.
43
+ */
44
+ export function getETag ( metadata : RepresentationMetadata ) : string | undefined {
45
+ const modified = metadata . get ( DC . terms . modified ) ;
46
+ if ( modified ) {
47
+ const date = new Date ( modified . value ) ;
48
+ return `"${ date . getTime ( ) } "` ;
49
+ }
50
+ }
0 commit comments