Skip to content

Commit f515a50

Browse files
fix(operators): request optimization
1 parent b1559aa commit f515a50

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

packages/operators/src/request.test.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -206,32 +206,33 @@ describe('test', () => {
206206
const { request } = await import('./request.js');
207207

208208
const progress = Progress();
209-
progress.subscribe({
210-
next: e => console.log('DOWNLOAD', e)
211-
});
209+
progress.subscribe({ next: e => console.log('DOWNLOAD', e) });
210+
212211
const byteRate = TransferRate(MBYTE, SECOND);
213-
byteRate.subscribe({
214-
next: e => console.log('RATE', e)
215-
// complete: () => console.log('complete')
216-
});
212+
byteRate.subscribe({ next: e => console.log('RATE', e) });
213+
217214
const estimateTime = EstimateTime(SECOND);
218-
estimateTime.subscribe({
219-
next: e => console.log('ESTIMATE', e)
215+
estimateTime.subscribe({ next: e => console.log('ESTIMATE', e) });
216+
217+
const fileMap = {
218+
VIDEO_170MB:
219+
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4',
220+
VIDEO_13MB:
221+
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4',
222+
SvgContentLengthValid: 'https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg',
223+
SvgContentLengthInvalid: 'https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg'
224+
};
225+
226+
const req = new Request(new URL(fileMap.SvgContentLengthInvalid), {
227+
method: 'GET'
220228
});
221-
// https://api.github.com/repos/mediaelement/mediaelement-files/contents/big_buck_bunny.mp4
222-
// https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4
223-
// https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg
224-
// https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg
225-
226-
const req = new Request(
227-
new URL('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4'),
228-
{
229-
method: 'GET'
230-
}
231-
);
232229

233230
const value = await lastValueFrom(
234-
of(req).pipe(request({ download: [progress, byteRate, estimateTime] }), resolveBlob())
231+
of(req).pipe(
232+
request({ download: [progress, byteRate, estimateTime] }),
233+
resolveBlob()
234+
//
235+
)
235236
);
236237
console.log('FINAL', value);
237238
writeFileSync('programming.mp4', global.Buffer.from(await value.arrayBuffer()));

packages/operators/src/stream/observables/EstimateTime.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { map, Subject } from 'rxjs';
1+
import { concatWith, map, of, Subject } from 'rxjs';
22

33
import { calcReceivedStats, MSECOND } from './utils';
44

55
export const EstimateTime = (timeUnit = MSECOND) => {
66
return new Subject().pipe(
77
calcReceivedStats(),
88
calcEstimatedTime(),
9+
concatWith(of(0)),
910
convertEstimedTimeTo(timeUnit)
1011
);
1112
};

packages/operators/vitest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default defineProject({
55
test: {
66
cacheDir: '../.cache/vitest',
77
setupFiles: ['../../setup.js'],
8-
testTimeout: 10000,
8+
testTimeout: 20000,
99
environment: 'edge-runtime'
1010
}
1111
});

0 commit comments

Comments
 (0)