Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Jan 19, 2024
1 parent 2d56b60 commit 54b3095
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 29 deletions.
30 changes: 29 additions & 1 deletion src/app/error-page/error-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { IrisinterfaceService } from '../services/irisinterface.service';

@Component({
selector: 'app-error-page',
templateUrl: './error-page.component.html',
styleUrls: ['./error-page.component.scss'],
})
export class ErrorPageComponent {
constructor(private router: Router) {}
isServerOnline = false;

constructor(
private router: Router,
private apiService: IrisinterfaceService
) {}

ngOnInit(): void {
this.checkIfServerOnline();
const interval = setInterval(() => {
this.checkIfServerOnline();
if (this.isServerOnline && this.router.url == '/error') {
this.router.navigate(['/']);
clearInterval(interval);
}
}, 1000);
}

checkIfServerOnline() {
this.apiService.isServerOnline().subscribe({
next: (data: any) => {
this.isServerOnline = true;
},
error: (err) => {
this.isServerOnline = false;
},
});
}

goToServerSettings() {
this.router.navigate(['/settings/server']);
Expand Down
3 changes: 2 additions & 1 deletion src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export class HomeComponent {
ngOnInit(): void {
this.chapterManager.init();
this.checkIfServerOnline();
setInterval(() => {
const interval = setInterval(() => {
this.checkIfServerOnline();
if (!this.isServerOnline && this.router.url == '/') {
this.router.navigate(['/error']);
clearInterval(interval);
}
}, 5000);
}
Expand Down
64 changes: 43 additions & 21 deletions src/app/services/irisinterface.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LocalStorageService } from './local-storage.service';
providedIn: 'root',
})
export class IrisinterfaceService {
public static protocol: string = 'http';
public static host: string = 'localhost';
public static port: number = 52773;

Expand All @@ -23,7 +24,8 @@ export class IrisinterfaceService {
isServerOnline() {
return this.http
.get<string>(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -38,7 +40,8 @@ export class IrisinterfaceService {

getVersion(): Observable<any> {
return this.http.get(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -56,7 +59,8 @@ export class IrisinterfaceService {
// make request and handle 404 status
return this.http
.get<User>(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -78,7 +82,8 @@ export class IrisinterfaceService {

getAllChapters(): Observable<any> {
return this.http.get(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -89,7 +94,8 @@ export class IrisinterfaceService {
verifyChapter(chapterName: string, password: string): Observable<any> {
return this.http
.get(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -116,7 +122,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.get(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -152,7 +159,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -181,7 +189,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -208,7 +217,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -238,7 +248,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -267,7 +278,8 @@ export class IrisinterfaceService {
name = name.replace(/ /g, '_');
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -292,7 +304,8 @@ export class IrisinterfaceService {
name = name.replace(/ /g, '_');
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -311,7 +324,8 @@ export class IrisinterfaceService {
getFile(name: string) {
return this.http
.get(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -332,7 +346,8 @@ export class IrisinterfaceService {
translateText(text: string, to: string): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -351,7 +366,8 @@ export class IrisinterfaceService {
getAllImageNames(): Observable<any> {
return this.http
.get(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -371,7 +387,8 @@ export class IrisinterfaceService {
getAllFileNames(): Observable<any> {
return this.http
.get(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand All @@ -396,7 +413,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -431,7 +449,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -465,7 +484,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -499,7 +519,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down Expand Up @@ -535,7 +556,8 @@ export class IrisinterfaceService {
): Observable<any> {
return this.http
.post(
'http://' +
IrisinterfaceService.protocol +
'://' +
IrisinterfaceService.host +
':' +
IrisinterfaceService.port +
Expand Down
27 changes: 25 additions & 2 deletions src/app/services/local-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ export class LocalStorageService {
IrisinterfaceService.port = serverPort;
}

getServerProtocol(): string {
let protocol = localStorage.getItem('serverProtocol');
if (protocol == null) {
return 'http';
}
return protocol;
}

setServerProtocol(protocol: string) {
LocalStorageService.setLS('serverProtocol', protocol);
IrisinterfaceService.protocol = protocol;
}

getUserName(): string | null {
return localStorage.getItem('userName');
}
Expand Down Expand Up @@ -190,14 +203,24 @@ export class LocalStorageService {
return null;
}

addServerConnection(name: string, host: string, port: number) {
addServerConnection(
name: string,
host: string,
port: number,
protocol: string
) {
let serverConnections = this.getAllServerConnections();
for (let i = 0; i < serverConnections.length; i++) {
if (serverConnections[i].name == name) {
serverConnections.splice(i, 1);
}
}
serverConnections.push({ name: name, host: host, port: port });
serverConnections.push({
name: name,
host: host,
port: port,
protocol: protocol,
});
LocalStorageService.setLS(
'serverConnections',
JSON.stringify(serverConnections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
<p class="label">Connection Name</p>
<input type="text" class="action" placeholder="Name" [(ngModel)]="name" />
</div>
<div class="row">
<p class="label">Protocol</p>
<select name="Level" [(ngModel)]="protocol" style="width: 110px">
<option value="http">http</option>
<option value="https">https</option>
</select>
</div>
<div class="row">
<p class="label">Host</p>
<input type="text" class="action" placeholder="Host" [(ngModel)]="host" />
Expand Down
Loading

0 comments on commit 54b3095

Please sign in to comment.