Skip to content

Commit ef702d0

Browse files
committed
fix directory copy functionality information retrieval
1 parent bb14e95 commit ef702d0

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

src/s3.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -583,26 +583,41 @@ export const copyS3Objects = async (
583583
registeredFileTypes
584584
);
585585

586-
// retrieve information of new file
587-
const newFileContents = await s3Client.send(
588-
new GetObjectCommand({
589-
Bucket: newBucketName ?? bucketName,
590-
Key: name + (suffix ? suffix : '')
591-
})
592-
);
586+
try {
587+
const newFileContents = await s3Client.send(
588+
new GetObjectCommand({
589+
Bucket: newBucketName ?? bucketName,
590+
Key: name + (suffix ? suffix : '')
591+
})
592+
);
593593

594-
data = {
595-
name: PathExt.basename(name),
596-
path: name,
597-
last_modified: newFileContents.LastModified!.toISOString(),
598-
created: new Date().toISOString(),
599-
content: await newFileContents.Body!.transformToString(),
600-
format: fileFormat as Contents.FileFormat,
601-
mimetype: fileMimeType,
602-
size: newFileContents.ContentLength!,
603-
writable: true,
604-
type: fileType
605-
};
594+
data = {
595+
name: PathExt.basename(name),
596+
path: name,
597+
last_modified: newFileContents.LastModified!.toISOString(),
598+
created: new Date().toISOString(),
599+
content: await newFileContents.Body!.transformToString(),
600+
format: fileFormat as Contents.FileFormat,
601+
mimetype: fileMimeType,
602+
size: newFileContents.ContentLength!,
603+
writable: true,
604+
type: fileType
605+
};
606+
} catch {
607+
// object directory itself doesn't exist
608+
data = {
609+
name: PathExt.basename(name),
610+
path: name,
611+
last_modified: new Date().toISOString(),
612+
created: new Date().toISOString(),
613+
content: [],
614+
format: fileFormat as Contents.FileFormat,
615+
mimetype: fileMimeType,
616+
size: 0,
617+
writable: true,
618+
type: fileType
619+
};
620+
}
606621

607622
return data;
608623
};

0 commit comments

Comments
 (0)