Show city, country and AS name in node page when available

This commit is contained in:
nymkappa 2022-07-12 21:07:38 +02:00
parent c6fa8c6172
commit f2983e28a3
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
2 changed files with 24 additions and 2 deletions

View File

@ -5,7 +5,7 @@ class NodesApi {
public async $getNode(public_key: string): Promise<any> {
try {
const query = `
SELECT nodes.*,
SELECT nodes.*, geo_names_as.names as as_organization, geo_names_city.names as city, geo_names_country.names as country,
(SELECT Count(*)
FROM channels
WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_count,
@ -16,10 +16,19 @@ class NodesApi {
FROM channels
WHERE status < 2 AND ( node1_public_key = ? OR node2_public_key = ? )) AS channels_capacity_avg
FROM nodes
LEFT JOIN geo_names geo_names_as on geo_names_as.id = as_number
LEFT JOIN geo_names geo_names_city on geo_names_city.id = city_id
LEFT JOIN geo_names geo_names_country on geo_names_country.id = country_id
WHERE public_key = ?
`;
const [rows]: any = await DB.query(query, [public_key, public_key, public_key, public_key, public_key, public_key, public_key]);
return rows[0];
if (rows.length > 0) {
rows[0].as_organization = JSON.parse(rows[0].as_organization);
rows[0].city = JSON.parse(rows[0].city);
rows[0].country = JSON.parse(rows[0].country);
return rows[0];
}
return null;
} catch (e) {
logger.err('$getNode error: ' + (e instanceof Error ? e.message : e));
throw e;

View File

@ -33,6 +33,13 @@
<app-sats [satoshis]="node.channels_capacity_avg"></app-sats><app-fiat [value]="node.channels_capacity_avg" digitsInfo="1.0-0"></app-fiat>
</td>
</tr>
<tr *ngIf="node.country || node.city">
<td i18n="location">Location</td>
<td>
<span *ngIf="node.country">{{ node.country.en }}</span>
<span *ngIf="node.city"> ({{ node.city.en }})</span>
</td>
</tr>
</tbody>
</table>
</div>
@ -56,6 +63,12 @@
<td i18n="address.balance">Color</td>
<td><div [ngStyle]="{'color': node.color}">{{ node.color }}</div></td>
</tr>
<tr *ngIf="node.country">
<td i18n="isp">ISP</td>
<td>
{{ node.as_organization }}
</td>
</tr>
</tbody>
</table>
</div>