You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
974 B
44 lines
974 B
import { crypto, toHashString } from "@std/crypto/mod.ts";
|
|
|
|
export interface Location {
|
|
country: string;
|
|
region: string;
|
|
}
|
|
|
|
interface InternalLocation {
|
|
status: string;
|
|
country: string;
|
|
countryCode: string;
|
|
region: string;
|
|
regionName: string;
|
|
city: string;
|
|
zip: string;
|
|
lat: number;
|
|
lon: number;
|
|
timezone: string;
|
|
isp: string;
|
|
org: string;
|
|
as: string;
|
|
query: string;
|
|
}
|
|
|
|
/** deviously lick (an ip's geolocation) */
|
|
export async function deviousLick(ip: string): Promise<Location> {
|
|
const res = await fetch(`http://ip-api.com/json/${ip}`);
|
|
|
|
const data: InternalLocation = await res.json();
|
|
|
|
return {
|
|
country: data.country,
|
|
region: data.regionName,
|
|
} as Location;
|
|
}
|
|
|
|
export async function hash(str: string): Promise<string> {
|
|
const digest = await crypto.subtle.digest(
|
|
"SHA3-256",
|
|
new TextEncoder().encode(str),
|
|
);
|
|
return toHashString(digest, "hex");
|
|
}
|