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K,EAAU,EAAK,EAAU,KAEjD,IAAI,EAAa,EACZ,EAAW,SAAS,iBACrB,EAAa,EAAW,QAAQ,MAAO,IAAM,eAGjD,MAAM,EAAW,CACf,MAAO,CACL,MAAO,EACP,QAAS,CACP,SAAU,KAShB,OAJI,IACF,EAAS,IAAM,GAGV,CACL,OAAQ,OACR,IAAK,EACL,QAAS,CACP,eAAgB,sBAChB,oBAAqB,EACrB,aAAc,SAEhB,SAAU,EACZ,EAGI,OAAS,IACb,IAAI,EAAa,EAAI,UAAU,6BAI/B,OAHK,IACH,EAAa,CAAC,GAET,CACL,CACE,KAAM,MACN,KAAM,QACN,QAAS,EAAW,IACpB,UAAU,EACV,QAAS,qCACT,MAAO,SAET,CACE,KAAM,WACN,KAAM,QACN,QAAS,EAAW,SACpB,UAAU,EACV,QAAS,UACT,MAAO,MAET,CACE,KAAM,MACN,KAAM,QACN,QAAS,EAAW,IACpB,UAAU,EACV,QAAS,YACT,MAAO,QAEX","file":"/npm/picgo-plugin-cloudimgs-uploader@1.0.5/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/picgo-plugin-cloudimgs-uploader@1.0.5/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","module.exports = (ctx) => {\n  const register = () => {\n    ctx.helper.uploader.register('cloudimgs-uploader', {\n      handle,\n      config: config,\n      name: '云图-cloudimgs'\n    })\n  }\n  return {\n    uploader: 'cloudimgs-uploader',\n    register\n  }\n}\n\nconst handle = async (ctx) => {\n  let userConfig = ctx.getConfig('picBed.cloudimgs-uploader')\n  if (!userConfig) {\n    throw new Error('Can\\'t find uploader config')\n  }\n  const url = userConfig.url\n  const password = userConfig.password\n  let dir = userConfig.dir\n  if (dir) {\n      dir = dir.replace(/^\\/+/, '').replace(/\\/+$/, '')\n  }\n\n  const 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 postConfig = postOptions(url, password, dir, imgList[i].fileName, image)\n    try {\n        let body = await ctx.request(postConfig)\n        if (typeof body === 'string') {\n            try {\n                body = JSON.parse(body)\n            } catch (e) {\n                // If parse fails, assume it might be a raw string URL or error\n                ctx.log.error('Failed to parse response:', body)\n            }\n        }\n        \n        ctx.log.info('Upload response:', body)\n\n        // Try to find the URL in common locations\n        if (body.data && body.data.url) {\n            imgList[i].imgUrl = url + body.data.url\n            imgList[i].url = url + body.data.url\n        }else {\n             ctx.log.error('Could not find URL in response', body)\n             throw new Error('Upload successful but cannot find URL in response. Check PicGo logs.')\n        }\n        \n        delete imgList[i].base64Image\n        delete imgList[i].buffer\n    } catch (err) {\n        ctx.log.error('Upload failed', err)\n        ctx.emit('notification', {\n            title: '上传失败',\n            body: err.message\n        })\n        throw err\n    }\n  }\n  return ctx\n}\n\nconst postOptions = (url, password, dir, fileName, image) => {\n  // Ensure url ends with /api/upload\n  let requestUrl = url\n  if (!requestUrl.includes('/api/upload')) {\n      requestUrl = requestUrl.replace(/\\/$/, '') + '/api/upload'\n  }\n\n  const formData = {\n    image: {\n      value: image,\n      options: {\n        filename: fileName\n      }\n    }\n  }\n  \n  if (dir) {\n    formData.dir = dir\n  }\n  \n  return {\n    method: 'POST',\n    url: requestUrl,\n    headers: {\n      'Content-Type': 'multipart/form-data',\n      'X-Access-Password': password,\n      'User-Agent': 'PicGo'\n    },\n    formData: formData\n  }\n}\n\nconst config = ctx => {\n  let userConfig = ctx.getConfig('picBed.cloudimgs-uploader')\n  if (!userConfig) {\n    userConfig = {}\n  }\n  return [\n    {\n      name: 'url',\n      type: 'input',\n      default: userConfig.url,\n      required: true,\n      message: '服务器域名（例如 https://img.xxx.com:8692）',\n      alias: '服务器域名'\n    },\n    {\n      name: 'password',\n      type: 'input',\n      default: userConfig.password,\n      required: true,\n      message: '图床配置的密码',\n      alias: '密码'\n    },\n    {\n      name: 'dir',\n      type: 'input',\n      default: userConfig.dir,\n      required: false,\n      message: '存储路径 (可选)',\n      alias: '存储路径'\n    }\n  ]\n}\n"]}