repo_description: ⏰ 60s API 免费接口。每天 60 秒看世界、奥运奖牌榜、小红书/B站/微博/抖音/知乎热搜、金价、油价、天气、翻译、壁纸、Epic 游戏、二维码、猫眼票房｜一系列 高质量、开源、可靠、全球 CDN 加速 的开放 API 集合，支持 Docker / Deno / Bun / Cloudflare Workers / Node.js 部署
repo_topics: 60s api bilibili bing bun cloudflare-workers deno docker entertainment fun news today-in-history typescript weibo youdao
code: import { config } from '../config.ts'
  import { Common } from '../common.ts'
  
  import type { Middleware } from '@oak/oak'
  
  const list: string[] = process.env.BLACKLIST_IPS ? JSON.parse(process.env.BLACKLIST_IPS) : []
  
  export function blacklist(): Middleware {
    return async (ctx, next) => {
      const ip = ctx.request.ip
      const ua = ctx.request.headers.get('User-Agent') || '-'
      const url = ctx.request.url
  
      Common.debug(`[BLACKLIST] blacklist IP list: ${list.join(', ')}`)
  
      if (ip && list.includes(ip)) {
        ctx.response.status = 403
        ctx.response.body = Common.buildJson(
          null,
          403,
          `由于滥用等原因，该 IP (${ip}) 已被禁止，如有疑问请联系 ${config.author}`,
        )
  
        console.log(`[BLACKLIST] Blocked request from IP: ${ip}, URL: ${url}, UA: ${ua}`)
  
        return
      }
  
      await next()
    }
  }
  