Skip to content

Commit

Permalink
feat: Use version from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Dec 21, 2020
1 parent 9a21d7b commit e69f4b6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
12 changes: 10 additions & 2 deletions apps/api/src/shared/config/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LogLevel } from '@nestjs/common'
import * as Joi from '@hapi/joi'
import { version } from '@pct-org/version'

export interface EnvConfig {
[key: string]: string;
Expand Down Expand Up @@ -38,6 +39,10 @@ export class ConfigService {
return this.envConfig[key] || ''
}

get version(): string {
return version
}

/**
* Get the correct formatted database uri
*/
Expand Down Expand Up @@ -114,10 +119,13 @@ export class ConfigService {
.default(1),

[ConfigService.MAX_CONNS]: Joi.number()
.default(35),
.default(35)
})

const { error, value: validatedEnvConfig } = envVarsSchema.validate(envConfig, { stripUnknown: true })
const {
error,
value: validatedEnvConfig
} = envVarsSchema.validate(envConfig, { stripUnknown: true })

if (error) {
throw new Error(`Config validation error: ${error.message}`)
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/status/status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class StatusService {
const sizePercentage = parseFloat((((disk.total - disk.available - folderSize) / disk.total) * 100).toFixed(2))

return {
version: 'unknown', // TODO:: Get git tag
version: this.configService.version,
totalMovies: await this.movieModel.countDocuments(),
totalShows: await this.showModel.countDocuments(),
totalEpisodes: await this.episodesModel.countDocuments(),
Expand Down
7 changes: 6 additions & 1 deletion apps/scraper/src/routes/status/status.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { Controller, Get, Inject, OnApplicationBootstrap } from '@nestjs/common'
import { SchedulerRegistry } from '@nestjs/schedule'
import { formatMsToRemaining } from '@pct-org/torrent/utils'

import { ConfigService } from '../../shared/config/config.service'

@Controller()
export class StatusController implements OnApplicationBootstrap {

@Inject()
private schedulerRegistry: SchedulerRegistry

@Inject()
private configService: ConfigService

private bootedSince: number

public onApplicationBootstrap(): void {
Expand All @@ -20,7 +25,7 @@ export class StatusController implements OnApplicationBootstrap {

return {
status: 'ok',
version: 'beta',
version: this.configService.version,
updated: cron.lastDate() || 'never',
nextUpdate: cron.nextDates(),
uptime: formatMsToRemaining(Date.now() - this.bootedSince)
Expand Down
10 changes: 9 additions & 1 deletion apps/scraper/src/shared/config/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LogLevel } from '@nestjs/common'
import * as Joi from '@hapi/joi'
import { version } from '@pct-org/version'

export interface EnvConfig {
[key: string]: string;
Expand Down Expand Up @@ -37,6 +38,10 @@ export class ConfigService {
return this.envConfig[key] || ''
}

get version(): string {
return version
}

/**
* Get the correct formatted database uri
*/
Expand Down Expand Up @@ -113,7 +118,10 @@ export class ConfigService {
[ConfigService.SCRAPE_ON_START]: Joi.boolean()
})

const { error, value: validatedEnvConfig } = envVarsSchema.validate(envConfig, { stripUnknown: true })
const {
error,
value: validatedEnvConfig
} = envVarsSchema.validate(envConfig, { stripUnknown: true })

if (error) {
throw new Error(`Config validation error: ${error.message}`)
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"@pct-org/types/shared": ["libs/types/shared/src/index.ts"],
"@pct-org/types/blacklist": ["libs/types/blacklist/src/index.ts"],
"@pct-org/types/download": ["libs/types/download/src/index.ts"],
"@pct-org/types/image": ["libs/types/image/src/index.ts"]
"@pct-org/types/image": ["libs/types/image/src/index.ts"],
"@pct-org/version": ["./package.json"]
}
},
"exclude": ["node_modules", "tmp"]
Expand Down

0 comments on commit e69f4b6

Please sign in to comment.