Skip to content

Commit 3fa2be9

Browse files
committed
fix: Activity is as:Add on Container POST
Notification emitted when a resource is created as a result of POST on a container has activity type set to `as:Add`.
1 parent 568b58a commit 3fa2be9

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/handlers/notify.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ function getParent (path) {
1717
return parent === '/' ? '/' : `${parent}/`
1818
}
1919

20-
function getActivity (method) {
20+
function getActivity (method, path) {
2121
if (method === 'DELETE') {
2222
return 'Delete'
2323
}
24+
if (method === 'POST' && path.endsWith('/')) {
25+
return 'Add'
26+
}
2427
return 'Update'
2528
}
2629

@@ -37,10 +40,10 @@ function getParentActivity (method, status) {
3740
function handler (req, res, next) {
3841
const { trigger, defaultNotification } = res.events.prep
3942

40-
const { method } = req
43+
const { method, path } = req
4144
const { statusCode } = res
4245
const eventID = res.getHeader('event-id')
43-
const fullUrl = new URL(req.path, `${req.protocol}://${req.hostname}/`)
46+
const fullUrl = new URL(path, `${req.protocol}://${req.hostname}/`)
4447

4548
// Date is a hack since node does not seem to provide access to send date.
4649
// Date needs to be shared with parent notification
@@ -56,10 +59,10 @@ function handler (req, res, next) {
5659
negotiatedFields
5760
) {
5861
const mediaType = negotiatedFields['content-type']
59-
62+
const activity = getActivity(method, path)
6063
if (ALLOWED_RDF_MIME_TYPES.includes(mediaType?.[0])) {
6164
return `${headerTemplate(negotiatedFields)}\r\n${solidRDFTemplate({
62-
activity: getActivity(method),
65+
activity,
6366
eventID,
6467
object: String(fullUrl),
6568
date: eventDate,
@@ -81,7 +84,7 @@ function handler (req, res, next) {
8184

8285
// Write a notification to parent container
8386
// POST in Solid creates a child resource
84-
const parent = getParent(req.path)
87+
const parent = getParent(path)
8588
if (parent && method !== 'POST') {
8689
try {
8790
const parentID = res.setEventID(parent)

test/integration/prep-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ solid:inserts { <u> <v> <z>. }.`
142142
expect(value.headers.get('content-type')).to.match(/application\/ld\+json/)
143143
const notification = await value.json()
144144
expect(notification).to.haveOwnProperty('published')
145-
expect(notification.type).to.equal('Update')
145+
expect(notification.type).to.equal('Add')
146146
expect(notification.object).to.match(/sampleContainer\/$/)
147147
controller.abort()
148148
})

0 commit comments

Comments
 (0)