├── .gitignore ├── .npmignore ├── .travis.yml ├── License ├── README.md ├── logo.png ├── package.json ├── src └── index.ts ├── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | .DS_Store 4 | yarn-error.log 5 | temp.js 6 | package-lock.json 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | yarn-error.log 3 | temp.js 4 | package-lock.json 5 | tsconfig.json 6 | tslint.json 7 | .vscode/ 8 | src/ 9 | .travis.yml 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: stable 3 | 4 | # Travis-CI Caching 5 | cache: 6 | directories: 7 | - node_modules 8 | yarn: true 9 | 10 | # S: Build Lifecycle 11 | install: 12 | - yarn 13 | 14 | stages: 15 | - name: deploy 16 | 17 | jobs: 18 | include: 19 | - stage: deploy 20 | script: 21 | - npm run build 22 | deploy: 23 | provider: npm 24 | email: "" 25 | api_key: "${NPM_TOKEN}" 26 | skip_cleanup: true 27 | on: 28 | branch: master 29 | branches: 30 | only: 31 | - master 32 | -------------------------------------------------------------------------------- /License: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 zhaoolee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## PicGo私有化图床插件 2 | 3 | 4 | 清明三天假, 完成了一个PicGo小插件, 可以将图片直接传到私有图床, 效果如图所示 5 | 6 | ![picgo插件](https://cdn.fangyuanxiaozhan.com/assets/1649143224074DD5Z0X0Q.png) 7 | 8 | 支持拖拽到picgo界面, picgo图标, 以及剪贴板上传 9 | 10 | ![支持各种形式上传](https://cdn.fangyuanxiaozhan.com/assets/1649143669492nxQdt25e.gif) 11 | 12 | 获得返回的图片链接均为自建图床的域名 13 | 14 | ``` 15 | ![](https://cdn.fangyuanxiaozhan.com/assets/1649143432086304QC157.jpeg) 16 | 17 | ![](https://cdn.fangyuanxiaozhan.com/assets/1649143420392RYBx4ZkW.jpeg) 18 | 19 | ![](https://cdn.fangyuanxiaozhan.com/assets/1649143411384pM5bKTCd.jpeg) 20 | ``` 21 | 22 | ![](https://cdn.fangyuanxiaozhan.com/assets/1649143432086304QC157.jpeg) 23 | 24 | ![](https://cdn.fangyuanxiaozhan.com/assets/1649143420392RYBx4ZkW.jpeg) 25 | 26 | ![](https://cdn.fangyuanxiaozhan.com/assets/1649143411384pM5bKTCd.jpeg) 27 | 28 | 服务端图床程序源自我以前的一个开源项目EasyTypora ,开源地址 : https://github.com/zhaoolee/EasyTypora 29 | 30 | 31 | 32 | ## 如何配置 33 | 34 | - 1. 首先安装 PicGo私有化图床插件 35 | 36 | 从github获得代码 37 | 38 | ``` 39 | git clone --depth=1 https://github.com/zhaoolee/pi-picgo.git 40 | 41 | cd pi-picgo 42 | npm i 43 | npm run build 44 | ``` 45 | 46 | 加载插件 47 | 48 | ![加载插件](https://cdn.fangyuanxiaozhan.com/assets/1649145305107SdxG5jRi.gif) 49 | 50 | - 2. 打开配置界面 51 | 52 | ![打开配置界面](https://cdn.fangyuanxiaozhan.com/assets/1649144135967d1TsRH6x.png) 53 | 54 | - 3. 输入三条必要信息, 并确定(三条必要信息,可通过往个人服务器部署EasyTypora 获得) 55 | 56 | ![输入三条必要信息](https://cdn.fangyuanxiaozhan.com/assets/1649144233519FpAb5r4E.png) 57 | 58 | 59 | - 4. 选择默认图床为pi-picgo 60 | 61 | ![选择默认图床为pi-picgo](https://cdn.fangyuanxiaozhan.com/assets/1649145380603GMSF6wjT.png) 62 | 63 | 64 | 配置完成! 65 | 66 | 67 | 68 | ## 未来的计划 69 | 70 | 为EasyTypora创建Docekr版本(更新到EasyTypora), 并提供部署到K8s树莓派集群的教程(更新到树莓派不吃灰), 配合内网穿透提供稳定的大容量公网图床服务! 71 | 72 | 73 | 《树莓派不吃灰》开源地址 https://github.com/zhaoolee/pi 74 | 75 | 《EasyTypora》开源地址 https://github.com/zhaoolee/EasyTypora 76 | 77 | 78 | 《PicGo私有化图床插件》开源地址 https://github.com/zhaoolee/pi-picgo 79 | 80 | 81 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaoolee/pi-picgo/dd4ab988bf03f3cbe4fc56e0fae37611d0b743cf/logo.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "picgo-plugin-pi-picgo", 3 | "version": "0.0.1", 4 | "description": "PicGo私有化图床插件", 5 | "main": "dist/index.js", 6 | "publishConfig": { 7 | "access": "public" 8 | }, 9 | "homepage": "", 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1", 12 | "build": "tsc -p .", 13 | "dev": "tsc -w -p .", 14 | "patch": "npm version patch && git push origin master && git push origin --tags", 15 | "minor": "npm version minor && git push origin master && git push origin --tags", 16 | "major": "npm version major && git push origin master && git push origin --tags" 17 | }, 18 | "keywords": [ 19 | "picgo", 20 | "picgo-gui-plugin", 21 | "picgo-plugin" 22 | ], 23 | "author": "zhaoolee", 24 | "license": "MIT", 25 | "devDependencies": { 26 | "@types/node": "^10.10.1", 27 | "picgo": "^1.4.0", 28 | "tslint": "^5.10.0", 29 | "tslint-config-standard": "^7.1.0", 30 | "typescript": "^3.7.3", 31 | "eslint": "^5.0.1", 32 | "eslint-config-standard": "^11.0.0", 33 | "eslint-plugin-import": "^2.13.0", 34 | "eslint-plugin-node": "^6.0.1", 35 | "eslint-plugin-promise": "^3.8.0", 36 | "eslint-plugin-standard": "^3.1.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import picgo from 'picgo' 2 | const fs = require("fs-extra"); 3 | const request = require('request'); 4 | 5 | // 上传图片 6 | async function upload_file(local_image_path: string, ctx: any) { 7 | // 填写host 例如: https://fangyuanxiaozhan.com 8 | const host = ctx.getConfig('picgo-plugin-pi-picgo.host'); 9 | // 填写客户端请求的端口号,例如 443 10 | const client_port = ctx.getConfig('picgo-plugin-pi-picgo.client_port'); 11 | // secret_token (客户端和服务端会同时添加secret_token鉴权,防止被他人滥用) 生成规则见 https://github.com/zhaoolee/EasyTypora 12 | const secret_token = ctx.getConfig('picgo-plugin-pi-picgo.secret_token'); 13 | console.log(`client_port${client_port}client_port${client_port}secret_token${secret_token}`) 14 | const url = `${host}:${client_port}/upload_file`; 15 | const formData = { 16 | file: fs.createReadStream(local_image_path), 17 | secret_token: secret_token 18 | }; 19 | return new Promise(async (resolve, reject) => { 20 | await request.post({ url: url, formData: formData }, function optionalCallback(err, httpResponse, body) { 21 | if (err) { 22 | // 如果请求出错,则返回一张猫爪图 23 | console.log("\nerr==>>", err, "\nhttpResponse==>>", httpResponse, "\nbody==>>", body, "\nurl===>>", url); 24 | resolve("https://www.v2fy.com/wp-content/uploads/2020/05/keycat1000.jpg") 25 | } else { 26 | // 如果请求正常,则返回图片地址 27 | resolve(body); 28 | } 29 | }) 30 | }) 31 | } 32 | 33 | export = (ctx: picgo) => { 34 | const register = () => { 35 | ctx.helper.uploader.register('pi-picgo', { 36 | async handle(ctx) { 37 | let input = ctx.input 38 | for(let m = 0; m < input.length; m++){ 39 | await (async (index)=>{ 40 | let newImage: string = (await upload_file(input[index], ctx)).toString(); 41 | ctx.output[index]["imgUrl"] = newImage; 42 | ctx.output[index]["url"] = newImage; 43 | })(m) 44 | } 45 | return ctx; 46 | } 47 | }) 48 | } 49 | 50 | const pluinConfig = ctx => { 51 | return [ 52 | { 53 | name: 'host', 54 | type: 'input', 55 | default: '', 56 | required: true 57 | }, 58 | { 59 | name: 'client_port', 60 | type: 'input', 61 | default: '', 62 | required: true 63 | }, 64 | { 65 | name: 'secret_token', 66 | type: 'input', 67 | default: '', 68 | required: true 69 | } 70 | ] 71 | } 72 | 73 | 74 | return { 75 | uploader: 'pi-picgo', 76 | config: pluinConfig, 77 | register 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "resolveJsonModule": true, 6 | "esModuleInterop": true, 7 | "allowSyntheticDefaultImports": true, 8 | "sourceMap": false, 9 | "target": "es2017", 10 | "declaration": true, 11 | "outDir": "dist", 12 | // It's shit. 13 | // "baseUrl": "src", 14 | // "paths": { 15 | // "@core/*": ["core/*"], 16 | // "@lib/*": ["lib/*"], 17 | // "@plugins/*": ["plugins/*"], 18 | // "@utils/*": ["utils/*"] 19 | // }, 20 | "lib": [ 21 | "es2017", 22 | "es2015", 23 | "es6" 24 | ] 25 | }, 26 | "include": [ 27 | "./src/**/*" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint-config-standard", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "sourceMap": true, 6 | "target": "es6", 7 | "types": [ 8 | "mocha", 9 | "chai", 10 | "jest" 11 | ] 12 | } 13 | } --------------------------------------------------------------------------------