Skip to content

Commit

Permalink
fix: use custom mtime for last-modified if available (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
targos authored Nov 8, 2024
1 parent efdeb3b commit 3dac9a7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/providers/r2Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function r2MetadataToHeaders(
'cache-control':
httpStatusCode === 200 ? CACHE_HEADERS.success : CACHE_HEADERS.failure,
expires: httpMetadata?.cacheExpiry?.toUTCString() ?? '',
'last-modified': object.uploaded.toUTCString(),
'last-modified': getLastModified(object),
'content-language': httpMetadata?.contentLanguage ?? '',
'content-disposition': httpMetadata?.contentDisposition ?? '',
'content-length': object.size.toString(),
Expand Down Expand Up @@ -156,3 +156,13 @@ function determineHttpStatusCode(
// We weren't given a body and preconditions succeeded.
return 304;
}

function getLastModified(object: R2Object): string {
// `rclone` sets the mtime custom metadata to the mtime of the original
// file.
if (typeof object.customMetadata?.mtime === 'string') {
return new Date(Number(object.customMetadata.mtime) * 1000).toUTCString();
} else {
return object.uploaded.toUTCString();
}
}

0 comments on commit 3dac9a7

Please sign in to comment.