Skip to content

Commit 3327b2e

Browse files
committed
fix: webhook bucket for copy/move cross buckets
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent 9bcc4dd commit 3327b2e

2 files changed

Lines changed: 79 additions & 2 deletions

File tree

src/storage/object.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export class ObjectStorage {
404404
tenant: this.db.tenant(),
405405
name: destinationKey,
406406
version: newVersion,
407-
bucketId: this.bucketId,
407+
bucketId: destinationBucket,
408408
metadata,
409409
reqId: this.db.reqId,
410410
})
@@ -537,7 +537,7 @@ export class ObjectStorage {
537537
tenant: this.db.tenant(),
538538
name: destinationObjectName,
539539
version: newVersion,
540-
bucketId: this.bucketId,
540+
bucketId: destinationBucket,
541541
metadata: metadata,
542542
oldObject: {
543543
name: sourceObjectName,

src/test/webhooks.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,47 @@ describe('Webhooks', () => {
251251
)
252252
})
253253

254+
it('will emit destination bucket in ObjectCreated:Move payload for cross-bucket moves', async () => {
255+
const obj = await createObject(pg, 'bucket6')
256+
const destinationKey = `${obj.name}-moved-${randomUUID()}`
257+
258+
const authorization = `Bearer ${await serviceKeyAsync}`
259+
const response = await appInstance.inject({
260+
method: 'POST',
261+
url: `/object/move`,
262+
headers: {
263+
authorization,
264+
},
265+
payload: {
266+
bucketId: 'bucket6',
267+
sourceKey: obj.name,
268+
destinationBucket: 'bucket2',
269+
destinationKey,
270+
},
271+
})
272+
273+
expect(response.statusCode).toBe(200)
274+
expect(sendSpy).toBeCalledTimes(3)
275+
expect(sendSpy).toHaveBeenNthCalledWith(
276+
3,
277+
expect.objectContaining({
278+
data: expect.objectContaining({
279+
event: expect.objectContaining({
280+
type: 'ObjectCreated:Move',
281+
payload: expect.objectContaining({
282+
bucketId: 'bucket2',
283+
name: destinationKey,
284+
oldObject: expect.objectContaining({
285+
bucketId: 'bucket6',
286+
name: obj.name,
287+
}),
288+
}),
289+
}),
290+
}),
291+
})
292+
)
293+
})
294+
254295
it('will emit a webhook upon object copied', async () => {
255296
const obj = await createObject(pg, 'bucket6')
256297

@@ -310,6 +351,42 @@ describe('Webhooks', () => {
310351
})
311352
)
312353
})
354+
355+
it('will emit destination bucket in ObjectCreated:Copy payload for cross-bucket copies', async () => {
356+
const obj = await createObject(pg, 'bucket6')
357+
const destinationKey = `${obj.name}-copied-${randomUUID()}`
358+
359+
const authorization = `Bearer ${await serviceKeyAsync}`
360+
const response = await appInstance.inject({
361+
method: 'POST',
362+
url: `/object/copy`,
363+
headers: {
364+
authorization,
365+
},
366+
payload: {
367+
bucketId: 'bucket6',
368+
sourceKey: obj.name,
369+
destinationBucket: 'bucket2',
370+
destinationKey,
371+
},
372+
})
373+
374+
expect(response.statusCode).toBe(200)
375+
expect(sendSpy).toBeCalledTimes(1)
376+
expect(sendSpy).toHaveBeenCalledWith(
377+
expect.objectContaining({
378+
data: expect.objectContaining({
379+
event: expect.objectContaining({
380+
type: 'ObjectCreated:Copy',
381+
payload: expect.objectContaining({
382+
bucketId: 'bucket2',
383+
name: destinationKey,
384+
}),
385+
}),
386+
}),
387+
})
388+
)
389+
})
313390
})
314391

315392
async function createObject(pg: TenantConnection, bucketId: string) {

0 commit comments

Comments
 (0)