add flag support
This commit is contained in:
Generated
+17
-2
@@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "uvpn.shop",
|
"name": "uvpn.shop",
|
||||||
"version": "0.5.3",
|
"version": "0.5.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "uvpn.shop",
|
"name": "uvpn.shop",
|
||||||
"version": "0.5.3",
|
"version": "0.5.4",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lucide/vue": "^1.16.0",
|
"@lucide/vue": "^1.16.0",
|
||||||
"@tailwindcss/vite": "^4.3.0",
|
"@tailwindcss/vite": "^4.3.0",
|
||||||
"@tresjs/cientos": "^5.7.1",
|
"@tresjs/cientos": "^5.7.1",
|
||||||
"@tresjs/core": "^5.8.1",
|
"@tresjs/core": "^5.8.1",
|
||||||
|
"@tw-labs/countries": "^0.0.2",
|
||||||
"@vueuse/head": "^0.9.8",
|
"@vueuse/head": "^0.9.8",
|
||||||
"marked": "^18.0.5",
|
"marked": "^18.0.5",
|
||||||
"swiper": "^12.1.4",
|
"swiper": "^12.1.4",
|
||||||
@@ -1202,6 +1203,20 @@
|
|||||||
"vue": ">=3.4"
|
"vue": ">=3.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@tw-labs/countries": {
|
||||||
|
"version": "0.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tw-labs/countries/-/countries-0.0.2.tgz",
|
||||||
|
"integrity": "sha512-mnCpRLhpMPTCMTnV18nKjLrdZ+4bUZSxdOgFWqdsZSM62RwPk1ddQCTN2XtRAR2zcLzlX91iTg2kSJ006qmXlA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=17"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"react": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@tweenjs/tween.js": {
|
"node_modules/@tweenjs/tween.js": {
|
||||||
"version": "23.1.3",
|
"version": "23.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-23.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-23.1.3.tgz",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"@tailwindcss/vite": "^4.3.0",
|
"@tailwindcss/vite": "^4.3.0",
|
||||||
"@tresjs/cientos": "^5.7.1",
|
"@tresjs/cientos": "^5.7.1",
|
||||||
"@tresjs/core": "^5.8.1",
|
"@tresjs/core": "^5.8.1",
|
||||||
|
"@tw-labs/countries": "^0.0.2",
|
||||||
"@vueuse/head": "^0.9.8",
|
"@vueuse/head": "^0.9.8",
|
||||||
"marked": "^18.0.5",
|
"marked": "^18.0.5",
|
||||||
"swiper": "^12.1.4",
|
"swiper": "^12.1.4",
|
||||||
|
|||||||
@@ -33,15 +33,16 @@
|
|||||||
<img
|
<img
|
||||||
v-if="flagUrl"
|
v-if="flagUrl"
|
||||||
:src="flagUrl"
|
:src="flagUrl"
|
||||||
:alt="ipData.location.country_code"
|
:alt="countryCode"
|
||||||
class="w-4 h-3 object-cover rounded-sm"
|
class="w-4 h-3 object-cover rounded-sm"
|
||||||
@error="handleFlagError"
|
@error="handleFlagError"
|
||||||
/>
|
/>
|
||||||
<span v-if="ipData.location.city" class="hidden sm:inline">{{ ipData.location.city }}</span>
|
<span v-if="countryEmoji" class="text-base">{{ countryEmoji }}</span>
|
||||||
<span v-if="ipData.location.country" class="text-gray-600 dark:text-gray-300 font-medium">
|
<span v-if="ipData.location?.city" class="hidden sm:inline">{{ ipData.location.city }}</span>
|
||||||
|
<span v-if="ipData.location?.country" class="text-gray-600 dark:text-gray-300 font-medium">
|
||||||
{{ ipData.location.country }}
|
{{ ipData.location.country }}
|
||||||
</span>
|
</span>
|
||||||
<span v-if="ipData.asn.name" class="hidden md:inline text-gray-400">
|
<span v-if="ipData.asn?.name" class="hidden md:inline text-gray-400">
|
||||||
• {{ truncateText(ipData.asn.name, 30) }}
|
• {{ truncateText(ipData.asn.name, 30) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -72,12 +73,36 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
|
import { getAllCountries, withFlags } from '@tw-labs/countries'
|
||||||
|
|
||||||
const ipData = ref(null)
|
const ipData = ref(null)
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const error = ref(false)
|
const error = ref(false)
|
||||||
const flagError = ref(false)
|
const flagError = ref(false)
|
||||||
|
|
||||||
|
// Загружаем список стран один раз
|
||||||
|
const countriesList = getAllCountries()
|
||||||
|
|
||||||
|
// Функция поиска страны по названию
|
||||||
|
function findCountryByName(countryName) {
|
||||||
|
if (!countryName) return null
|
||||||
|
|
||||||
|
// Точное совпадение
|
||||||
|
const found = countriesList.find(
|
||||||
|
c => c.label.toLowerCase() === countryName.toLowerCase()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (found) return found
|
||||||
|
|
||||||
|
// Частичное совпадение (для "Russian Federation" vs "Russia" и т.п.)
|
||||||
|
const partial = countriesList.find(
|
||||||
|
c => countryName.toLowerCase().includes(c.label.toLowerCase()) ||
|
||||||
|
c.label.toLowerCase().includes(countryName.toLowerCase())
|
||||||
|
)
|
||||||
|
|
||||||
|
return partial || null
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchIp() {
|
async function fetchIp() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
error.value = false
|
error.value = false
|
||||||
@@ -87,7 +112,27 @@ async function fetchIp() {
|
|||||||
const response = await fetch('/api/v1/ip')
|
const response = await fetch('/api/v1/ip')
|
||||||
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
||||||
|
|
||||||
ipData.value = await response.json()
|
const data = await response.json()
|
||||||
|
|
||||||
|
// Находим код страны по названию
|
||||||
|
const countryName = data.location?.country
|
||||||
|
const foundCountry = findCountryByName(countryName)
|
||||||
|
const countryCode = foundCountry?.code || null
|
||||||
|
|
||||||
|
// Добавляем флаговые данные через withFlags
|
||||||
|
let countryWithFlags = null
|
||||||
|
if (foundCountry) {
|
||||||
|
countryWithFlags = withFlags(foundCountry)
|
||||||
|
}
|
||||||
|
|
||||||
|
ipData.value = {
|
||||||
|
...data,
|
||||||
|
location: {
|
||||||
|
...data.location,
|
||||||
|
computed_country_code: countryCode
|
||||||
|
},
|
||||||
|
_flags: countryWithFlags
|
||||||
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('IP fetch error:', err)
|
console.error('IP fetch error:', err)
|
||||||
@@ -100,13 +145,31 @@ async function fetchIp() {
|
|||||||
|
|
||||||
const isProtected = computed(() => {
|
const isProtected = computed(() => {
|
||||||
if (!ipData.value) return false
|
if (!ipData.value) return false
|
||||||
return ipData.value.security.vpn || ipData.value.security.proxy || ipData.value.security.tor
|
return ipData.value.security?.vpn || ipData.value.security?.proxy || ipData.value.security?.tor
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Код страны (вычисленный)
|
||||||
|
const countryCode = computed(() => {
|
||||||
|
return ipData.value?.location?.computed_country_code || null
|
||||||
|
})
|
||||||
|
|
||||||
|
// Emoji флага из withFlags
|
||||||
|
const countryEmoji = computed(() => {
|
||||||
|
return ipData.value?._flags?.flagEmoji || null
|
||||||
|
})
|
||||||
|
|
||||||
|
// URL флага
|
||||||
const flagUrl = computed(() => {
|
const flagUrl = computed(() => {
|
||||||
const countryCode = ipData.value?.location?.country_code
|
// Сначала пробуем взять SVG из withFlags
|
||||||
if (!countryCode || flagError.value) return null
|
if (ipData.value?._flags?.flagSvg && !flagError.value) {
|
||||||
return `https://flagcdn.com/${countryCode.toLowerCase()}.svg`
|
return ipData.value._flags.flagSvg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если нет — формируем сами через flagcdn
|
||||||
|
const code = countryCode.value
|
||||||
|
if (!code || flagError.value) return null
|
||||||
|
|
||||||
|
return `https://flagcdn.com/${code.toLowerCase()}.svg`
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleFlagError() {
|
function handleFlagError() {
|
||||||
|
|||||||
Reference in New Issue
Block a user