1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
12 | return function (target, key) { decorator(target, key, paramIndex); }
|
13 | };
|
14 | Object.defineProperty(exports, "__esModule", { value: true });
|
15 | var _a;
|
16 | const api_dto_1 = require("./api.dto");
|
17 | const common_1 = require("@nestjs/common");
|
18 | const swagger_1 = require("@nestjs/swagger");
|
19 | const express_1 = require("express");
|
20 | const _1 = require(".");
|
21 | let AppController =
|
22 |
|
23 |
|
24 |
|
25 | class AppController {
|
26 | constructor(Fs, Path, appSettings) {
|
27 | this.Fs = Fs;
|
28 | this.Path = Path;
|
29 | this.appSettings = appSettings;
|
30 | }
|
31 | |
32 |
|
33 |
|
34 | async getPackageJson() {
|
35 | const packageJsonPath = this.Path.join(__dirname, '../package.json');
|
36 |
|
37 | const packageJson = await this.Fs.readFile(packageJsonPath, 'utf8');
|
38 | return JSON.parse(packageJson);
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | getDocsUrl(req) {
|
46 | if (this.appSettings.docUrl) {
|
47 | return `${req.protocol}://${req.get('host')}${this.appSettings.docUrl}`;
|
48 | }
|
49 | else {
|
50 | return null;
|
51 | }
|
52 | }
|
53 | |
54 |
|
55 |
|
56 |
|
57 | async apiInfo(req) {
|
58 | let packageJson;
|
59 | try {
|
60 | packageJson = await this.getPackageJson();
|
61 | }
|
62 | catch (ex) {
|
63 | throw common_1.HttpCode(500);
|
64 | }
|
65 | return {
|
66 | api_version: '1.0',
|
67 | package_version: packageJson.version,
|
68 | name: packageJson.name,
|
69 | description: packageJson.description,
|
70 | _links: {
|
71 | homepage: packageJson.homepage,
|
72 | bug_report: packageJson.bugs && packageJson.bugs.url || null,
|
73 | repository: packageJson.repository && packageJson.repository.url || null,
|
74 | docs: this.getDocsUrl(req),
|
75 | }
|
76 | };
|
77 | }
|
78 | };
|
79 | __decorate([
|
80 | swagger_1.ApiOperation({ title: 'API Info' }),
|
81 | swagger_1.ApiResponse({ status: 200, type: api_dto_1.APIDto }),
|
82 | common_1.Get('/'),
|
83 | __param(0, common_1.Req()),
|
84 | __metadata("design:type", Function),
|
85 | __metadata("design:paramtypes", [typeof (_a = typeof express_1.Request !== "undefined" && express_1.Request) === "function" && _a || Object]),
|
86 | __metadata("design:returntype", Promise)
|
87 | ], AppController.prototype, "apiInfo", null);
|
88 | AppController = __decorate([
|
89 | common_1.Controller('/api/v1')
|
90 | |
91 |
|
92 |
|
93 | ,
|
94 | __param(0, common_1.Inject('Fs')),
|
95 | __param(1, common_1.Inject('Path')),
|
96 | __param(2, common_1.Inject('LXDHubAPISettings')),
|
97 | __metadata("design:paramtypes", [Object, Object, _1.LXDHubAPISettings])
|
98 | ], AppController);
|
99 | exports.AppController = AppController;
|
100 |
|
\ | No newline at end of file |