@@ -7,7 +7,7 @@ console.log("connected to sqlite");
77
88console . log ( 'creating "stats" table' ) ;
99const query = sqlite . query (
10- "CREATE TABLE `stats` (`id` text, `json_stats ` text );" ,
10+ "CREATE TABLE `stats` (`id` text, `bundle_name ` text UNIQUE, `json_stats` text );" ,
1111) ;
1212query . run ( ) ;
1313console . log ( 'created "stats" table' ) ;
@@ -52,13 +52,14 @@ app.all("/file-upload/:id/:status{[0-9]{3}}", async (c) => {
5252 }
5353
5454 console . log ( "uploading file" ) ;
55- const data : unknown = await c . req . json ( ) ;
55+ const data : { bundleName : string } = await c . req . json ( ) ;
5656 console . log ( "finished upload" ) ;
5757
5858 console . log ( "inserting stats" ) ;
59+ const bundleName = data ! . bundleName ;
5960 const insertStats = JSON . stringify ( data ) ;
6061 const query = sqlite . query (
61- `INSERT INTO stats (id, json_stats) VALUES ('${ id } ', '${ insertStats } ')` ,
62+ `INSERT INTO stats (id, bundle_name, json_stats) VALUES ('${ id } ', ' ${ bundleName } ', '${ insertStats } ')` ,
6263 ) ;
6364 query . run ( ) ;
6465 query . finalize ( ) ;
@@ -87,4 +88,31 @@ app.all("/get-stats/:id", (c) => {
8788 return c . text ( "Not found" , { status : 404 } ) ;
8889} ) ;
8990
91+ app . all ( "/get-stats-by-bundle-name/:bundleName" , ( c ) => {
92+ const bundleName = c . req . param ( "bundleName" ) ;
93+ console . log ( "getting stats" , bundleName ) ;
94+
95+ const query = sqlite . query (
96+ "SELECT * FROM stats WHERE bundle_name = $bundleName" ,
97+ ) ;
98+ const result = query . get ( { $bundleName : bundleName } ) as {
99+ id : string ;
100+ json_stats : string ;
101+ } ;
102+ query . finalize ( ) ;
103+
104+ if ( result ) {
105+ console . log ( "stats found" , bundleName ) ;
106+ const query = sqlite . query (
107+ `DELETE FROM stats WHERE bundle_name = '${ bundleName } '` ,
108+ ) ;
109+ query . run ( ) ;
110+ query . finalize ( ) ;
111+ return c . json ( { stats : result . json_stats } , { status : 200 } ) ;
112+ }
113+
114+ console . log ( "stats not found" , bundleName ) ;
115+ return c . text ( "Not found" , { status : 404 } ) ;
116+ } ) ;
117+
90118export default app ;
0 commit comments