[Task 3] Fix sse crash

This commit is contained in:
2025-11-17 08:13:40 +01:00
parent 5525c4b4ad
commit 5916cce77f
2 changed files with 74 additions and 12 deletions

View File

@@ -19,10 +19,13 @@ const storage = multer.diskStorage( {
) => { ) => {
// Suggested in Multer's readme // Suggested in Multer's readme
const uniqueSuffix = Date.now() + '-' + Math.round( Math.random() * 1E3 ); const uniqueSuffix = Date.now() + '-' + Math.round( Math.random() * 1E3 );
const fname = file.fieldname + '-' + uniqueSuffix;
// TODO: We could consider allowing the filename to be overwritten using a query param on the
// request (i.e. url would be /upload?fname=<filename>)
fileEvent.emit( 'uploaded', file.fieldname + '-' + uniqueSuffix ); fileEvent.emit( 'uploaded', fname );
cb( null, file.fieldname + '-' + uniqueSuffix ); cb( null, fname );
} }
} ); } );
// CSV file upload endpoint // CSV file upload endpoint
@@ -37,12 +40,11 @@ const fileEvent = new FileEvent();
app.post( app.post(
'/upload', '/upload',
upload.single( 'dataFile' ), upload.single( 'dataFile' ),
( ( _req, res ) => {
req, res, next // NOTE: We do only need the next function in the handler when we want a middleware,
) => { // otherwise we can simply omit it
console.log( console.log( 'Uploaded file' );
req, res, next res.send( 'Ok' );
);
} }
); );
@@ -140,10 +142,14 @@ const sendSSEData = ( event: string, data: string ) => {
const subs = Object.values( subscribers ); const subs = Object.values( subscribers );
for ( let i = 0; i < subs.length; i++ ) { for ( let i = 0; i < subs.length; i++ ) {
subs[i]!.response.write( `data: ${ JSON.stringify( { try {
'event': event, subs[i]!.response.write( `data: ${ JSON.stringify( {
'data': data 'event': event,
} ) }\n\n` ); 'data': data
} ) }\n\n` );
} catch ( e ) {
console.debug( e );
}
} }
}; };

View File

@@ -0,0 +1,56 @@
title,artist,dancingStyle
1 Emperor's Dream,Ballroom Dance Orchestra & Marc Reift,Slow Walz
2 Kaiserwalzer,Ballroom Dance Orchestra & Marc Reift,Wiener Walzer
3 Macarena (Wish),Los del Mar,Flashmob
4 Wannabe (Wish),Spice Girls,Discofox
5 Dancing Queen (Wish),ABBA,Discofox
6 Splish Splash,Bobby Darin,Jive/ Rocknroll
"7 See You Later, Alligator",Bill Haley,Jive/ Rocknroll
8 Rico Vacilon,Pedro Garcia & His Del Prado Orchestra,Cha Cha Cha
9 El Diablo Anda Suelto,Rey Ruiz,Cha ch cha
10 Hips Don't Lie (Wish,Shakira,Salsa/ Discofox
11 Como Volver a Ser Feliz,Luis Enrique,Salsa
12 Moon River,,Slow Walz
13 Morning has broken,Cat Stevens,Wiener Walzer
14 Jeepers creepers,Benny Goodmann,Discofox/Foxtrott
15 ..Baby One More Time (Wish),Britney Spears,Discofox
16 Can't Stop the Feeling! (Wish),Justin Timberlake,Discofox
17 Tea for Two Cha Cha,Tommy Dorsey and His Orchestra,Cha ch cha
18 Muevelo,Rey Ruiz,Cha ch cha
19 I feel good,Ray Charles,Jive/Rocknroll
21 Jailhouse Rock,Elvis Presley,Jive/Rocknroll
22 Are you lonesome,Elvis Presley,Slow Walz
23 Louenesee,Span,Walzer
24 Something Stupid,Michael Bubl<62>,Rumba/cha cha cha
25 Stayin' Alive (wish),Bee Gees,Discofox
26 Uptown Funk (Wish),Bruno Mars,Discofox
27 suelta la cintura,Ruben leon,Cha ch cha
28 Come Dance With Me,Michael Bubl<62>,cha cha cha
29 Kiss me,Sixpence None the Richer,Discofox/Foxtrott
30 ily (i love you baby) [feat. Emilee],Surf Mesa,Discofox
31 Crazy Little Thing Called Love,Queen,Jive/ Rocknroll
32 Great Balls of Fire,Jerry Lee Lewis,Jive/ Rocknroll
33 La Bamba,Ritchie Valens,Jive/ Rocknroll
34 Macho,Charles Fox,Salsa
35 The Last Waltz,Engelbert Humperdinck,Walzer
36 An der sch<63>nen blauen Donau,New 101 Strings Orchestra,Wiener Walzer
37 Dance The Night,Dua Lipa,Discofox
38 Iko Iko,Justin Wellington,Discofox
39 Beat It (Wish),Michael Jackson,Jive
40 Super Freaky Girl (Wish),Nicki Minaj,Jive/ Rocknroll
41 California Girls (Wish),Katy Perry,Discofox
3 Macarena (Wish),Los del Mar,Flashmob
43 Ay Mujer,Rey Ruiz,Cha ch cha
44 Lets get loud,Jennifer Lopez,Cha ch cha
45 Friday,Riton & Nightcrawlers,Party
46 Take On Me,a-ha,Party
47 Gimme! Gimme! Gimme! (Wish),ABBA,Party
48 I Gotta Feeling (Wish),Black Eyed Peas,Party
49 Angels,Robbie Williams,Slow
50 Hangover (Wish),Taio Cruz,Party
51 The Real Slim Shady (Wish),Eminem,Party
52 I don't care,,Party
53 YMCA,Village People,Party
54 Cotton Eye Joe (Wish),Rednex,Sex & Violins
55 Nothing compares to you,Sinhead O' Connor,Slow
56 Komet,Udo Lindenberg & Apache 207,Partyende