{"version":3,"sources":["jsdelivr-header.js","/npm/picgo-plugin-ipfs-nftstorage@1.0.0/src/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,WAAE,WAAU,KAAE,MAAS,QAAQ,eAErC,OAAO,QAAW,IAChB,MAOM,EAAS,eAAgB,GAC7B,IAAI,EAAa,EAAI,UAAU,0BAC/B,IAAK,EACH,MAAM,IAAI,MAAM,8BAElB,MAAM,EAAS,EAAW,OACpB,EAAU,EAAW,QAC3B,IACE,IAAI,EAAU,EAAI,OAClB,IAAK,IAAI,KAAK,EAAS,CACrB,IAAI,EAAQ,EAAQ,GAAG,QAClB,GAAS,EAAQ,GAAG,cACvB,EAAQ,OAAO,KAAK,EAAQ,GAAG,YAAa,WAE9C,MAAM,EAAQ,IAAI,WAAW,CAAE,MAAO,IAChC,QAAY,EAAM,UAAU,IAAI,KAAK,CAAC,YACrC,EAAQ,GAAG,mBACX,EAAQ,GAAG,OAElB,IAAI,EAAS,WAAW,yBACT,MAAX,GAA+B,KAAZ,IACrB,EAAS,GAAG,UAAgB,KAE9B,EAAQ,GAAW,OAAI,CACzB,CACF,CAAE,MAAO,GACP,EAAI,KAAK,eAAgB,CACvB,MAAO,cACP,KAAM,KAAK,UAAU,IAEzB,CACF,EAEM,EAAS,IACb,IAAI,EAAa,EAAI,UAAU,0BAI/B,OAHK,IACH,EAAa,CAAC,GAET,CACL,CACE,KAAM,SACN,KAAM,QACN,QAAS,EAAW,OACpB,UAAU,EACV,QAAS,qBAEX,CACE,KAAM,UACN,KAAM,QACN,QAAS,EAAW,QACpB,UAAU,EACV,QAAS,0CACT,MAAO,gBAEX,EAGF,MAAO,CACL,SAAU,kBACV,SAlEe,KACf,EAAI,OAAO,SAAS,SAAS,kBAAmB,CAC9C,SACA,KAAM,kBACN,OAAQ,GACT,EA8DH","file":"/npm/picgo-plugin-ipfs-nftstorage@1.0.0/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/picgo-plugin-ipfs-nftstorage@1.0.0/src/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 { NFTStorage, Blob } = require('nft.storage')\n\nmodule.exports = (ctx) => {\n  const register = () => {\n    ctx.helper.uploader.register('ipfs-nftstorage', {\n      handle,\n      name: 'ipfs-nftstorage',\n      config: config\n    })\n  }\n  const handle = async function (ctx) {\n    let userConfig = ctx.getConfig('picBed.ipfs-nftstorage')\n    if (!userConfig) {\n      throw new Error('Can\\'t find uploader config')\n    }\n    const apiKey = userConfig.apiKey\n    const gateway = userConfig.gateway\n    try {\n      let imgList = ctx.output\n      for (let i in imgList) {\n        let image = imgList[i].buffer\n        if (!image && imgList[i].base64Image) {\n          image = Buffer.from(imgList[i].base64Image, 'base64')\n        }\n        const store = new NFTStorage({ token: apiKey })\n        const cid = await store.storeBlob(new Blob([image]))\n        delete imgList[i].base64Image\n        delete imgList[i].buffer\n\n        let imgUrl = `https://${cid}.ipfs.nftstorage.link`\n        if (gateway != null && gateway !== '') {\n          imgUrl = `${gateway}/ipfs/${cid}`\n        }\n        imgList[i]['imgUrl'] = imgUrl\n      }\n    } catch (err) {\n      ctx.emit('notification', {\n        title: 'upload fail',\n        body: JSON.stringify(err)\n      })\n    }\n  }\n\n  const config = ctx => {\n    let userConfig = ctx.getConfig('picBed.ipfs-nftstorage')\n    if (!userConfig) {\n      userConfig = {}\n    }\n    return [\n      {\n        name: 'apiKey',\n        type: 'input',\n        default: userConfig.apiKey,\n        required: true,\n        message: 'nftstorage apiKey'\n      },\n      {\n        name: 'gateway',\n        type: 'input',\n        default: userConfig.gateway,\n        required: false,\n        message: 'ipfs-gateway 如: https://nftstorage.link',\n        alias: 'ipfs-gateway'\n      }\n    ]\n  }\n\n  return {\n    uploader: 'ipfs-nftstorage',\n    register\n  }\n}\n"]}