feat: Add get single pack function and download manager

master
ogomez-at-wiris 2022-02-22 17:26:52 +01:00
parent dc187beb72
commit e4a4056fc3
5 changed files with 24 additions and 4 deletions

View File

View File

@ -1,5 +1,6 @@
import { Request, Response, NextFunction } from "express"; import { Request, Response, NextFunction } from "express";
import Pack from "./interfaces/pack"; import Pack from "./interfaces/pack";
import PackService from "./services/pack_service";
export default class PackAPI { export default class PackAPI {
public static getPacks = async ( public static getPacks = async (
@ -8,7 +9,22 @@ export default class PackAPI {
next: NextFunction next: NextFunction
) => { ) => {
return res.status(200).json({ 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',
}); });
}; };
} }

View File

@ -4,3 +4,4 @@ import PackAPI from "../pack_api";
export const packRoutes = express.Router(); export const packRoutes = express.Router();
packRoutes.get("/packs", PackAPI.getPacks); packRoutes.get("/packs", PackAPI.getPacks);
packRoutes.get("/getpack", PackAPI.downloadSinglePack);

View File

@ -45,9 +45,10 @@ router.use((req, res, next) => {
/** Server */ /** Server */
const httpServer = http.createServer(router); const httpServer = http.createServer(router);
const PORT: any = process.env.PORT ?? 6060; const PORT: any = process.env.PORT ?? 6060;
const start = performance.now();
PackService.getInitialList().then(() => { PackService.getInitialList().then(() => {
httpServer.listen(PORT, () => httpServer.listen(PORT, () =>
console.log(`The server is running on port ${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')
}); });

View File

@ -12,7 +12,6 @@ export default class PackService {
public static getInitialList = async (): Promise<void> => { public static getInitialList = async (): Promise<void> => {
let packs = await fs.readdirSync(PACK_BASE_PATH); let packs = await fs.readdirSync(PACK_BASE_PATH);
PackService.packList = await Promise.all(packs.map((pack) => PackService.getPackInfo(pack))) PackService.packList = await Promise.all(packs.map((pack) => PackService.getPackInfo(pack)))
}; };
@ -38,6 +37,9 @@ export default class PackService {
}) })
); );
if (bpm === '') {
console.log('pack without bpm found', name);
}
const currentPack: Pack = { const currentPack: Pack = {
name: name, name: name,
size: size, size: size,