Skip to content

Commit 678abe3

Browse files
committed
process meta consistently
1 parent a3e6abf commit 678abe3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

packages/s3-file-storage/src/lib/s3-file-storage.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,22 @@ export class S3FileStorage implements FileStorage {
271271
}
272272

273273
private extractMetadata(key: string, headers: Headers): FileMetadata {
274-
const lastModifiedHeader = headers.get('last-modified');
275-
const lastModified = lastModifiedHeader ? new Date(lastModifiedHeader).getTime() : Date.now();
274+
const metadataLastModified = headers.get('x-amz-meta-lastModified');
275+
const lastModifiedHeader = headers.get('last-modified')!;
276+
const lastModified = metadataLastModified ? parseInt(metadataLastModified) : new Date(lastModifiedHeader).getTime();
276277

277-
const metadataName = headers.get('x-amz-meta-name') || '';
278-
const metadataLastModified = headers.get('x-amz-meta-lastModified') || '';
279-
const metadataType = headers.get('x-amz-meta-type') || '';
278+
let name = headers.get('x-amz-meta-name');
279+
if (!name) {
280+
name = key.split('/').pop() || key;
281+
}
282+
const type = headers.get('x-amz-meta-type') || headers.get('content-type') || '';
280283

281284
return {
282285
key,
283-
name: metadataName,
284-
lastModified: parseInt(metadataLastModified, 10) || lastModified,
285-
type: metadataType,
286-
size: parseInt(headers.get('content-length') || '0', 10),
286+
name,
287+
lastModified,
288+
type,
289+
size: parseInt(headers.get('content-length') || '0'),
287290
};
288291
}
289292

@@ -308,9 +311,6 @@ export class S3FileStorage implements FileStorage {
308311
type,
309312
size
310313
} = this.extractMetadata(key, initial.headers);
311-
312-
// Try to get the file name from metadata
313-
const fileName = name || key.split('/').pop() || key;
314314

315315
// Store AWS client and key in variables that can be captured by the closure
316316
const aws = this.aws;
@@ -369,7 +369,7 @@ export class S3FileStorage implements FileStorage {
369369

370370
return new LazyFile(
371371
lazyContent,
372-
fileName,
372+
name,
373373
{
374374
type,
375375
lastModified

0 commit comments

Comments
 (0)