mirror of
https://github.com/sharevb/it-tools.git
synced 2026-12-01 09:22:15 +03:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42f39bfa6e | ||
|
|
130183cb36 | ||
|
|
43922ae5f9 | ||
|
|
c906f11745 |
No files matched your search
Vendored
+4
-5
@@ -11,6 +11,7 @@ declare module '@vue/runtime-core' {
|
|||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
'404.page': typeof import('./src/pages/404.page.vue')['default']
|
'404.page': typeof import('./src/pages/404.page.vue')['default']
|
||||||
About: typeof import('./src/pages/About.vue')['default']
|
About: typeof import('./src/pages/About.vue')['default']
|
||||||
|
ApiTester: typeof import('./src/tools/api-tester/api-tester.vue')['default']
|
||||||
App: typeof import('./src/App.vue')['default']
|
App: typeof import('./src/App.vue')['default']
|
||||||
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
|
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
|
||||||
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
|
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
|
||||||
@@ -102,7 +103,6 @@ declare module '@vue/runtime-core' {
|
|||||||
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
||||||
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
||||||
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
||||||
IpGeoLocation: typeof import('./src/tools/ip-geo-location/ip-geo-location.vue')['default']
|
|
||||||
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
||||||
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
|
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
|
||||||
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
|
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
|
||||||
@@ -127,13 +127,13 @@ declare module '@vue/runtime-core' {
|
|||||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||||
NA: typeof import('naive-ui')['NA']
|
|
||||||
NAlert: typeof import('naive-ui')['NAlert']
|
|
||||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||||
|
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||||
NCode: typeof import('naive-ui')['NCode']
|
NCode: typeof import('naive-ui')['NCode']
|
||||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDivider: typeof import('naive-ui')['NDivider']
|
NDivider: typeof import('naive-ui')['NDivider']
|
||||||
|
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||||
NGi: typeof import('naive-ui')['NGi']
|
NGi: typeof import('naive-ui')['NGi']
|
||||||
@@ -141,13 +141,12 @@ declare module '@vue/runtime-core' {
|
|||||||
NH1: typeof import('naive-ui')['NH1']
|
NH1: typeof import('naive-ui')['NH1']
|
||||||
NH3: typeof import('naive-ui')['NH3']
|
NH3: typeof import('naive-ui')['NH3']
|
||||||
NIcon: typeof import('naive-ui')['NIcon']
|
NIcon: typeof import('naive-ui')['NIcon']
|
||||||
|
NInput: typeof import('naive-ui')['NInput']
|
||||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||||
NLabel: typeof import('naive-ui')['NLabel']
|
NLabel: typeof import('naive-ui')['NLabel']
|
||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
NP: typeof import('naive-ui')['NP']
|
|
||||||
NProgress: typeof import('naive-ui')['NProgress']
|
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
NSpin: typeof import('naive-ui')['NSpin']
|
NSpin: typeof import('naive-ui')['NSpin']
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const props = withDefaults(
|
|||||||
language?: string
|
language?: string
|
||||||
copyPlacement?: 'top-right' | 'bottom-right' | 'outside' | 'none'
|
copyPlacement?: 'top-right' | 'bottom-right' | 'outside' | 'none'
|
||||||
copyMessage?: string
|
copyMessage?: string
|
||||||
|
wordWrap?: boolean
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
followHeightOf: null,
|
followHeightOf: null,
|
||||||
@@ -47,7 +48,7 @@ const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : copyMessage.
|
|||||||
:style="height ? `min-height: ${height - 40 /* card padding */ + 10 /* negative margin compensation */}px` : ''"
|
:style="height ? `min-height: ${height - 40 /* card padding */ + 10 /* negative margin compensation */}px` : ''"
|
||||||
>
|
>
|
||||||
<n-config-provider :hljs="hljs">
|
<n-config-provider :hljs="hljs">
|
||||||
<n-code :code="value" :language="language" :trim="false" data-test-id="area-content" />
|
<n-code :code="value" :language="language" :word-wrap="wordWrap" :trim="false" data-test-id="area-content" />
|
||||||
</n-config-provider>
|
</n-config-provider>
|
||||||
</n-scrollbar>
|
</n-scrollbar>
|
||||||
<div absolute right-10px top-10px>
|
<div absolute right-10px top-10px>
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
function useDebouncedRef<T>(initialValue: T, delay: number, immediate: boolean = false) {
|
|
||||||
const state = ref(initialValue);
|
|
||||||
const debouncedRef = customRef((track, trigger) => ({
|
|
||||||
get() {
|
|
||||||
track();
|
|
||||||
return state.value;
|
|
||||||
},
|
|
||||||
set: _.debounce(
|
|
||||||
(value) => {
|
|
||||||
state.value = value;
|
|
||||||
trigger();
|
|
||||||
},
|
|
||||||
delay,
|
|
||||||
{ leading: immediate },
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
return debouncedRef;
|
|
||||||
}
|
|
||||||
export default useDebouncedRef;
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { useRouteQuery } from '@vueuse/router';
|
import { useRouteQuery } from '@vueuse/router';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
import { useStorage } from '@vueuse/core';
|
||||||
|
|
||||||
export { useQueryParam };
|
export { useQueryParam, useQueryParamOrStorage };
|
||||||
|
|
||||||
const transformers = {
|
const transformers = {
|
||||||
number: {
|
number: {
|
||||||
@@ -16,6 +17,12 @@ const transformers = {
|
|||||||
fromQuery: (value: string) => value.toLowerCase() === 'true',
|
fromQuery: (value: string) => value.toLowerCase() === 'true',
|
||||||
toQuery: (value: boolean) => (value ? 'true' : 'false'),
|
toQuery: (value: boolean) => (value ? 'true' : 'false'),
|
||||||
},
|
},
|
||||||
|
object: {
|
||||||
|
fromQuery: (value: string) => {
|
||||||
|
return JSON.parse(value);
|
||||||
|
},
|
||||||
|
toQuery: (value: object) => JSON.stringify(value),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue: T }) {
|
function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue: T }) {
|
||||||
@@ -33,3 +40,27 @@ function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue:
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useQueryParamOrStorage<T>({ name, storageName, defaultValue }: { name: string; storageName: string; defaultValue: T }) {
|
||||||
|
const type = typeof defaultValue;
|
||||||
|
const transformer = transformers[type as keyof typeof transformers] ?? transformers.string;
|
||||||
|
|
||||||
|
const storageRef = useStorage(storageName, defaultValue);
|
||||||
|
const proxyDefaultValue = transformer.toQuery(defaultValue as never);
|
||||||
|
const proxy = useRouteQuery(name, proxyDefaultValue);
|
||||||
|
|
||||||
|
const r = ref(defaultValue);
|
||||||
|
|
||||||
|
watch(r,
|
||||||
|
(value) => {
|
||||||
|
proxy.value = transformer.toQuery(value as never);
|
||||||
|
storageRef.value = value as never;
|
||||||
|
},
|
||||||
|
{ deep: true });
|
||||||
|
|
||||||
|
r.value = (proxy.value && proxy.value !== proxyDefaultValue
|
||||||
|
? transformer.fromQuery(proxy.value) as unknown as T
|
||||||
|
: storageRef.value as T) as never;
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||||
|
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||||
|
|
||||||
|
interface KeyValuePair {
|
||||||
|
key: string
|
||||||
|
value?: string
|
||||||
|
}
|
||||||
|
const baseUrl = useQueryParamOrStorage({ name: 'url', storageName: 'api-tester:url', defaultValue: '' });
|
||||||
|
const method = useQueryParamOrStorage({ name: 'method', storageName: 'api-tester:m', defaultValue: 'POST' });
|
||||||
|
const queryParams = useQueryParamOrStorage<KeyValuePair[]>({ name: 'params', storageName: 'api-tester:params', defaultValue: [] });
|
||||||
|
const headers = useQueryParamOrStorage<KeyValuePair[]>({ name: 'headers', storageName: 'api-tester:headers', defaultValue: [] });
|
||||||
|
const contentType = useQueryParamOrStorage({ name: 'ct', storageName: 'api-tester:ct', defaultValue: 'application/json' });
|
||||||
|
const body = useQueryParamOrStorage({ name: 'body', storageName: 'api-tester:body', defaultValue: '' });
|
||||||
|
const noCORS = ref(false);
|
||||||
|
const apiCallResult = ref();
|
||||||
|
|
||||||
|
const inprogress = ref(false);
|
||||||
|
async function callAPI() {
|
||||||
|
const url = new URL(baseUrl.value);
|
||||||
|
for (const kv of queryParams.value) {
|
||||||
|
if (!kv.key) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
url.searchParams.append(kv.key, kv.value || '');
|
||||||
|
}
|
||||||
|
const queryHeaders = [] as [string, string][];
|
||||||
|
for (const kv of headers.value) {
|
||||||
|
if (!kv.key) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
queryHeaders.push([kv.key, kv.value || '']);
|
||||||
|
}
|
||||||
|
queryHeaders.push(['Content-Type', contentType.value || '']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: method.value,
|
||||||
|
headers: queryHeaders,
|
||||||
|
body: (method.value === 'GET' || method.value === 'HEAD') ? null : body.value,
|
||||||
|
mode: noCORS.value ? 'no-cors' : 'cors',
|
||||||
|
});
|
||||||
|
|
||||||
|
let responseText = await response.text();
|
||||||
|
try {
|
||||||
|
responseText = JSON.stringify(JSON.parse(responseText), null, 2);
|
||||||
|
}
|
||||||
|
catch (_) {
|
||||||
|
}
|
||||||
|
apiCallResult.value = {
|
||||||
|
code: response.status,
|
||||||
|
error: '',
|
||||||
|
result: responseText,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (err: any) {
|
||||||
|
apiCallResult.value = {
|
||||||
|
code: -1,
|
||||||
|
error: err.toString(),
|
||||||
|
result: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function emptyKeyPair() {
|
||||||
|
return {
|
||||||
|
key: '',
|
||||||
|
value: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-card title="API Calling">
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="baseUrl"
|
||||||
|
label="Base API Url"
|
||||||
|
placeholder="Base API Url"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
|
||||||
|
<c-select
|
||||||
|
v-model:value="method"
|
||||||
|
label="HTTP Method:"
|
||||||
|
:options="['GET', 'POST', 'PUT', 'DELETE', 'PATCH']"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
|
||||||
|
<c-card title="Headers" mb-2>
|
||||||
|
<n-dynamic-input v-model:value="headers" :on-create="emptyKeyPair">
|
||||||
|
<template #create-button-default>
|
||||||
|
Add a new HTTP Header
|
||||||
|
</template>
|
||||||
|
<template #default="{ value }">
|
||||||
|
<div v-if="value" w-100 flex justify-center gap-2>
|
||||||
|
<c-input-text v-model:value="value.key" placeholder="Header Name" type="text" />
|
||||||
|
<c-input-text v-model:value="value.value" placeholder="Value" type="text" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</n-dynamic-input>
|
||||||
|
<c-select
|
||||||
|
v-model:value="contentType"
|
||||||
|
label="Content-Type:"
|
||||||
|
:options="['application/json', 'text/plain']"
|
||||||
|
mt-2
|
||||||
|
/>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card title="Query Parameters" mb-2>
|
||||||
|
<n-dynamic-input v-model:value="queryParams" :on-create="emptyKeyPair">
|
||||||
|
<template #create-button-default>
|
||||||
|
Add a new Query Parameter
|
||||||
|
</template>
|
||||||
|
<template #default="{ value }">
|
||||||
|
<div v-if="value" w-100 flex justify-center gap-2>
|
||||||
|
<c-input-text v-model:value="value.key" placeholder="Param Name" type="text" />
|
||||||
|
<c-input-text v-model:value="value.value" placeholder="Value" type="text" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</n-dynamic-input>
|
||||||
|
</c-card>
|
||||||
|
<c-input-text
|
||||||
|
v-if="method !== 'GET' && method !== 'HEAD'"
|
||||||
|
v-model:value="body"
|
||||||
|
label="Body"
|
||||||
|
placeholder="HTTP Query body"
|
||||||
|
multiline
|
||||||
|
monospace
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
|
||||||
|
<n-checkbox v-model:checked="noCORS">
|
||||||
|
No CORS
|
||||||
|
</n-checkbox>
|
||||||
|
|
||||||
|
<div mt-5 flex justify-center>
|
||||||
|
<c-button secondary @click="callAPI">
|
||||||
|
Call API
|
||||||
|
</c-button>
|
||||||
|
</div>
|
||||||
|
</c-card>
|
||||||
|
<n-spin
|
||||||
|
v-if="inprogress"
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
<c-alert v-if="!inprogress && apiCallResult && apiCallResult.code !== 200" type="error" mt-12 title="Error while calling API">
|
||||||
|
<p><strong>Status code = {{ apiCallResult.code }}</strong></p>
|
||||||
|
<TextareaCopyable :value="apiCallResult.error" copy-placement="none" />
|
||||||
|
</c-alert>
|
||||||
|
<c-card v-if="!inprogress && apiCallResult && apiCallResult.code === 200" mt-12 title="API Call result">
|
||||||
|
<TextareaCopyable :value="apiCallResult.result" word-wrap />
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { World } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'API Tester',
|
||||||
|
path: '/api-tester',
|
||||||
|
description: 'HTTP API Tester',
|
||||||
|
keywords: ['api', 'http', 'call', 'tester'],
|
||||||
|
component: () => import('./api-tester.vue'),
|
||||||
|
icon: World,
|
||||||
|
createdAt: new Date('2024-05-11'),
|
||||||
|
});
|
||||||
@@ -4,7 +4,6 @@ import emojiKeywords from 'emojilib';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import type { EmojiInfo } from './emoji.types';
|
import type { EmojiInfo } from './emoji.types';
|
||||||
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
||||||
import useDebouncedRef from '@/composable/debouncedref';
|
|
||||||
|
|
||||||
const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join('');
|
const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join('');
|
||||||
const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined;
|
const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined;
|
||||||
@@ -24,7 +23,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _
|
|||||||
.map((emojiInfos, group) => ({ group, emojiInfos }))
|
.map((emojiInfos, group) => ({ group, emojiInfos }))
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
const searchQuery = useDebouncedRef('', 500);
|
const searchQuery = ref('');
|
||||||
|
|
||||||
const { searchResult } = useFuzzySearch({
|
const { searchResult } = useFuzzySearch({
|
||||||
search: searchQuery,
|
search: searchQuery,
|
||||||
|
|||||||
+3
-10
@@ -5,8 +5,8 @@ import { tool as basicAuthGenerator } from './basic-auth-generator';
|
|||||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||||
|
|
||||||
import { tool as textToUnicode } from './text-to-unicode';
|
import { tool as textToUnicode } from './text-to-unicode';
|
||||||
import { tool as ipGeoLocation } from './ip-geo-location';
|
|
||||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||||
|
import { tool as apiTester } from './api-tester';
|
||||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||||
@@ -129,6 +129,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
httpStatusCodes,
|
httpStatusCodes,
|
||||||
jsonDiff,
|
jsonDiff,
|
||||||
safelinkDecoder,
|
safelinkDecoder,
|
||||||
|
apiTester,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -153,15 +154,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Network',
|
name: 'Network',
|
||||||
components: [
|
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
|
||||||
ipv4SubnetCalculator,
|
|
||||||
ipv4AddressConverter,
|
|
||||||
ipv4RangeExpander,
|
|
||||||
macAddressLookup,
|
|
||||||
macAddressGenerator,
|
|
||||||
ipv6UlaGenerator,
|
|
||||||
ipGeoLocation,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Math',
|
name: 'Math',
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import { World } from '@vicons/tabler';
|
|
||||||
import { defineTool } from '../tool';
|
|
||||||
|
|
||||||
export const tool = defineTool({
|
|
||||||
name: 'IP Geo Location',
|
|
||||||
path: '/ip-geo-location',
|
|
||||||
description: 'Retrieve information about an IPv4/6 address or domain location',
|
|
||||||
keywords: ['ip', 'domain', 'geo', 'location'],
|
|
||||||
component: () => import('./ip-geo-location.vue'),
|
|
||||||
icon: World,
|
|
||||||
createdAt: new Date('2024-01-17'),
|
|
||||||
});
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
|
|
||||||
|
|
||||||
const ip = ref('8.8.8.8');
|
|
||||||
const errorMessage = ref('');
|
|
||||||
|
|
||||||
const fields: Array<{ field: string; name: string }> = [
|
|
||||||
{ field: 'ip', name: 'IP' },
|
|
||||||
{ field: 'hostname', name: 'Host Name' },
|
|
||||||
{ field: 'country', name: 'Country Code' },
|
|
||||||
{ field: 'region', name: 'Region/state Code' },
|
|
||||||
{ field: 'city', name: 'City' },
|
|
||||||
{ field: 'postal', name: 'Postal Code' },
|
|
||||||
{ field: 'loc', name: 'Latitude/Longitude' },
|
|
||||||
{ field: 'timezone', name: 'Timezone' },
|
|
||||||
{ field: 'org', name: 'Organization Name' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const geoInfos = ref<CKeyValueListItems>([]);
|
|
||||||
const geoInfosData = ref<{
|
|
||||||
loc?: string
|
|
||||||
}>({});
|
|
||||||
const status = ref<'pending' | 'error' | 'success'>('pending');
|
|
||||||
const token = useStorage('ip-geoloc:token', '');
|
|
||||||
|
|
||||||
const openStreetMapUrl = computed(
|
|
||||||
() => {
|
|
||||||
const [gpsLatitude, gpsLongitude] = geoInfosData.value.loc?.split(',') || [];
|
|
||||||
return gpsLatitude && gpsLongitude ? `https://www.openstreetmap.org/?mlat=${gpsLatitude}&mlon=${gpsLongitude}#map=18/${gpsLatitude}/${gpsLongitude}` : undefined;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
async function onGetInfos() {
|
|
||||||
try {
|
|
||||||
status.value = 'pending';
|
|
||||||
|
|
||||||
const geoInfoQueryResponse = await fetch(
|
|
||||||
token.value !== ''
|
|
||||||
? `https://ipinfo.io/${ip.value}/json?token=${token.value}`
|
|
||||||
: `https://ipinfo.io/${ip.value}/json`);
|
|
||||||
if (!geoInfoQueryResponse.ok) {
|
|
||||||
throw geoInfoQueryResponse.statusText;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await geoInfoQueryResponse.json();
|
|
||||||
|
|
||||||
const allGeoInfos = [];
|
|
||||||
for (const field of fields) {
|
|
||||||
if (data[field.field]) {
|
|
||||||
allGeoInfos.push({
|
|
||||||
label: field.name,
|
|
||||||
value: data[field.field],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
status.value = 'success';
|
|
||||||
geoInfos.value = allGeoInfos;
|
|
||||||
geoInfosData.value = data;
|
|
||||||
}
|
|
||||||
catch (e: any) {
|
|
||||||
errorMessage.value = e.toString();
|
|
||||||
status.value = 'error';
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<div flex items-center gap-2>
|
|
||||||
<c-input-text
|
|
||||||
v-model:value="ip"
|
|
||||||
placeholder="Enter an IPv4/6"
|
|
||||||
@update:value="() => { status = 'pending' }"
|
|
||||||
/>
|
|
||||||
<c-button align-center @click="onGetInfos">
|
|
||||||
Get GEO Location Infos
|
|
||||||
</c-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<details mt-2>
|
|
||||||
<summary>Optional ipinfo.io token</summary>
|
|
||||||
<c-input-text
|
|
||||||
v-model:value="token"
|
|
||||||
placeholder="Optional ipinfo.io token"
|
|
||||||
@update:value="() => { status = 'pending' }"
|
|
||||||
/>
|
|
||||||
<n-p>
|
|
||||||
<n-a href="https://ipinfo.io/">
|
|
||||||
Signup for a free token
|
|
||||||
</n-a>
|
|
||||||
</n-p>
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<n-divider />
|
|
||||||
|
|
||||||
<c-card v-if="status === 'pending'" mt-5>
|
|
||||||
Click on button above to get latest infos
|
|
||||||
</c-card>
|
|
||||||
|
|
||||||
<c-card v-if="status === 'success' && openStreetMapUrl" mt-4>
|
|
||||||
<c-button :href="openStreetMapUrl" target="_blank">
|
|
||||||
Localize on Open Street Map
|
|
||||||
</c-button>
|
|
||||||
</c-card>
|
|
||||||
|
|
||||||
<c-card v-if="status === 'success'" mt-5>
|
|
||||||
<c-key-value-list :items="geoInfos" />
|
|
||||||
</c-card>
|
|
||||||
|
|
||||||
<n-alert v-if="status === 'error'" title="Errors occured" type="error" mt-5>
|
|
||||||
{{ errorMessage }}
|
|
||||||
</n-alert>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
Reference in new issue
Block a user