@@ -11,7 +11,7 @@ import { every } from "hono/combine";
11
11
import { hyperdriveMysql } from "./middleware/hyperdrive-mysql" ;
12
12
import { bearerAuth } from "hono/bearer-auth" ;
13
13
import { logger } from "hono/logger" ;
14
- import { VERIFY_LICENSE_SQL } from "./constants" ;
14
+ import { GET_LATEST_VERSION_SQL , VERIFY_LICENSE_SQL } from "./constants" ;
15
15
16
16
async function verifyTokenAndLicense ( token : string , c : Context ) {
17
17
const db = c . get ( 'db' ) ;
@@ -90,23 +90,22 @@ app.use("/api/v2/convert/:sourceFormat/to/:targetFormat", (c, next) => {
90
90
//#endregion
91
91
92
92
//#region Download redirects
93
- // TODO: Disabled temporarily until I figure out why Hyperdrive is broken
94
- // app.use("/download/*", (c, next) => {
95
- // return hyperdriveMysql({
96
- // config: c.env.DB,
97
- // })(c, next);
98
- // });
99
- // app.get("/download/:version/:packageName", async (c) => {
100
- // let { version, packageName } = c.req.param();
101
- // if (version === 'latest') {
102
- // const db = c.get('db');
103
- // if (!db) throw new Error('download controller must be used with (and sequenced after) the hyperdrive middleware');
104
- // const [results] = await db.query(GET_LATEST_VERSION_SQL);
105
- // const rows = results as mysql.RowDataPacket[];
106
- // version = `${rows[0].major}.${rows[0].minor}.${rows[0].revision}`;
107
- // }
108
- // return c.redirect(`${c.env.S3_BUCKET}/${version}/${packageName}`);
109
- // });
93
+ app . use ( "/download/*" , ( c , next ) => {
94
+ return hyperdriveMysql ( {
95
+ config : c . env . DB ,
96
+ } ) ( c , next ) ;
97
+ } ) ;
98
+ app . get ( "/download/:version/:packageName" , async ( c ) => {
99
+ let { version, packageName } = c . req . param ( ) ;
100
+ if ( version === 'latest' ) {
101
+ const db = c . get ( 'db' ) ;
102
+ if ( ! db ) throw new Error ( 'download controller must be used with (and sequenced after) the hyperdrive middleware' ) ;
103
+ const [ results ] = await db . query ( GET_LATEST_VERSION_SQL ) ;
104
+ const rows = results as mysql . RowDataPacket [ ] ;
105
+ version = `${ rows [ 0 ] . major } .${ rows [ 0 ] . minor } .${ rows [ 0 ] . revision } ` ;
106
+ }
107
+ return c . redirect ( `${ c . env . S3_BUCKET } /${ version } /${ packageName } ` ) ;
108
+ } ) ;
110
109
//#endregion
111
110
112
111
//#region All other requests
0 commit comments