Skip to content

Commit

Permalink
fix(operators): request optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Jan 8, 2025
1 parent b1559aa commit f515a50
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
43 changes: 22 additions & 21 deletions packages/operators/src/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,32 +206,33 @@ describe('test', () => {
const { request } = await import('./request.js');

const progress = Progress();
progress.subscribe({
next: e => console.log('DOWNLOAD', e)
});
progress.subscribe({ next: e => console.log('DOWNLOAD', e) });

Check warning on line 209 in packages/operators/src/request.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement

const byteRate = TransferRate(MBYTE, SECOND);
byteRate.subscribe({
next: e => console.log('RATE', e)
// complete: () => console.log('complete')
});
byteRate.subscribe({ next: e => console.log('RATE', e) });

Check warning on line 212 in packages/operators/src/request.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement

const estimateTime = EstimateTime(SECOND);
estimateTime.subscribe({
next: e => console.log('ESTIMATE', e)
estimateTime.subscribe({ next: e => console.log('ESTIMATE', e) });

Check warning on line 215 in packages/operators/src/request.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement

const fileMap = {
VIDEO_170MB:
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4',
VIDEO_13MB:
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4',
SvgContentLengthValid: 'https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg',
SvgContentLengthInvalid: 'https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg'
};

const req = new Request(new URL(fileMap.SvgContentLengthInvalid), {
method: 'GET'
});
// https://api.github.com/repos/mediaelement/mediaelement-files/contents/big_buck_bunny.mp4
// https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4
// https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg
// https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg

const req = new Request(
new URL('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4'),
{
method: 'GET'
}
);

const value = await lastValueFrom(
of(req).pipe(request({ download: [progress, byteRate, estimateTime] }), resolveBlob())
of(req).pipe(
request({ download: [progress, byteRate, estimateTime] }),
resolveBlob()
//
)
);
console.log('FINAL', value);

Check warning on line 237 in packages/operators/src/request.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
writeFileSync('programming.mp4', global.Buffer.from(await value.arrayBuffer()));
Expand Down
3 changes: 2 additions & 1 deletion packages/operators/src/stream/observables/EstimateTime.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { map, Subject } from 'rxjs';
import { concatWith, map, of, Subject } from 'rxjs';

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

export const EstimateTime = (timeUnit = MSECOND) => {
return new Subject().pipe(
calcReceivedStats(),
calcEstimatedTime(),
concatWith(of(0)),
convertEstimedTimeTo(timeUnit)
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/operators/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineProject({
test: {
cacheDir: '../.cache/vitest',
setupFiles: ['../../setup.js'],
testTimeout: 10000,
testTimeout: 20000,
environment: 'edge-runtime'
}
});

0 comments on commit f515a50

Please sign in to comment.