Skip to content

Commit f0e4804

Browse files
committed
Fix issues where bulk copy fails.
1 parent 9b15976 commit f0e4804

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

src/storage/object/copy.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import { putObjectWithVersion } from '../version/put.js';
2121
import { listCommand } from '../utils/list.js';
2222
import { hasPermission } from '../../utils/auth.js';
2323

24-
const MAX_KEYS = 900;
24+
const MAX_KEYS = 2;
2525

2626
export const copyFile = async (config, env, daCtx, sourceKey, details, isRename) => {
2727
const Key = `${sourceKey.replace(details.source, details.destination)}`;
28-
2928
if (!hasPermission(daCtx, sourceKey, 'read') || !hasPermission(daCtx, Key, 'write')) {
3029
return {
3130
$metadata: {
@@ -81,11 +80,12 @@ export const copyFile = async (config, env, daCtx, sourceKey, details, isRename)
8180
env,
8281
{ bucket: daCtx.bucket, org: daCtx.org, key: sourceKey },
8382
);
83+
const body = await original.body.transformToString();
8484
return /* await */ putObjectWithVersion(env, daCtx, {
8585
bucket: daCtx.bucket,
8686
org: daCtx.org,
8787
key: Key,
88-
body: original.body,
88+
body,
8989
contentLength: original.contentLength,
9090
type: original.contentType,
9191
});
@@ -105,7 +105,7 @@ export const copyFile = async (config, env, daCtx, sourceKey, details, isRename)
105105
} finally {
106106
if (Key.endsWith('.html')) {
107107
// Reset the collab cached state for the copied object
108-
await invalidateCollab('syncAdmin', `${daCtx.origin}/source/${daCtx.org}/${Key}`, env);
108+
await invalidateCollab('syncadmin', `${daCtx.origin}/source/${daCtx.org}/${Key}`, env);
109109
}
110110
}
111111
};

src/storage/utils/version.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,8 @@ import {
1313
S3Client,
1414
} from '@aws-sdk/client-s3';
1515

16-
export function createBucketIfMissing(client) {
17-
client.middlewareStack.add(
18-
(next) => async (args) => {
19-
// eslint-disable-next-line no-param-reassign
20-
args.request.headers['cf-create-bucket-if-missing'] = 'true';
21-
return next(args);
22-
},
23-
{
24-
step: 'build',
25-
name: 'createIfMissingMiddleware',
26-
tags: ['METADATA', 'CREATE-BUCKET-IF-MISSING'],
27-
},
28-
);
29-
return client;
30-
}
31-
3216
export function ifNoneMatch(config) {
3317
const client = new S3Client(config);
34-
createBucketIfMissing(client);
3518
client.middlewareStack.add(
3619
(next) => async (args) => {
3720
// eslint-disable-next-line no-param-reassign
@@ -49,7 +32,6 @@ export function ifNoneMatch(config) {
4932

5033
export function ifMatch(config, match) {
5134
const client = new S3Client(config);
52-
createBucketIfMissing(client);
5335
client.middlewareStack.add(
5436
(next) => async (args) => {
5537
// eslint-disable-next-line no-param-reassign

src/storage/version/put.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import getS3Config from '../utils/config.js';
1818
import {
19-
createBucketIfMissing, ifMatch, ifNoneMatch,
19+
ifMatch, ifNoneMatch,
2020
} from '../utils/version.js';
2121
import getObject from '../object/get.js';
2222

@@ -39,7 +39,7 @@ export async function putVersion(config, {
3939
}, noneMatch = true) {
4040
const length = ContentLength ?? getContentLength(Body);
4141

42-
const client = noneMatch ? ifNoneMatch(config) : createBucketIfMissing(new S3Client(config));
42+
const client = noneMatch ? ifNoneMatch(config) : new S3Client(config);
4343
const input = {
4444
Bucket, Key: `${Org}/.da-versions/${ID}/${Version}.${Ext}`, Body, Metadata, ContentLength: length,
4545
};
@@ -118,7 +118,6 @@ export async function putObjectWithVersion(env, daCtx, update, body) {
118118
Label,
119119
},
120120
});
121-
122121
if (versionResp.status !== 200 && versionResp.status !== 412) {
123122
return versionResp.status;
124123
}
@@ -132,7 +131,6 @@ export async function putObjectWithVersion(env, daCtx, update, body) {
132131
});
133132
try {
134133
const resp = await client.send(command);
135-
136134
return resp.$metadata.httpStatusCode;
137135
} catch (e) {
138136
if (e.$metadata.httpStatusCode === 412) {

0 commit comments

Comments
 (0)