use different api for country code/flag that support https

This commit is contained in:
RaidMax 2021-07-02 10:04:56 -05:00
parent 33a427bb8a
commit 8b06da5783
3 changed files with 28 additions and 10 deletions

View File

@ -23,7 +23,7 @@
</div> </div>
<!-- Name/Level Column --> <!-- Name/Level Column -->
<div class="w-50 d-block d-lg-inline-flex flex-column flex-fill text-center text-lg-left pb-3 pb-lg-0 pt-3 pt-lg-0 pl-3 pr-3 ml-auto mr-auto" style="overflow-wrap: anywhere"> <div class="w-50 d-block d-lg-inline-flex flex-column flex-fill text-center text-lg-left pb-3 pb-lg-0 pt-3 pt-lg-0 pl-3 pr-3 ml-auto mr-auto" style="overflow-wrap: anywhere">
<div class="mt-n2 d-block d-lg-inline-flex"> <div class="mt-n2 d-block d-lg-inline-flex @(ViewBag.Authorized ? "" : "flex-fill")">
<div id="profile_name" class="client-name h1 mb-0"> <div id="profile_name" class="client-name h1 mb-0">
<color-code value="@Model.Name" allow="@ViewBag.EnableColorCodes"></color-code> <color-code value="@Model.Name" allow="@ViewBag.EnableColorCodes"></color-code>
</div> </div>
@ -35,12 +35,9 @@
@if (ViewBag.Authorized) @if (ViewBag.Authorized)
{ {
<div class="d-flex flex-row justify-content-start flex-fill flex-column flex-md-row mr-2 mb-2 mb-md-0"> <div class="d-flex flex-row justify-content-start flex-fill flex-column flex-lg-row mr-lg-2 mb-2 mb-md-0">
<div class="ip-lookup-profile align-self-center mr-0 mr-md-2" <div class="ip-lookup-profile align-self-center mr-0 mr-lg-2 ml-lg-n1" data-ip="@Model.IPAddress"></div>
data-ip="@Model.IPAddress" <div id="ip_lookup_country" class="h4 mb-2 mb-lg-0 align-self-center text-muted"></div>
style="background-image: url('http://api.hostip.info/flag.php?ip=@Model.IPAddress'); height: 2.5rem; min-width: 3.0rem; background-size: contain; background-repeat: no-repeat; background-position: center;">
</div>
<div id="ip_lookup_country" class="h4 mb-0 align-self-center text-muted"></div>
</div> </div>
<div id="profile_aliases" class="text-muted pt-0 pt-lg-2 pb-2"> <div id="profile_aliases" class="text-muted pt-0 pt-lg-2 pb-2">

View File

@ -201,3 +201,11 @@
background-color: $dark; background-color: $dark;
color: $white !important; color: $white !important;
} }
.ip-lookup-profile {
height: 2.5rem;
min-width: 3.0rem;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
}

View File

@ -12,9 +12,22 @@
const ipAddresses = $('.ip-lookup-profile'); const ipAddresses = $('.ip-lookup-profile');
$.each(ipAddresses, function (index, address) { $.each(ipAddresses, function (index, address) {
$.get('http://ip-api.com/json/' + $(address).data('ip'), function (result) { let ip = $(address).data('ip');
const country = result['country']; if (ip.length === 0) {
$('#ip_lookup_country').text(country) return;
}
$.get('https://ip2c.org/' + ip, function (result) {
const countryCode = result.split(';')[1].toLowerCase();
const country = result.split(';')[3];
if (country === 'Unknown') {
return;
}
$('#ip_lookup_country').text(country);
if (countryCode !== 'zz' && countryCode !== '') {
$(address).css('background-image', `url(https://www.countryflags.io/${countryCode}/flat/64.png)`);
}
}); });
}); });