@@ -38,18 +38,32 @@ function getParentActivity (method, status) {
38
38
return 'Update'
39
39
}
40
40
41
+ function filterMillseconds ( isoDate ) {
42
+ return `${ isoDate . substring ( 0 , 19 ) } ${ isoDate . substring ( 23 ) } `
43
+ }
44
+
45
+ function getDate ( date ) {
46
+ if ( date ) {
47
+ const eventDate = new Date ( date )
48
+ if ( ! isNaN ( eventDate . valueOf ( ) ) ) {
49
+ return filterMillseconds ( eventDate . toISOString ( ) )
50
+ }
51
+ }
52
+ const now = new Date ( )
53
+ return filterMillseconds ( now . toISOString ( ) )
54
+ }
55
+
41
56
function handler ( req , res , next ) {
42
57
const { trigger, defaultNotification } = res . events . prep
43
58
44
59
const { method, path } = req
45
60
const { statusCode } = res
46
- const eventID = res . getHeader ( 'event-id' )
61
+ const eventID = res . setEventID ( )
47
62
const fullUrl = new URL ( path , `${ req . protocol } ://${ req . hostname } /` )
48
63
49
64
// Date is a hack since node does not seem to provide access to send date.
50
65
// Date needs to be shared with parent notification
51
- const eventDate = res . _header . match ( / ^ D a t e : ( .* ?) $ / m) ?. [ 1 ] ||
52
- new Date ( ) . toUTCString ( )
66
+ const eventDate = getDate ( res . _header . match ( / ^ D a t e : ( .* ?) $ / m) ?. [ 1 ] )
53
67
54
68
// If the resource itself newly created,
55
69
// it could not have been subscribed for notifications already
@@ -61,18 +75,19 @@ function handler (req, res, next) {
61
75
) {
62
76
const mediaType = negotiatedFields [ 'content-type' ]
63
77
const activity = getActivity ( method , path )
64
- const target = activity === 'Add'
78
+ const object = activity === 'Add'
65
79
? res . getHeader ( 'location' )
80
+ : String ( fullUrl )
81
+ const target = activity === 'Add'
82
+ ? String ( fullUrl )
66
83
: undefined
67
84
if ( ALLOWED_RDF_MIME_TYPES . includes ( mediaType ?. [ 0 ] ) ) {
68
85
return `${ headerTemplate ( negotiatedFields ) } \r\n${ solidRDFTemplate ( {
69
86
activity,
70
87
eventID,
71
- object : String ( fullUrl ) ,
88
+ object,
72
89
target,
73
90
date : eventDate ,
74
- // We use eTag as a proxy for state for now
75
- state : res . getHeader ( 'ETag' ) ,
76
91
mediaType
77
92
} ) } `
78
93
} else {
@@ -93,7 +108,10 @@ function handler (req, res, next) {
93
108
// POST in Solid creates a child resource
94
109
const parent = getParent ( path )
95
110
if ( parent && method !== 'POST' ) {
96
- const parentID = res . setEventID ( parent )
111
+ res . setEventID ( {
112
+ path : parent ,
113
+ id : eventID
114
+ } )
97
115
const parentUrl = new URL ( parent , fullUrl )
98
116
try {
99
117
trigger ( {
@@ -103,15 +121,15 @@ function handler (req, res, next) {
103
121
) {
104
122
const mediaType = negotiatedFields [ 'content-type' ]
105
123
const activity = getParentActivity ( method , statusCode )
106
- const target = activity !== 'Update' ? String ( fullUrl ) : undefined
124
+ const object = activity === 'Update' ? String ( parentUrl ) : String ( fullUrl )
125
+ const target = activity === 'Update' ? undefined : String ( parentUrl )
107
126
if ( ALLOWED_RDF_MIME_TYPES . includes ( mediaType ?. [ 0 ] ) ) {
108
127
return `${ headerTemplate ( negotiatedFields ) } \r\n${ solidRDFTemplate ( {
109
128
activity,
110
- eventID : parentID ,
129
+ eventID,
111
130
date : eventDate ,
112
- object : String ( parentUrl ) ,
131
+ object,
113
132
target,
114
- eTag : undefined ,
115
133
mediaType
116
134
} ) } `
117
135
}
0 commit comments