feat: add meta geo
This commit is contained in:
@@ -9,8 +9,7 @@ export default function AdminPanelLoading() {
|
||||
text="Access only for users with ADMIN role."
|
||||
/>
|
||||
<div className="flex flex-col gap-5">
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-3 lg:grid-cols-3">
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
|
||||
+11
-7
@@ -7,21 +7,25 @@ export async function GET(req: NextRequest) {
|
||||
const url = new URL(req.url);
|
||||
const slug = url.searchParams.get("slug");
|
||||
const ip = url.searchParams.get("ip");
|
||||
const city = url.searchParams.get("city");
|
||||
const region = url.searchParams.get("region");
|
||||
const country = url.searchParams.get("country");
|
||||
const latitude = url.searchParams.get("latitude");
|
||||
const longitude = url.searchParams.get("longitude");
|
||||
if (!slug || !ip) return Response.json(null);
|
||||
|
||||
const res = await getUrlBySuffix(slug);
|
||||
if (res?.target && res?.active === 1) {
|
||||
console.log("[api/s]", ip, res.id);
|
||||
// TODO
|
||||
// console.log("[api/s]", ip, res.id);
|
||||
await createUserShortUrlMeta({
|
||||
urlId: res.id,
|
||||
click: 1,
|
||||
ip: ip ? ip.split(",")[0] : "127.0.0.1",
|
||||
city: "",
|
||||
region: "",
|
||||
country: "",
|
||||
latitude: "",
|
||||
longitude: "",
|
||||
city,
|
||||
region,
|
||||
country,
|
||||
latitude,
|
||||
longitude,
|
||||
});
|
||||
return Response.json(res.target);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,26 @@ export const docsConfig: DocsConfig = {
|
||||
// },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Examples",
|
||||
items: [
|
||||
{
|
||||
title: "Vercel Custom Domain",
|
||||
href: "/docs/examples/vercel",
|
||||
icon: "page",
|
||||
},
|
||||
{
|
||||
title: "Zeabur Custom Domain",
|
||||
href: "/docs/examples/zeabur",
|
||||
icon: "page",
|
||||
},
|
||||
{
|
||||
title: "Other",
|
||||
href: "/docs/examples/other",
|
||||
icon: "page",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Developer",
|
||||
items: [
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: Other
|
||||
description: Free parsing custom domain names.
|
||||
---
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: Vercel Custom Domain
|
||||
description: Free parsing of Vercel custom domain names.
|
||||
---
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: Zeabur Custom Domain
|
||||
description: Free parsing of Zeabur custom domain names.
|
||||
---
|
||||
+22
-7
@@ -2,22 +2,37 @@ import { NextResponse } from "next/server";
|
||||
import { auth } from "auth";
|
||||
|
||||
import { siteConfig } from "./config/site";
|
||||
import { createUserShortUrlMeta, getUrlBySuffix } from "./lib/dto/short-urls";
|
||||
|
||||
// export { auth as middleware } from "auth";
|
||||
|
||||
// Or like this if you need to do something here.
|
||||
export default auth(async (req) => {
|
||||
// console.log(req.auth); // { session: { user: { ... } } }
|
||||
// console.log(req.auth);
|
||||
const ip = req.headers.get("X-Forwarded-For");
|
||||
// console.log("[middle/s]", ip);
|
||||
|
||||
if (req.url.includes("/s/")) {
|
||||
const slugRegex = /[^/]+$/;
|
||||
const match = req.url.match(slugRegex);
|
||||
const match = req.url.match(/[^/]+$/);
|
||||
let geo = {
|
||||
city: "",
|
||||
region: "",
|
||||
country: "",
|
||||
latitude: "",
|
||||
longitude: "",
|
||||
};
|
||||
const data = await fetch(`https://ip.wr.do/api?ip=${ip}`); // http://ip-api.com/json/42.48.83.141
|
||||
if (data.ok) {
|
||||
const geoData = await data.json();
|
||||
geo = {
|
||||
city: geoData.city,
|
||||
region: geoData.region,
|
||||
country: geoData.country,
|
||||
latitude: geoData.latitude,
|
||||
longitude: geoData.longitude,
|
||||
};
|
||||
}
|
||||
|
||||
if (match) {
|
||||
const res = await fetch(
|
||||
`${siteConfig.url}/api/s?slug=${match[0]}&ip=${ip}`,
|
||||
`${siteConfig.url}/api/s?slug=${match[0]}&ip=${ip}&city=${geo.city}®ion=${geo.region}&country=${geo.country}&latitude=${geo.latitude}&longitude=${geo.longitude}`,
|
||||
{
|
||||
method: "GET",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user