Easyimages
Neil
[up主专用,视频内嵌代码贴在这]
Docker 搭建 Easyimage + PicGo 教程
Easyimage
Easyimage 项目地址:Github
Docker Compose
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| easyimage: container_name: easyimage image: ddsderek/easyimage:latest restart: unless-stopped ports: - '5205:80' environment: - TZ=Asia/Shanghai - PUID=1000 - PGID=1000 - DEBUG=false volumes: - '/root/app-data/easyimage/config:/app/web/config' - '/root/app-data/easyimage/i:/app/web/i'
|
PicGo
PicGo 项目地址:Github
PicGo 插件目前只有此方法尝试成功。
下载插件 easyimage 1.0.0,图床设置->配置 Api 地址和 Token 。

尝试了好多次,也无法使用 PicGo 通过 Easyimage 图床插件进行图片上传。
Windows 下插件安装在 C:\Users\[你的用户名]\AppData\Roaming\picgo\node_modules
picgo-plugin-easyimage\dist\index.js 直接覆盖以下源码(无需修改),重启 PicGo 。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| const UPLOADER = "easyimage"; module.exports = (ctx) => { const config = (ctx) => { let userConfig = ctx.getConfig("picBed." + UPLOADER); if (!userConfig) { userConfig = {}; } return [ { name: "server", type: "input", default: userConfig.server, required: true, message: "示例: http://10.20.30.19:8070/api/index.php", alias: "API调用地址", }, { name: "token", type: "input", default: userConfig.token, required: true, message: "认证 token 信息", alias: "调用Token", }, ]; }; const uploader = { config, handle: async (ctx) => { let userConfig = ctx.getConfig("picBed." + UPLOADER); if (!userConfig) { throw new Error("Can't find uploader config"); } const imgList = ctx.output; for (let i in imgList) { const img = imgList[i]; const { base64Image, fileName } = img; let { buffer } = img; if (!buffer && base64Image) { buffer = Buffer.from(img.base64Image, "base64"); }
const boundary = '----WebKitFormBoundary' + Math.random().toString(36).substr(2, 10);
let reqBodyParts = [];
reqBodyParts.push(Buffer.from(`--${boundary}\r\n`)); reqBodyParts.push(Buffer.from(`Content-Disposition: form-data; name="token"\r\n\r\n`)); reqBodyParts.push(Buffer.from(`${userConfig.token}\r\n`));
reqBodyParts.push(Buffer.from(`--${boundary}\r\n`)); reqBodyParts.push(Buffer.from(`Content-Disposition: form-data; name="image"; filename="${fileName}"\r\n`)); reqBodyParts.push(Buffer.from(`Content-Type: image/png\r\n\r\n`)); reqBodyParts.push(buffer); reqBodyParts.push(Buffer.from(`\r\n`));
reqBodyParts.push(Buffer.from(`--${boundary}--\r\n`)); const reqBody = Buffer.concat(reqBodyParts);
const requestConfig = { url: userConfig.server, method: "POST", headers: { "Content-Type": `multipart/form-data; boundary=${boundary}`, "User-Agent": "PicGo-easyimage", "Content-Length": reqBody.length, }, body: reqBody, }; let body = await ctx.Request.request(requestConfig); body = JSON.parse(body); const { url: imgUrl, message } = body; if (imgUrl) { img.imgUrl = imgUrl; } else { ctx.emit("notification", { title: "上传失败", body: message, }); } } return ctx; }, }; const register = () => { ctx.helper.uploader.register(UPLOADER, uploader); }; return { register, config, uploader: UPLOADER, }; };
|