mirror of
https://github.com/plankanban/planka.git
synced 2026-07-15 21:48:11 +03:00
fix: Forward headers correctly when reading from S3
This commit is contained in:
@@ -51,15 +51,13 @@ class LocalFileManager {
|
||||
const readStream = fs.createReadStream(filePath);
|
||||
|
||||
if (withHeaders) {
|
||||
const weakEtag = `W/"${stat.size.toString(16)}-${stat.mtime.getTime().toString(16)}"`;
|
||||
|
||||
return [
|
||||
readStream,
|
||||
{
|
||||
'Content-Type': mime.lookup(filePathSegment) || 'application/octet-stream',
|
||||
'Content-Length': stat.size,
|
||||
'Last-Modified': stat.mtime.toUTCString(),
|
||||
ETag: weakEtag,
|
||||
ETag: `W/"${stat.size.toString(16)}-${stat.mtime.getTime().toString(16)}"`,
|
||||
'Accept-Ranges': 'bytes',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -56,17 +56,29 @@ class S3FileManager {
|
||||
const result = await this.client.send(command);
|
||||
|
||||
if (withHeaders) {
|
||||
return [
|
||||
result.Body,
|
||||
{
|
||||
'Content-Type':
|
||||
result.ContentType || mime.lookup(filePathSegment) || 'application/octet-stream',
|
||||
'Content-Length': result.ContentLength,
|
||||
'Last-Modified': result.LastModified && result.LastModified.toUTCString(),
|
||||
ETag: result.ETag,
|
||||
'Accept-Ranges': result.AcceptRanges || 'bytes',
|
||||
},
|
||||
];
|
||||
const headers = {
|
||||
'Content-Type':
|
||||
result.ContentType || mime.lookup(filePathSegment) || 'application/octet-stream',
|
||||
'Accept-Ranges': result.AcceptRanges || 'bytes',
|
||||
};
|
||||
|
||||
if (!_.isUndefined(result.ContentLength)) {
|
||||
headers['Content-Length'] = result.ContentLength;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(result.LastModified)) {
|
||||
headers['Last-Modified'] = result.LastModified.toUTCString();
|
||||
}
|
||||
|
||||
if (_.isUndefined(result.ETag)) {
|
||||
if (!_.isUndefined(result.ContentLength) && !_.isUndefined(result.LastModified)) {
|
||||
headers.ETag = `W/"${result.ContentLength.toString(16)}-${result.LastModified.getTime().toString(16)}"`;
|
||||
}
|
||||
} else {
|
||||
headers.ETag = result.ETag;
|
||||
}
|
||||
|
||||
return [result.Body, headers];
|
||||
}
|
||||
|
||||
return result.Body;
|
||||
|
||||
Reference in New Issue
Block a user