@@ -7,7 +7,7 @@ console.log("connected to sqlite");
7
7
8
8
console . log ( 'creating "stats" table' ) ;
9
9
const 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 );" ,
11
11
) ;
12
12
query . run ( ) ;
13
13
console . log ( 'created "stats" table' ) ;
@@ -52,13 +52,14 @@ app.all("/file-upload/:id/:status{[0-9]{3}}", async (c) => {
52
52
}
53
53
54
54
console . log ( "uploading file" ) ;
55
- const data : unknown = await c . req . json ( ) ;
55
+ const data : { bundleName : string } = await c . req . json ( ) ;
56
56
console . log ( "finished upload" ) ;
57
57
58
58
console . log ( "inserting stats" ) ;
59
+ const bundleName = data ! . bundleName ;
59
60
const insertStats = JSON . stringify ( data ) ;
60
61
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 } ')` ,
62
63
) ;
63
64
query . run ( ) ;
64
65
query . finalize ( ) ;
@@ -87,4 +88,31 @@ app.all("/get-stats/:id", (c) => {
87
88
return c . text ( "Not found" , { status : 404 } ) ;
88
89
} ) ;
89
90
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
+
90
118
export default app ;
0 commit comments