diff --git a/README.md b/README.md index 00a13b1..ea3082e 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,14 @@ -
- -[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 -[circleci-url]: https://circleci.com/gh/nestjs/nest - -A progressive Node.js framework for building efficient and scalable server-side applications.
- - +An API server for personal KODI plugin. ## Description -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. +A rewrite attempt from "vanilla" node.js into framework based (Nest.js). + +## License + +No licence (Nest is MIT) + +## Below are left from nest readme ## Installation @@ -57,17 +41,3 @@ $ npm run test:e2e # test coverage $ npm run test:cov ``` - -## Support - -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). - -## Stay in touch - -- Author - [Kamil MyĆliwiec](https://kamilmysliwiec.com) -- Website - [https://nestjs.com](https://nestjs.com/) -- Twitter - [@nestframework](https://twitter.com/nestframework) - -## License - -Nest is [MIT licensed](LICENSE). diff --git a/package-lock.json b/package-lock.json index 28087e9..c45b500 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "nest-test", + "name": "kodi-api-server", "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "nest-test", + "name": "kodi-api-server", "version": "0.0.1", "license": "UNLICENSED", "dependencies": { diff --git a/src/Static/static.controller.ts b/src/Static/static.controller.ts index 2a73764..64e66f9 100644 --- a/src/Static/static.controller.ts +++ b/src/Static/static.controller.ts @@ -10,6 +10,7 @@ import { import { NextFunction, Request, Response } from 'express'; import { readdir, stat } from 'fs/promises'; import { join } from 'path'; +import { Stats } from 'fs'; @Controller('*') export class StaticController { @@ -19,6 +20,7 @@ export class StaticController { @Res() response: Response, @Next() next: NextFunction, ) { + //todo - refactor to use service const relPath = request.url; //relPath = relPath.split('%2E').join('.'); //relPath = relPath.split('%2e').join('.'); @@ -31,154 +33,74 @@ export class StaticController { const path = join(__dirname, process.env.STATIC_SERVE_FOLDER, relPath); - const stats: any = await stat(path).catch(() => false); + const stats: Stats | false = await stat(path).catch(() => false); if (stats === false) { throw new NotFoundException('Path not found: ' + relPath); } - if (stats.isDirectory()) { - response.status(200).send(await readDirectory(path, relPath)); - //.send(JSON.stringify(await readDirectory(path, relPath), null, ' ')); - - return; + if (!stats.isDirectory()) { + return next(); } - return next(); + response.status(200).send(await readDirectory(path, relPath)); + + return; } } +//todo - move this to service async function readDirectory(path: string, relPath: string) { let files = await readdir(path); - let longestFileLenght = 0; + let longestFileLength = 0; files = files.filter((fileName: string) => { const fileIncluded = fileName[0] !== '.'; - longestFileLenght = fileIncluded ? fileName.length : longestFileLenght; + longestFileLength = + fileIncluded && longestFileLength < fileName.length + ? fileName.length + : longestFileLength; return fileIncluded; }); - let result: string; + longestFileLength += 10; - if (files.length == 0) { - //strPath = strPath.replace(strRootDir, "") - result = "\n" - result = result + "../' - result = result + "\n
`;
+
+ result = `../`;
+
+ for (const file of files) {
+ const stats: Stats | false = await stat(join(path, file)).catch(
+ () => false,
+ );
+
+ if (stats === false) {
+ continue;
+ }
+ const arrDate: Array = stats.birthtime.toUTCString().split(' ');
+ const strDate: string =
+ ' '.repeat(longestFileLength - file.length) +
+ `${arrDate[1]}-${arrDate[2]}-${arrDate[3]} ${arrDate[4]}`;
+
+ if (stats.isDirectory()) {
+ const strSize = ' '.repeat(19) + '-';
+ result += '\n' + `${file}/${strDate + strSize}`;
+ continue;
+ }
+ let strSize = stats.size.toString();
+ strSize = ' '.repeat(20 - strSize.length) + strSize;
+
+ result += '\n' + `${file} ${strDate + strSize}`;
}
- return result;
+ const resultHtmlEnd = ` ../' -// result = result + "\n
../\n';
-// result = result + arrRows.join('\n');
-// result = result + '\n