@@ -38,18 +38,32 @@ function getParentActivity (method, status) {
3838 return 'Update'
3939}
4040
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+
4156function handler ( req , res , next ) {
4257 const { trigger, defaultNotification } = res . events . prep
4358
4459 const { method, path } = req
4560 const { statusCode } = res
46- const eventID = res . getHeader ( 'event-id' )
61+ const eventID = res . setEventID ( )
4762 const fullUrl = new URL ( path , `${ req . protocol } ://${ req . hostname } /` )
4863
4964 // Date is a hack since node does not seem to provide access to send date.
5065 // 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 ] )
5367
5468 // If the resource itself newly created,
5569 // it could not have been subscribed for notifications already
@@ -61,18 +75,19 @@ function handler (req, res, next) {
6175 ) {
6276 const mediaType = negotiatedFields [ 'content-type' ]
6377 const activity = getActivity ( method , path )
64- const target = activity === 'Add'
78+ const object = activity === 'Add'
6579 ? res . getHeader ( 'location' )
80+ : String ( fullUrl )
81+ const target = activity === 'Add'
82+ ? String ( fullUrl )
6683 : undefined
6784 if ( ALLOWED_RDF_MIME_TYPES . includes ( mediaType ?. [ 0 ] ) ) {
6885 return `${ headerTemplate ( negotiatedFields ) } \r\n${ solidRDFTemplate ( {
6986 activity,
7087 eventID,
71- object : String ( fullUrl ) ,
88+ object,
7289 target,
7390 date : eventDate ,
74- // We use eTag as a proxy for state for now
75- state : res . getHeader ( 'ETag' ) ,
7691 mediaType
7792 } ) } `
7893 } else {
@@ -93,7 +108,10 @@ function handler (req, res, next) {
93108 // POST in Solid creates a child resource
94109 const parent = getParent ( path )
95110 if ( parent && method !== 'POST' ) {
96- const parentID = res . setEventID ( parent )
111+ res . setEventID ( {
112+ path : parent ,
113+ id : eventID
114+ } )
97115 const parentUrl = new URL ( parent , fullUrl )
98116 try {
99117 trigger ( {
@@ -103,15 +121,15 @@ function handler (req, res, next) {
103121 ) {
104122 const mediaType = negotiatedFields [ 'content-type' ]
105123 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 )
107126 if ( ALLOWED_RDF_MIME_TYPES . includes ( mediaType ?. [ 0 ] ) ) {
108127 return `${ headerTemplate ( negotiatedFields ) } \r\n${ solidRDFTemplate ( {
109128 activity,
110- eventID : parentID ,
129+ eventID,
111130 date : eventDate ,
112- object : String ( parentUrl ) ,
131+ object,
113132 target,
114- eTag : undefined ,
115133 mediaType
116134 } ) } `
117135 }
0 commit comments