From b579a80c797a48f44abf28cf4f18fc9b75867a79 Mon Sep 17 00:00:00 2001 From: Innei Date: Sun, 2 Jul 2023 23:20:54 +0800 Subject: [PATCH] fix: remove upstash Signed-off-by: Innei --- src/components/layout/footer/FooterInfo.tsx | 46 ++++++++++----------- src/middleware.ts | 27 +++++------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/components/layout/footer/FooterInfo.tsx b/src/components/layout/footer/FooterInfo.tsx index 74821b279e..9b81854922 100644 --- a/src/components/layout/footer/FooterInfo.tsx +++ b/src/components/layout/footer/FooterInfo.tsx @@ -1,9 +1,7 @@ import Link from 'next/link' import { SubscribeTextButton } from '~/components/widgets/subscribe/SubscribeTextButton' -import { isDev } from '~/lib/env' import { clsxm } from '~/lib/helper' -import { kvKeys, redis } from '~/lib/redis.server' import { linkSections } from './config' import { GatewayCount } from './GatewayCount' @@ -90,28 +88,28 @@ const PoweredBy: Component = ({ className }) => { ) } -type VisitorGeolocation = { - country: string - city?: string - flag: string -} +// type VisitorGeolocation = { +// country: string +// city?: string +// flag: string +// } const FooterBottom = async () => { - let lastVisitor: VisitorGeolocation | undefined = undefined - if (process.env.VERCEL_ENV === 'production') { - const [lv, cv] = await redis.mget( - kvKeys.lastVisitor, - kvKeys.currentVisitor, - ) - lastVisitor = lv - await redis.set(kvKeys.lastVisitor, cv) - } + // let lastVisitor: VisitorGeolocation | undefined = undefined + // if (process.env.VERCEL_ENV === 'production') { + // const [lv, cv] = await redis.mget( + // kvKeys.lastVisitor, + // kvKeys.currentVisitor, + // ) + // lastVisitor = lv + // await redis.set(kvKeys.lastVisitor, cv) + // } - if (isDev) { - lastVisitor = { - country: 'US', - flag: '🇺🇸', - } - } + // if (isDev) { + // lastVisitor = { + // country: 'US', + // flag: '🇺🇸', + // } + // } return (

@@ -143,7 +141,7 @@ const FooterBottom = async () => { - {!!lastVisitor && ( + {/* {!!lastVisitor && ( <> @@ -154,7 +152,7 @@ const FooterBottom = async () => { .join(', ')} - )} + )} */}

) diff --git a/src/middleware.ts b/src/middleware.ts index e9e7f19b7b..dc44111fab 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,9 +1,7 @@ -import dayjs from 'dayjs' import { NextResponse } from 'next/server' import type { NextRequest } from 'next/server' import countries from '~/data/countries.json' -import { kvKeys, redis } from '~/lib/redis.server' import { REQUEST_GEO, @@ -54,23 +52,20 @@ export default async function middleware(req: NextRequest) { if (geo && !isApi && process.env.VERCEL_ENV) { const country = geo.country - const city = geo.city + // const city = geo.city const countryInfo = countries.find((x) => x.cca2 === country) if (countryInfo) { - try { - const ipKey = `visitor_ip_${dayjs().format('YYYY-MM-DD')}` - - await redis.sadd(ipKey, ip) - - const countryInfo = countries.find((x) => x.cca2 === country) - if (countryInfo) { - const flag = countryInfo.flag - await redis.set(kvKeys.currentVisitor, { country, city, flag }) - } - - await redis.expire(ipKey, 60 * 60 * 24 * 7) - } catch {} + // try { + // const ipKey = `visitor_ip_${dayjs().format('YYYY-MM-DD')}` + // await redis.sadd(ipKey, ip) + // const countryInfo = countries.find((x) => x.cca2 === country) + // if (countryInfo) { + // const flag = countryInfo.flag + // await redis.set(kvKeys.currentVisitor, { country, city, flag }) + // } + // await redis.expire(ipKey, 60 * 60 * 24 * 7) + // } catch {} } }