{"version":3,"sources":["jsdelivr-header.js","/npm/koa-ip@2.1.4/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,OAAS,QAAQ,UACjB,cAAgB,QAAQ,wBACxB,UAAY,QAAQ,cACpB,MAAQ,QAAQ,QAAR,CAAiB,UAE/B,OAAO,QAAU,SAAU,GAMzB,OALA,OAAO,EAAM,uBACR,cAAc,KACjB,EAAO,CAAE,UAAW,MAAM,QAAQ,GAAQ,EAAO,CAAC,KAG7C,eAAsB,EAAK,GAChC,MAAM,EAAK,EAAI,IAAM,UAAU,YAAY,EAAI,KAC/C,IAAI,GAAO,EAeX,GAbI,EAAK,WAAa,MAAM,QAAQ,EAAK,aACvC,EAAO,EAAK,UAAU,MAAM,GACnB,IAAI,OAAO,GAAM,KAAK,MAI7B,GAAQ,EAAK,WAAa,MAAM,QAAQ,EAAK,aAC/C,GAAQ,EAAK,UAAU,MAAM,GACpB,IAAI,OAAO,GAAM,KAAK,MAK7B,EAEF,OADA,MAAM,GAAG,IAAI,UAAY,WAClB,IAImB,mBAAjB,EAAK,SACd,MAAM,GAAG,IAAI,UAAY,uBACnB,EAAK,QAAQ,EAAK,KAExB,MAAM,GAAG,IAAI,UAAY,WACzB,EAAI,MAAM,KAEd,CACF","file":"/npm/koa-ip@2.1.4/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/koa-ip@2.1.4/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const assert = require('assert')\nconst isPlainObject = require('lodash.isplainobject')\nconst requestIp = require('request-ip')\nconst debug = require('debug')('koa-ip')\n\nmodule.exports = function (opts) {\n  assert(opts, 'koa-ip missing opts')\n  if (!isPlainObject(opts)) {\n    opts = { whitelist: Array.isArray(opts) ? opts : [opts] }\n  }\n\n  return async function koaIp (ctx, next) {\n    const ip = ctx.ip || requestIp.getClientIp(ctx.req)\n    let pass = true\n\n    if (opts.whitelist && Array.isArray(opts.whitelist)) {\n      pass = opts.whitelist.some((item) => {\n        return new RegExp(item).test(ip)\n      })\n    }\n\n    if (pass && opts.blacklist && Array.isArray(opts.blacklist)) {\n      pass = !opts.blacklist.some((item) => {\n        return new RegExp(item).test(ip)\n      })\n    }\n\n    // pass\n    if (pass) {\n      debug(`${new Date()}: \"${ip} -> ✓\"`)\n      return next()\n    }\n\n    // not pass\n    if (typeof opts.handler === 'function') {\n      debug(`${new Date()}: \"${ip} -> handler\"`)\n      await opts.handler(ctx, next)\n    } else {\n      debug(`${new Date()}: \"${ip} -> ×\"`)\n      ctx.throw(403)\n    }\n  }\n}\n"]}