mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 10:19:08 +00:00
Fix mismatching gif response byte length
Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
@@ -81,14 +81,22 @@ export function _getSegmentRanges(
|
|||||||
return segmentRanges;
|
return segmentRanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assertExpected<T>(actual: T, expected: T, message: string) {
|
||||||
|
strictAssert(
|
||||||
|
Object.is(actual, expected),
|
||||||
|
`${message}: ${actual} (expected: ${expected})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchSegment(
|
async function fetchSegment(
|
||||||
url: string,
|
url: string,
|
||||||
segmentRange: _SegmentRange,
|
segmentRange: _SegmentRange,
|
||||||
|
contentLength: number,
|
||||||
signal?: AbortSignal
|
signal?: AbortSignal
|
||||||
): Promise<ArrayBufferView> {
|
): Promise<ArrayBufferView> {
|
||||||
const { messaging } = window.textsecure;
|
const { messaging } = window.textsecure;
|
||||||
strictAssert(messaging, 'Missing window.textsecure.messaging');
|
strictAssert(messaging, 'Missing window.textsecure.messaging');
|
||||||
const { data } = await messaging.server.fetchBytesViaProxy({
|
const { data, response } = await messaging.server.fetchBytesViaProxy({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url,
|
url,
|
||||||
signal,
|
signal,
|
||||||
@@ -97,9 +105,22 @@ async function fetchSegment(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
strictAssert(
|
assertExpected(
|
||||||
data.buffer.byteLength === segmentRange.segmentSize,
|
response.headers.get('Content-Length'),
|
||||||
'Response buffer should be exact length of segment range'
|
`${segmentRange.segmentSize}`,
|
||||||
|
'Unexpected Content-Length header'
|
||||||
|
);
|
||||||
|
|
||||||
|
assertExpected(
|
||||||
|
response.headers.get('Content-Range'),
|
||||||
|
`bytes ${segmentRange.startIndex}-${segmentRange.endIndexInclusive}/${contentLength}`,
|
||||||
|
'Unexpected Content-Range header'
|
||||||
|
);
|
||||||
|
|
||||||
|
assertExpected(
|
||||||
|
data.byteLength,
|
||||||
|
segmentRange.segmentSize,
|
||||||
|
'Unexpected response buffer byte length'
|
||||||
);
|
);
|
||||||
|
|
||||||
let slice: ArrayBufferView;
|
let slice: ArrayBufferView;
|
||||||
@@ -125,7 +146,7 @@ export async function fetchInSegments(
|
|||||||
const segmentRanges = _getSegmentRanges(contentLength, segmentSize);
|
const segmentRanges = _getSegmentRanges(contentLength, segmentSize);
|
||||||
const segmentBuffers = await Promise.all(
|
const segmentBuffers = await Promise.all(
|
||||||
segmentRanges.map(segmentRange => {
|
segmentRanges.map(segmentRange => {
|
||||||
return fetchSegment(url, segmentRange, signal);
|
return fetchSegment(url, segmentRange, contentLength, signal);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return new Blob(segmentBuffers);
|
return new Blob(segmentBuffers);
|
||||||
|
|||||||
Reference in New Issue
Block a user