@@ -15,22 +15,6 @@ function toDataList(data) {
1515 return unorderedList ( dataList ) ;
1616}
1717
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-
3418/**
3519 * @typedef {Object } Env
3620 */
@@ -57,7 +41,7 @@ export default {
5741 return new Response ( null , { status : 400 , headers : respHeaders } ) ;
5842 }
5943
60- const parsedBody = await parseStreamAsJson ( request . body ) ;
44+ const parsedBody = await request . json ( ) ;
6145 if ( parsedBody === null ) {
6246 return new Response ( null , { status : 400 , headers : respHeaders } ) ;
6347 }
@@ -68,7 +52,7 @@ export default {
6852
6953 try {
7054 const response = await fetch ( 'https://github.nusmods.com/venues' ) ;
71- const currentVenues = await parseStreamAsJson ( response . body ) ;
55+ const currentVenues = await response . json ( ) ;
7256 currentVenue = currentVenues [ venue ] ;
7357 } catch ( e ) {
7458 currentVenueError = e ;
0 commit comments