Skip to content

Commit 3bc0aec

Browse files
committed
fix: rename bucketName -> bucketId in copy and move
1 parent 1c1d9ae commit 3bc0aec

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/routes/object/copyObject.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const copyRequestBodySchema = {
1313
type: 'object',
1414
properties: {
1515
sourceKey: { type: 'string', example: 'folder/source.png' },
16-
bucketName: { type: 'string', example: 'avatars' },
16+
bucketId: { type: 'string', example: 'avatars' },
1717
destinationKey: { type: 'string', example: 'folder/destination.png' },
1818
},
19-
required: ['sourceKey', 'bucketName', 'destinationKey'],
19+
required: ['sourceKey', 'bucketId', 'destinationKey'],
2020
} as const
2121
const successResponseSchema = {
2222
type: 'object',
@@ -48,11 +48,11 @@ export default async function routes(fastify: FastifyInstance) {
4848
const authHeader = request.headers.authorization
4949
const jwt = authHeader.substring('Bearer '.length)
5050

51-
const { sourceKey, destinationKey, bucketName } = request.body
51+
const { sourceKey, destinationKey, bucketId } = request.body
5252
request.log.info(
5353
'sourceKey is %s and bucketName is %s and destinationKey is %s',
5454
sourceKey,
55-
bucketName,
55+
bucketId,
5656
destinationKey
5757
)
5858

@@ -82,7 +82,7 @@ export default async function routes(fastify: FastifyInstance) {
8282
.select('bucket_id, metadata')
8383
.match({
8484
name: sourceKey,
85-
bucket_id: bucketName,
85+
bucket_id: bucketId,
8686
})
8787
.single()
8888

@@ -112,11 +112,11 @@ export default async function routes(fastify: FastifyInstance) {
112112
}
113113
request.log.info({ results }, 'results')
114114

115-
const s3SourceKey = `${projectRef}/${bucketName}/${sourceKey}`
116-
const s3DestinationKey = `${projectRef}/${bucketName}/${destinationKey}`
115+
const s3SourceKey = `${projectRef}/${bucketId}/${sourceKey}`
116+
const s3DestinationKey = `${projectRef}/${bucketId}/${destinationKey}`
117117
const copyResult = await copyObject(client, globalS3Bucket, s3SourceKey, s3DestinationKey)
118118
return response.status(copyResult.$metadata.httpStatusCode ?? 200).send({
119-
Key: `${bucketName}/${destinationKey}`,
119+
Key: `${bucketId}/${destinationKey}`,
120120
})
121121
}
122122
)

src/routes/object/moveObject.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const client = initClient(region, globalS3Endpoint)
1212
const moveObjectsBodySchema = {
1313
type: 'object',
1414
properties: {
15-
bucketName: { type: 'string', example: 'avatars' },
15+
bucketId: { type: 'string', example: 'avatars' },
1616
sourceKey: { type: 'string', example: 'folder/cat.png' },
1717
destinationKey: { type: 'string', example: 'folder/newcat.png' },
1818
},
19-
required: ['bucketName', 'sourceKey', 'destinationKey'],
19+
required: ['bucketId', 'sourceKey', 'destinationKey'],
2020
} as const
2121
const successResponseSchema = {
2222
type: 'object',
@@ -49,7 +49,7 @@ export default async function routes(fastify: FastifyInstance) {
4949
const authHeader = request.headers.authorization
5050
const jwt = authHeader.substring('Bearer '.length)
5151

52-
const { destinationKey, sourceKey, bucketName } = request.body
52+
const { destinationKey, sourceKey, bucketId } = request.body
5353

5454
if (!isValidKey(destinationKey)) {
5555
return response
@@ -67,7 +67,7 @@ export default async function routes(fastify: FastifyInstance) {
6767
last_accessed_at: new Date().toISOString(),
6868
name: destinationKey,
6969
})
70-
.match({ bucket_id: bucketName, name: sourceKey })
70+
.match({ bucket_id: bucketId, name: sourceKey })
7171
.single()
7272

7373
if (objectResponse.error) {
@@ -77,8 +77,8 @@ export default async function routes(fastify: FastifyInstance) {
7777
}
7878

7979
// if successfully updated, copy and delete object from s3
80-
const oldS3Key = `${projectRef}/${bucketName}/${sourceKey}`
81-
const newS3Key = `${projectRef}/${bucketName}/${destinationKey}`
80+
const oldS3Key = `${projectRef}/${bucketId}/${sourceKey}`
81+
const newS3Key = `${projectRef}/${bucketId}/${destinationKey}`
8282

8383
// @todo what happens if one of these fail?
8484
await copyObject(client, globalS3Bucket, oldS3Key, newS3Key)

src/test/object.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe('testing copy object', () => {
344344
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
345345
},
346346
payload: {
347-
bucketName: 'bucket2',
347+
bucketId: 'bucket2',
348348
sourceKey: 'authenticated/casestudy.png',
349349
destinationKey: 'authenticated/casestudy11.png',
350350
},
@@ -362,7 +362,7 @@ describe('testing copy object', () => {
362362
authorization: `Bearer ${anonKey}`,
363363
},
364364
payload: {
365-
bucketName: 'bucket2',
365+
bucketId: 'bucket2',
366366
sourceKey: 'authenticated/casestudy.png',
367367
destinationKey: 'authenticated/casestudy11.png',
368368
},
@@ -376,7 +376,7 @@ describe('testing copy object', () => {
376376
method: 'POST',
377377
url: '/object/copy',
378378
payload: {
379-
bucketName: 'bucket2',
379+
bucketId: 'bucket2',
380380
sourceKey: 'authenticated/casestudy.png',
381381
destinationKey: 'authenticated/casestudy11.png',
382382
},
@@ -393,7 +393,7 @@ describe('testing copy object', () => {
393393
authorization: `Bearer ${anonKey}`,
394394
},
395395
payload: {
396-
bucketName: 'notfound',
396+
bucketId: 'notfound',
397397
sourceKey: 'authenticated/casestudy.png',
398398
destinationKey: 'authenticated/casestudy11.png',
399399
},
@@ -410,7 +410,7 @@ describe('testing copy object', () => {
410410
authorization: `Bearer ${anonKey}`,
411411
},
412412
payload: {
413-
bucketName: 'bucket2',
413+
bucketId: 'bucket2',
414414
sourceKey: 'authenticated/notfound.png',
415415
destinationKey: 'authenticated/casestudy11.png',
416416
},
@@ -708,7 +708,7 @@ describe('testing move object', () => {
708708
payload: {
709709
sourceKey: 'authenticated/move-orig.png',
710710
destinationKey: 'authenticated/move-new.png',
711-
bucketName: 'bucket2',
711+
bucketId: 'bucket2',
712712
},
713713
headers: {
714714
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
@@ -726,7 +726,7 @@ describe('testing move object', () => {
726726
payload: {
727727
sourceKey: 'authenticated/move-orig-2.png',
728728
destinationKey: 'authenticated/move-new-2.png',
729-
bucketName: 'bucket2',
729+
bucketId: 'bucket2',
730730
},
731731
headers: {
732732
authorization: `Bearer ${anonKey}`,
@@ -744,7 +744,7 @@ describe('testing move object', () => {
744744
payload: {
745745
sourceKey: 'authenticated/move-orig-3.png',
746746
destinationKey: 'authenticated/move-orig-new-3.png',
747-
bucketName: 'bucket2',
747+
bucketId: 'bucket2',
748748
},
749749
})
750750
expect(response.statusCode).toBe(400)
@@ -759,7 +759,7 @@ describe('testing move object', () => {
759759
payload: {
760760
sourceKey: 'authenticated/move-orig-3.png',
761761
destinationKey: 'authenticated/move-orig-new-3.png',
762-
bucketName: 'notfound',
762+
bucketId: 'notfound',
763763
},
764764
headers: {
765765
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
@@ -777,7 +777,7 @@ describe('testing move object', () => {
777777
payload: {
778778
sourceKey: 'authenticated/notfound',
779779
destinationKey: 'authenticated/move-orig-new-3.png',
780-
bucketName: 'bucket2',
780+
bucketId: 'bucket2',
781781
},
782782
headers: {
783783
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
@@ -795,7 +795,7 @@ describe('testing move object', () => {
795795
payload: {
796796
sourceKey: 'authenticated/move-orig-2.png',
797797
destinationKey: 'authenticated/move-orig-3.png',
798-
bucketName: 'bucket2',
798+
bucketId: 'bucket2',
799799
},
800800
headers: {
801801
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,

0 commit comments

Comments
 (0)