Skip to content

Commit

Permalink
fix: remove upstash
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 2, 2023
1 parent 5b926e3 commit b579a80
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
46 changes: 22 additions & 24 deletions src/components/layout/footer/FooterInfo.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<VisitorGeolocation[]>(
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<VisitorGeolocation[]>(
// 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 (
<div className="mt-12 space-y-3 text-center md:mt-6 md:text-left">
<p>
Expand Down Expand Up @@ -143,7 +141,7 @@ const FooterBottom = async () => {
</StyledLink>
<Divider />
<GatewayCount />
{!!lastVisitor && (
{/* {!!lastVisitor && (
<>
<Divider />
<span>
Expand All @@ -154,7 +152,7 @@ const FooterBottom = async () => {
.join(', ')}
</span>
</>
)}
)} */}
</p>
</div>
)
Expand Down
27 changes: 11 additions & 16 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {}
}
}

Expand Down

1 comment on commit b579a80

@vercel
Copy link

@vercel vercel bot commented on b579a80 Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

springtide.vercel.app
shiro-git-main-innei.vercel.app
shiro-innei.vercel.app
innei.in

Please sign in to comment.