@@ -15,22 +15,6 @@ function toDataList(data) {
15
15
return unorderedList ( dataList ) ;
16
16
}
17
17
18
- async function parseStreamAsJson ( stream ) {
19
- const chunks = [ ] ;
20
- for await ( const chunk of stream ) {
21
- chunks . push ( chunk ) ;
22
- }
23
- const totalLen = chunks . reduce ( ( acc , chunk ) => acc + chunk . length , 0 ) ;
24
- if ( totalLen === 0 ) {
25
- return null ;
26
- }
27
- const mergedChunks = new Uint8Array ( totalLen ) ;
28
- for ( let i = 0 , offset = 0 ; i < chunks . length ; offset += chunks [ i ] . length , ++ i ) {
29
- mergedChunks . set ( chunks [ i ] , offset ) ;
30
- }
31
- return JSON . parse ( new TextDecoder ( ) . decode ( mergedChunks ) ) ;
32
- }
33
-
34
18
/**
35
19
* @typedef {Object } Env
36
20
*/
@@ -57,7 +41,7 @@ export default {
57
41
return new Response ( null , { status : 400 , headers : respHeaders } ) ;
58
42
}
59
43
60
- const parsedBody = await parseStreamAsJson ( request . body ) ;
44
+ const parsedBody = await request . json ( ) ;
61
45
if ( parsedBody === null ) {
62
46
return new Response ( null , { status : 400 , headers : respHeaders } ) ;
63
47
}
@@ -68,7 +52,7 @@ export default {
68
52
69
53
try {
70
54
const response = await fetch ( 'https://github.nusmods.com/venues' ) ;
71
- const currentVenues = await parseStreamAsJson ( response . body ) ;
55
+ const currentVenues = await response . json ( ) ;
72
56
currentVenue = currentVenues [ venue ] ;
73
57
} catch ( e ) {
74
58
currentVenueError = e ;
0 commit comments