Clean code from outdated http based methods

This commit is contained in:
piotrpekala7 2020-11-04 00:12:29 +01:00
parent 288879ccb2
commit 149b68e037
13 changed files with 13 additions and 14 deletions

View File

@ -154,6 +154,6 @@ export class ImportApplianceComponent implements OnInit {
}
private getUploadPath(server: Server, emulator: string, filename: string) {
return `http://${server.host}:${server.port}/v2/${emulator}/images/${filename}`;
return `${server.protocol}//${server.host}:${server.port}/v2/${emulator}/images/${filename}`;
}
}

View File

@ -203,7 +203,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
this.nodesDataSource.changes.subscribe((nodes: Node[]) => {
if (!this.server) return;
nodes.forEach((node: Node) => {
node.symbol_url = `http://${this.server.host}:${this.server.port}/v2/symbols/${node.symbol}/raw`;
node.symbol_url = `${this.server.protocol}//${this.server.host}:${this.server.port}/v2/symbols/${node.symbol}/raw`;
});
this.nodes = nodes;

View File

@ -53,6 +53,7 @@ export class ServersComponent implements OnInit, OnDestroy {
this.serverService.checkServerVersion(server).subscribe(
(serverInfo) => {
if ((serverInfo.version.split('.')[1]>=2) && (serverInfo.version.split('.')[0]>=2)) {
if (!server.protocol) server.protocol = location.protocol as ServerProtocol;
if (!this.serverDatabase.find(server.name)) this.serverDatabase.addServer(server);
}
},

View File

@ -116,7 +116,7 @@ export class TemplateComponent implements OnInit, OnDestroy {
}
getImageSourceForTemplate(template: Template) {
return `http://${this.server.host}:${this.server.port}/v2/symbols/${template.symbol}/raw`;
return `${this.server.protocol}//${this.server.host}:${this.server.port}/v2/symbols/${template.symbol}/raw`;
}
ngOnDestroy() {

View File

@ -1,7 +1,7 @@
export type ServerAuthorization = 'basic' | 'none';
export type ServerLocation = 'local' | 'remote' | 'bundled';
export type ServerStatus = 'stopped' | 'starting' | 'running';
export type ServerProtocol = 'http' | 'https'
export type ServerProtocol = 'http:' | 'https:'
export class Server {
id: number;

View File

@ -19,7 +19,7 @@ export class ApplianceService {
}
getUploadPath(server: Server, emulator: string, filename: string) {
return `http://${server.host}:${server.port}/v2/compute/${emulator}/images/${filename}`;
return `${server.protocol}//${server.host}:${server.port}/v2/compute/${emulator}/images/${filename}`;
}
updateAppliances(server: Server): Observable<Appliance[]> {

View File

@ -14,7 +14,7 @@ export class ComputeService {
}
getUploadPath(server: Server, emulator: string, filename: string) {
return `http://${server.host}:${server.port}/v2/${emulator}/images/${filename}`;
return `${server.protocol}//${server.host}:${server.port}/v2/${emulator}/images/${filename}`;
}
getStatistics(server: Server): Observable<ComputeStatistics[]> {

View File

@ -176,9 +176,6 @@ export class HttpServer {
}
private getOptionsForServer<T extends HeadersOptions>(server: Server, url: string, options: T) {
console.log('Server ', server.protocol);
console.log('Location ', location.protocol);
if (server.host && server.port) {
if (!server.protocol) {
server.protocol = location.protocol as ServerProtocol;

View File

@ -14,7 +14,7 @@ export class IosService {
}
getImagePath(server: Server, filename: string): string {
return `http://${server.host}:${server.port}/v2/compute/dynamips/images/${filename}`;
return `${server.protocol}//${server.host}:${server.port}/v2/compute/dynamips/images/${filename}`;
}
getTemplates(server: Server): Observable<IosTemplate[]> {

View File

@ -22,7 +22,7 @@ export class IouService {
}
getImagePath(server: Server, filename: string): string {
return `http://${server.host}:${server.port}/v2/compute/iou/images/${filename}`;
return `${server.protocol}//${server.host}:${server.port}/v2/compute/iou/images/${filename}`;
}
addTemplate(server: Server, iouTemplate: any): Observable<any> {

View File

@ -69,11 +69,11 @@ export class ProjectService {
}
getUploadPath(server: Server, uuid: string, project_name: string) {
return `http://${server.host}:${server.port}/v2/projects/${uuid}/import?name=${project_name}`;
return `${server.protocol}//${server.host}:${server.port}/v2/projects/${uuid}/import?name=${project_name}`;
}
getExportPath(server: Server, project: Project) {
return `http://${server.host}:${server.port}/v2/projects/${project.project_id}/export`;
return `${server.protocol}//${server.host}:${server.port}/v2/projects/${project.project_id}/export`;
}
export(server: Server, project_id: string): Observable<any> {

View File

@ -20,7 +20,7 @@ export class QemuService {
}
getImagePath(server: Server, filename: string): string {
return `http://${server.host}:${server.port}/v2/compute/qemu/images/${filename}`;
return `${server.protocol}//${server.host}:${server.port}/v2/compute/qemu/images/${filename}`;
}
getBinaries(server: Server): Observable<QemuBinary[]> {

View File

@ -5,5 +5,6 @@ export function getTestServer(): Server {
server.host = '127.0.0.1';
server.port = 3080;
server.authorization = 'none';
server.protocol = 'http:';
return server;
}