mirror of
https://github.com/docmost/docmost.git
synced 2025-11-12 17:42:36 +10:00
feat: add version check (#922)
* Add version endpoint * version indicator * refetch * * Translate strings * Handle error
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { RobotsTxtController } from './robots.txt.controller';
|
||||
import { VersionController } from './version.controller';
|
||||
import { VersionService } from './version.service';
|
||||
|
||||
@Module({
|
||||
controllers: [RobotsTxtController],
|
||||
controllers: [RobotsTxtController, VersionController],
|
||||
providers: [VersionService],
|
||||
})
|
||||
export class SecurityModule {}
|
||||
|
||||
27
apps/server/src/integrations/security/version.controller.ts
Normal file
27
apps/server/src/integrations/security/version.controller.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {
|
||||
Controller,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
NotFoundException,
|
||||
Post,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { VersionService } from './version.service';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { EnvironmentService } from '../environment/environment.service';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('version')
|
||||
export class VersionController {
|
||||
constructor(
|
||||
private readonly versionService: VersionService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post()
|
||||
async getVersion() {
|
||||
if (this.environmentService.isCloud()) throw new NotFoundException();
|
||||
return this.versionService.getVersion();
|
||||
}
|
||||
}
|
||||
28
apps/server/src/integrations/security/version.service.ts
Normal file
28
apps/server/src/integrations/security/version.service.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const packageJson = require('./../../../package.json');
|
||||
|
||||
@Injectable()
|
||||
export class VersionService {
|
||||
constructor() {}
|
||||
|
||||
async getVersion() {
|
||||
const url = `https://api.github.com/repos/docmost/docmost/releases/latest`;
|
||||
|
||||
let latestVersion = 0;
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) return;
|
||||
const data = await response.json();
|
||||
latestVersion = data?.tag_name?.replace('v', '');
|
||||
} catch (err) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
return {
|
||||
currentVersion: packageJson?.version,
|
||||
latestVersion: latestVersion,
|
||||
releaseUrl: 'https://github.com/docmost/docmost/releases',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user