From 3f3314a62a7b0ae60a2ebd7be628f9146b23d783 Mon Sep 17 00:00:00 2001 From: Nato Boram Date: Wed, 8 Jul 2020 16:47:13 -0400 Subject: [PATCH] Add more icons --- CHANGELOG.md | 3 ++- src/app/pages/pages.component.html | 7 ++---- src/app/pages/pages.component.ts | 33 ++++++++++++++++++++++++----- src/app/services/gateway.service.ts | 8 +++---- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e15a7..be8ad0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this ### Added - Support for subdomain gateways -- Strict Mode +- Strict mode +- More icons ### Changed diff --git a/src/app/pages/pages.component.html b/src/app/pages/pages.component.html index 5b4e2d8..25b413d 100644 --- a/src/app/pages/pages.component.html +++ b/src/app/pages/pages.component.html @@ -36,13 +36,10 @@ - + diff --git a/src/app/pages/pages.component.ts b/src/app/pages/pages.component.ts index fb61c2f..52cc2dd 100644 --- a/src/app/pages/pages.component.ts +++ b/src/app/pages/pages.component.ts @@ -2,6 +2,7 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit, ViewChild } from '@angular/core'; import { MatTable, MatTableDataSource } from '@angular/material/table'; import { Subscription } from 'rxjs'; +import { environment } from '../../environments/environment'; import { Protocol } from '../enums/protocol.enum'; import { GatewayService } from '../services/gateway.service'; @@ -19,7 +20,7 @@ export class PagesComponent implements OnInit { ipns = ''; readonly dataSource = new MatTableDataSource([]); - readonly displayedColumns: ['error', 'gateway'] = ['error', 'gateway']; + readonly displayedColumns: ['icon', 'gateway'] = ['icon', 'gateway']; readonly subscriptions: Subscription[] = []; constructor( @@ -31,10 +32,12 @@ export class PagesComponent implements OnInit { } cacheIPFS(): void { + this.ipfs = this.ipfs.trim(); this.cache(Protocol.IPFS, this.ipfs); } cacheIPNS(): void { + this.ipns = this.ipns.trim(); this.cache(Protocol.IPNS, this.ipns); } @@ -55,20 +58,40 @@ export class PagesComponent implements OnInit { this.gateways.forEach((gateway): void => { this.subscriptions.push( - this.gatewayService.get(gateway, protocol, hashpath).subscribe((): void => { - this.dataSource.data.push({ gateway: this.gatewayService.url(gateway, protocol, hashpath), error: null }); + this.gatewayService.get(gateway, protocol, hashpath).subscribe((resp): void => { + this.dataSource.data.push({ + gateway: this.gatewayService.url(gateway, protocol, hashpath), + message: resp.statusText, + icon: this.icon(resp.status) + }); this.matTable.renderRows(); }, (error: HttpErrorResponse): void => { - this.dataSource.data.push({ gateway: this.gatewayService.url(gateway, protocol, hashpath), error }); + this.dataSource.data.push({ + gateway: this.gatewayService.url(gateway, protocol, hashpath), + message: error.statusText, + icon: this.icon(error.status) + }); this.matTable.renderRows(); }) ); }); } + private icon(status: number): string { + if (status >= 200 && status < 300) return '✅'; + switch (status) { + case 0: return '❌'; + case 403: return '⛔'; + case 404: return '❓'; + case 500: return '❗'; + default: return environment.production ? '❌' : '🤦‍♂️'; + } + } + } interface Result { gateway: string; - error: HttpErrorResponse | null; + message: string; + icon: string; } diff --git a/src/app/services/gateway.service.ts b/src/app/services/gateway.service.ts index 4eddfd3..28b7f8d 100644 --- a/src/app/services/gateway.service.ts +++ b/src/app/services/gateway.service.ts @@ -1,4 +1,4 @@ -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpResponseBase } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { environment } from '../../environments/environment'; @@ -26,9 +26,9 @@ export class GatewayService { throw new Error('Couldn\'t find environment nor base.') } - get(gateway: string, protocol: Protocol, hashpath: string): Observable { - return this.http.get(`${this.url(gateway, protocol, hashpath)}#x-ipfs-companion-no-redirect`, { - responseType: 'blob' as 'json' + get(gateway: string, protocol: Protocol, hashpath: string): Observable { + return this.http.get(`${this.url(gateway, protocol, hashpath)}#x-ipfs-companion-no-redirect`, { + observe: 'response' }); }
Status -
-
-
-
+ {{ element.icon }}