diff --git a/src/managers/download_manager.ts b/src/managers/download_manager.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/pack_api.ts b/src/pack_api.ts index 526cc43..5001dfb 100644 --- a/src/pack_api.ts +++ b/src/pack_api.ts @@ -1,5 +1,6 @@ import { Request, Response, NextFunction } from "express"; import Pack from "./interfaces/pack"; +import PackService from "./services/pack_service"; export default class PackAPI { public static getPacks = async ( @@ -8,7 +9,22 @@ export default class PackAPI { next: NextFunction ) => { return res.status(200).json({ - message: "hello all packs", + packs: JSON.stringify(await PackService.getPackList()), + }); + }; + + public static downloadSinglePack = async ( + req: Request, + res: Response, + next: NextFunction + ) => { + if (!req.query.name) { + return res.status(500).json({ + message: 'pack name not specified', + }); + } + return res.status(200).json({ + message: 'ok', }); }; } diff --git a/src/routes/packs.ts b/src/routes/packs.ts index e0aa66e..e77918f 100644 --- a/src/routes/packs.ts +++ b/src/routes/packs.ts @@ -4,3 +4,4 @@ import PackAPI from "../pack_api"; export const packRoutes = express.Router(); packRoutes.get("/packs", PackAPI.getPacks); +packRoutes.get("/getpack", PackAPI.downloadSinglePack); \ No newline at end of file diff --git a/src/server.ts b/src/server.ts index 72b3d17..a38a10e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -45,9 +45,10 @@ router.use((req, res, next) => { /** Server */ const httpServer = http.createServer(router); const PORT: any = process.env.PORT ?? 6060; +const start = performance.now(); PackService.getInitialList().then(() => { httpServer.listen(PORT, () => console.log(`The server is running on port ${PORT}`) ); - console.log('initialized with ',PackService.getPackList().length) + console.log('initialized with ',PackService.getPackList().length, 'packs in ', Math.round(performance.now() - start), 'ms') }); diff --git a/src/services/pack_service.ts b/src/services/pack_service.ts index 3152d32..e012599 100644 --- a/src/services/pack_service.ts +++ b/src/services/pack_service.ts @@ -12,7 +12,6 @@ export default class PackService { public static getInitialList = async (): Promise => { let packs = await fs.readdirSync(PACK_BASE_PATH); - PackService.packList = await Promise.all(packs.map((pack) => PackService.getPackInfo(pack))) }; @@ -38,12 +37,15 @@ export default class PackService { }) ); + if (bpm === '') { + console.log('pack without bpm found', name); + } const currentPack: Pack = { name: name, size: size, bpm: bpm, }; - + return currentPack; }; }