├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── License ├── README.md ├── package.json ├── src └── index.js ├── tsconfig.json └── tslint.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "standard" 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | .DS_Store 4 | yarn-error.log 5 | temp.js 6 | package-lock.json 7 | ./.idea 8 | .idea/.gitignore 9 | .idea/codeStyles/ 10 | .idea/inspectionProfiles/ 11 | -------------------------------------------------------------------------------- /.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 | .idea 11 | -------------------------------------------------------------------------------- /.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 xlzy520 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-plugin-smms-user 2 | 3 | [![下载](https://img.shields.io/npm/dm/picgo-plugin-smms-user.svg?color=brightgreen)](https://npmcharts.com/compare/picgo-plugin-smms-user?minimal=true) 4 | [![版本](https://img.shields.io/npm/v/picgo-plugin-smms-user.svg?color=brightgreen)](https://www.npmjs.com/package/picgo-plugin-smms-user) 5 | [![许可](https://img.shields.io/badge/license-mit-brightgreen.svg)](https://github.com/xlzy520/picgo-plugin-smms-user/blob/master/License) 6 | 7 | 8 | 为 [PicGo](https://github.com/Molunerfinn/PicGo) 开发的一款插件,新增了[SM.MS注册用户](https://sm.ms/home/) 图床。 9 | 使用SM.MS V2的API上传,适用于注册了SM.MS的用户。填写`Authorization`即可 10 | 11 | ### 安装 12 | 13 | - 在线安装 14 | 15 | 打开 [PicGo](https://github.com/Molunerfinn/PicGo) 详细窗口,选择**插件设置**,搜索**smms-user**安装,然后重启应用即可。 16 | 17 | - 离线安装 18 | 19 | 克隆该项目,复制项目到 以下目录: 20 | - Windows: `%APPDATA%\picgo\` 21 | - Linux: `$XDG_CONFIG_HOME/picgo/` or `~/.config/picgo/` 22 | - macOS: `~/Library/Application\ Support/picgo/` 23 | 24 | 切换到新目录执行 `npm install ./picgo-plugin-smms-user`,然后重启应用即可。 25 | 26 | ### 截图 27 | 28 | ![](https://i.loli.net/2019/09/29/LPmKlQ4zFX9JpNw.jpg) 29 | 30 | ### 配置 31 | 在[这里](https://sm.ms/home/apitoken)获取Authorization 32 | 33 | |参数名称|类型|描述|是否必须| 34 | |:--:|:--:|:--:|:--:| 35 | |Authorization|input|Authorization即API Token|true| 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "picgo-plugin-smms-user", 3 | "version": "1.0.9", 4 | "description": "SMMS-用户", 5 | "main": "src/index.js", 6 | "publishConfig": { 7 | "access": "public" 8 | }, 9 | "homepage": "", 10 | "scripts": { 11 | "publish": "npm publish --registry http://registry.npmjs.org", 12 | "test": "echo \"Error: no test specified\" && exit 1", 13 | "patch": "npm version patch && git push origin master && git push origin --tags", 14 | "minor": "npm version minor && git push origin master && git push origin --tags", 15 | "major": "npm version major && git push origin master && git push origin --tags" 16 | }, 17 | "keywords": [ 18 | "picgo", 19 | "picgo-gui-plugin", 20 | "picgo-plugin" 21 | ], 22 | "author": "zhibikanmohuakai", 23 | "repository": { 24 | "type": "git", 25 | "url": "git@github.com:/xlzy520/picgo-plugin-smms-user.git" 26 | }, 27 | "license": "MIT", 28 | "devDependencies": { 29 | "eslint": "^5.0.1", 30 | "eslint-config-standard": "^11.0.0", 31 | "eslint-plugin-import": "^2.13.0", 32 | "eslint-plugin-node": "^6.0.1", 33 | "eslint-plugin-promise": "^3.8.0", 34 | "eslint-plugin-standard": "^3.1.0", 35 | "@varnxy/logger": "^1.1.2" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | module.exports = (ctx) => { 2 | const register = () => { 3 | ctx.helper.uploader.register('smms-user', { 4 | handle, 5 | name: 'SM.MS-登录用户', 6 | config: config 7 | }) 8 | } 9 | const postOptions = (Authorization, fileName, image) => { 10 | return { 11 | method: 'POST', 12 | url: `https://smms.app/api/v2/upload`, 13 | headers: { 14 | contentType: 'multipart/form-data', 15 | 'User-Agent': 'PicGo', 16 | 'Authorization': Authorization||undefined, 17 | }, 18 | formData: { 19 | smfile: { 20 | value: image, 21 | options: { 22 | filename: fileName 23 | } 24 | }, 25 | ssl: 'true' 26 | } 27 | }; 28 | }; 29 | const handle = async (ctx) => { 30 | let userConfig = ctx.getConfig('picBed.smms-user') 31 | if (!userConfig) { 32 | throw new Error('Can\'t find uploader config') 33 | } 34 | const Authorization = userConfig.Authorization 35 | const imgList = ctx.output; 36 | for (let i in imgList) { 37 | let image = imgList[i].buffer; 38 | if (!image && imgList[i].base64Image) { 39 | image = Buffer.from(imgList[i].base64Image, 'base64'); 40 | } 41 | const postConfig = postOptions(Authorization, imgList[i].fileName, image); 42 | let body = await ctx.Request.request(postConfig); 43 | 44 | body = JSON.parse(body); 45 | if (body.code === 'success') { 46 | delete imgList[i].base64Image; 47 | delete imgList[i].buffer; 48 | imgList[i]['imgUrl'] = body.data.url; 49 | } 50 | else { 51 | ctx.emit('notification', { 52 | title: '上传失败', 53 | body: body.message 54 | }); 55 | throw new Error(body.message); 56 | } 57 | } 58 | return ctx; 59 | }; 60 | 61 | const config = ctx => { 62 | let userConfig = ctx.getConfig('picBed.smms-user') 63 | if (!userConfig) { 64 | userConfig = {} 65 | } 66 | return [ 67 | { 68 | name: 'Authorization', 69 | type: 'input', 70 | default: userConfig.Authorization, 71 | required: true, 72 | message: 'Auth', 73 | alias: 'Auth' 74 | } 75 | ] 76 | } 77 | return { 78 | uploader: 'smms-user', 79 | config: config, 80 | register 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /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 | } --------------------------------------------------------------------------------