feat: Add get single pack function and download manager
parent
dc187beb72
commit
e4a4056fc3
|
@ -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',
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,3 +4,4 @@ import PackAPI from "../pack_api";
|
|||
export const packRoutes = express.Router();
|
||||
|
||||
packRoutes.get("/packs", PackAPI.getPacks);
|
||||
packRoutes.get("/getpack", PackAPI.downloadSinglePack);
|
|
@ -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')
|
||||
});
|
||||
|
|
|
@ -12,7 +12,6 @@ export default class PackService {
|
|||
|
||||
public static getInitialList = async (): Promise<void> => {
|
||||
let packs = await fs.readdirSync(PACK_BASE_PATH);
|
||||
|
||||
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 = {
|
||||
name: name,
|
||||
size: size,
|
||||
|
|
Loading…
Reference in New Issue