Implement version info endpoint and update version display in UI

This commit is contained in:
adityachandelgit
2025-04-16 15:33:13 -06:00
committed by Aditya Chandel
parent 6d1384aac4
commit 70a4360207
9 changed files with 123 additions and 25 deletions
@@ -0,0 +1,22 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import {API_CONFIG} from '../../config/api-config';
export interface AppVersion {
current: string;
latest: string;
}
@Injectable({
providedIn: 'root'
})
export class VersionService {
private versionUrl = `${API_CONFIG.BASE_URL}/api/v1/version`;
constructor(private http: HttpClient) {}
getVersion(): Observable<AppVersion> {
return this.http.get<AppVersion>(this.versionUrl);
}
}
@@ -28,17 +28,28 @@
</ul>
</div>
<p style="margin-top: auto;" class="p-4 text-center w-full">
<a
[href]="getVersionUrl(version)"
target="_blank"
rel="noopener noreferrer"
class="text-gray-300 hover:underline hover:text-gray-500">
{{ version }}
</a>
</p>
<ng-container *ngIf="versionInfo">
<div style="margin-top: auto;" class="p-4 text-center w-full text-sm">
<div class="text-gray-200">
<a
[href]="getVersionUrl(versionInfo.current)"
target="_blank"
rel="noopener noreferrer"
class="hover:underline hover:text-gray-100 text-sm"
>
{{ versionInfo.current }}
</a>
</div>
<div *ngIf="versionInfo.latest && versionInfo.latest !== versionInfo.current">
<a
[href]="getVersionUrl(versionInfo.latest)"
target="_blank"
rel="noopener noreferrer"
class="text-orange-400 hover:underline hover:text-orange-300 text-xs"
>
(Update)
</a>
</div>
</div>
</ng-container>
</div>
@@ -8,7 +8,7 @@ import {map} from 'rxjs/operators';
import {ShelfService} from '../../../book/service/shelf.service';
import {BookService} from '../../../book/service/book.service';
import {LibraryShelfMenuService} from '../../../book/service/library-shelf-menu.service';
import {version} from '../../../../environments/version';
import {AppVersion, VersionService} from '../../../core/service/version.service';
@Component({
selector: 'app-menu',
@@ -20,15 +20,20 @@ export class AppMenuComponent implements OnInit {
shelfMenu$: Observable<any> | undefined;
homeMenu$: Observable<any> | undefined;
versionInfo: AppVersion | null = null;
private libraryService = inject(LibraryService);
private shelfService = inject(ShelfService);
private bookService = inject(BookService);
private versionService = inject(VersionService);
private libraryShelfMenuService = inject(LibraryShelfMenuService);
protected readonly version = version;
ngOnInit(): void {
this.versionService.getVersion().subscribe((data) => {
this.versionInfo = data;
});
this.libraryMenu$ = this.libraryService.libraryState$.pipe(
map((state) => [
{
@@ -89,12 +94,12 @@ export class AppMenuComponent implements OnInit {
);
}
getVersionUrl(version: string): string {
getVersionUrl(version: string | undefined): string {
if (!version) return '#';
if (version.startsWith('v')) {
return `https://github.com/adityachandelgit/BookLore/releases/tag/${version}`;
} else {
return `https://github.com/adityachandelgit/BookLore/commit/${version}`;
}
}
}
-1
View File
@@ -1 +0,0 @@
export const version = 'v0.0.0';