Skip to content

Commit

Permalink
Added version information
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyBoo committed May 25, 2020
1 parent fe72a3c commit 7d02faf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ utils/*.json
**/.schema-build-info
test*
dump/*
version
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM simplyboo6/vimtur-base@sha256:f30cc178f6c9676449e08b0aee59e31c120eb5c467cb435c33fd2bedb230f593

ARG VERSION_NAME=dev

## Copy in source
COPY ./ /app/
RUN echo "$VERSION_NAME" > /app/version

## Build server
RUN cd /usr/lib/node_modules/phash2 && yarn link
Expand Down
7 changes: 7 additions & 0 deletions client/src/app/components/config/config.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,13 @@ <h4>Misc Configuration</h4>
</div>
</div>
</div>

<div class="card">
<h4>Version</h4>
<div>
{{ version || 'Loading version...' }}
</div>
</div>
</div>
<ng-template #loading>
<h4>Loading...</h4>
Expand Down
9 changes: 8 additions & 1 deletion client/src/app/components/config/config.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { Configuration, Scanner, QueuedTask, ListedTask } from '@vimtur/common';
import { AlertService } from 'app/services/alert.service';
import { TasksService } from 'app/services/tasks.service';
import { Subscription } from 'rxjs';
import { Subscription, Observable } from 'rxjs';
import { ListItem } from 'app/shared/types';

@Component({
Expand Down Expand Up @@ -37,6 +37,7 @@ export class ConfigComponent implements OnInit, OnDestroy {
public streamQualities: ListItem<number>[] = [];
public minQuality: ListItem<number>[] = [];
public scanResults?: Scanner.Summary;
public version?: string;

public addTagModel?: string;
public deleteTagModel?: string;
Expand Down Expand Up @@ -85,6 +86,12 @@ export class ConfigComponent implements OnInit, OnDestroy {
}),
);

this.subscriptions.push(
this.configService.getVersion().subscribe(version => {
this.version = version;
}),
);

this.subscriptions.push(
this.tagService.getTags().subscribe(tags => {
this.tags = tags;
Expand Down
5 changes: 5 additions & 0 deletions client/src/app/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export class ConfigService {
);
}

public getVersion(): Observable<string> {
// As json because of incorrect typings.
return this.httpClient.get<string>('/api/version', { responseType: 'text' as 'json' });
}

public getConfiguration(): ReplaySubject<Configuration.Main> {
return this.configReplay;
}
Expand Down
15 changes: 15 additions & 0 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ function readJsonSync(file: string): Configuration.Main {
return JSON.parse(StripJsonComments(FS.readFileSync(file).toString()));
}

function getVersion(): string {
try {
const version = FS.readFileSync('./version')
.toString()
.trim();
console.log(`Version file found: ${version}`);
return version;
} catch (_err) {
console.warn('Failed to load version file. Using default.');
return 'DEVELOPMENT';
}
}

export const VERSION_NAME = getVersion();

const DEFAULTS: any = {
port: 3523,
// Enabled pHash generation during auto-import.
Expand Down
6 changes: 5 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as Utils from './utils';
import { Database } from './types';
import { setup as setupDb } from './database';
import { wrap } from './express-async';
import Config from './config';
import Config, { VERSION_NAME } from './config';

// Routes
import * as ActorRouter from './routes/actors';
Expand All @@ -37,6 +37,10 @@ async function createServer(db: Database): Promise<Server> {
app.use('/api/insights', await InsightsRouter.create(db));
app.use('/api/tasks', await TasksRouter.create(db, io));

app.get('/api/version', (_req: Request, res: Response) => {
res.send(VERSION_NAME);
});

if (!require.main) {
throw new Error('require.main undefned');
}
Expand Down

0 comments on commit 7d02faf

Please sign in to comment.