init
This commit is contained in:
parent
736b6f8050
commit
a93be9bfd2
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
node_modules/
|
||||
dist/
|
||||
.DS_Store
|
||||
yarn-error.log
|
||||
temp.js
|
||||
package-lock.json
|
||||
./.idea
|
||||
.idea/.gitignore
|
||||
.idea/codeStyles/
|
||||
.idea/inspectionProfiles/
|
10
.npmignore
Normal file
10
.npmignore
Normal file
@ -0,0 +1,10 @@
|
||||
node_modules/
|
||||
yarn-error.log
|
||||
temp.js
|
||||
package-lock.json
|
||||
tsconfig.json
|
||||
tslint.json
|
||||
.vscode/
|
||||
src/
|
||||
.travis.yml
|
||||
.idea
|
31
.travis.yml
Normal file
31
.travis.yml
Normal file
@ -0,0 +1,31 @@
|
||||
language: node_js
|
||||
node_js: stable
|
||||
|
||||
# Travis-CI Caching
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
yarn: true
|
||||
|
||||
# S: Build Lifecycle
|
||||
install:
|
||||
- yarn
|
||||
|
||||
stages:
|
||||
- name: deploy
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: deploy
|
||||
script:
|
||||
- npm run build
|
||||
deploy:
|
||||
provider: npm
|
||||
email: ""
|
||||
api_key: "${NPM_TOKEN}"
|
||||
skip_cleanup: true
|
||||
on:
|
||||
branch: master
|
||||
branches:
|
||||
only:
|
||||
- master
|
21
License
Normal file
21
License
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 xlzy520
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
38
README.md
Normal file
38
README.md
Normal file
@ -0,0 +1,38 @@
|
||||
## picgo-plugin-light-picture
|
||||
|
||||
<!-- [![下载](https://img.shields.io/npm/dm/picgo-plugin-smms-user.svg?color=brightgreen)](https://npmcharts.com/compare/picgo-plugin-light-picture?minimal=true)
|
||||
[![版本](https://img.shields.io/npm/v/picgo-plugin-smms-user.svg?color=brightgreen)](https://www.npmjs.com/package/picgo-plugin-light-picture) -->
|
||||
[![许可](https://img.shields.io/badge/license-mit-brightgreen.svg)](https://github.com/xlzy520/picgo-plugin-smms-user/blob/master/License)
|
||||
|
||||
|
||||
为 [PicGo](https://github.com/Molunerfinn/PicGo) 开发的一款插件,用于 [LightPicture](https://github.com/osuuu/LightPicture) 图床。
|
||||
LightPicture是一个使用thinkphp+vue开发,前后端分离的企业/团队图床系统。部署完图床系统后在插件输入你的系统的访问地址以及key即可使用。
|
||||
|
||||
### 安装
|
||||
|
||||
- 在线安装
|
||||
|
||||
👷...
|
||||
<!-- 打开 [PicGo](https://github.com/Molunerfinn/PicGo) 详细窗口,选择**插件设置**,搜索**light-picture**安装,然后重启应用即可。 -->
|
||||
|
||||
- 离线安装
|
||||
|
||||
克隆该项目,复制项目到 以下目录:
|
||||
- Windows: `%APPDATA%\picgo\`
|
||||
- Linux: `$XDG_CONFIG_HOME/picgo/` or `~/.config/picgo/`
|
||||
- macOS: `~/Library/Application\ Support/picgo/`
|
||||
|
||||
切换到目录执行 `npm install ./picgo-plugin-smms-user`,然后重启应用即可。
|
||||
|
||||
### 截图
|
||||
|
||||
![](https://sslbackend.deercloud.site:450/LightPicture/2022/10/d979ef86c966701d.png)
|
||||
|
||||
### 配置
|
||||
|
||||
注意⚠️:key在LightPicture右上角的个人资料里,不在左侧菜单的接口那里。
|
||||
|
||||
|参数名称|类型|描述|是否必须|
|
||||
|:--:|:--:|:--:|:--:|
|
||||
|服务器地址|input|即LightPicture网页地址(除非你的前后短分离部署的)|true|
|
||||
|Key|input|Key即API密钥|true|
|
37
package.json
Normal file
37
package.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "picgo-plugin-light-picture",
|
||||
"version": "1.0.0",
|
||||
"description": "LightPicture图床",
|
||||
"main": "src/index.js",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"homepage": "",
|
||||
"scripts": {
|
||||
"publish": "npm publish --registry http://registry.npmjs.org",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"patch": "npm version patch && git push origin master && git push origin --tags",
|
||||
"minor": "npm version minor && git push origin master && git push origin --tags",
|
||||
"major": "npm version major && git push origin master && git push origin --tags"
|
||||
},
|
||||
"keywords": [
|
||||
"picgo",
|
||||
"picgo-gui-plugin",
|
||||
"picgo-plugin"
|
||||
],
|
||||
"author": "ColdeZhang",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:/coldezhang/picgo-plugin-light-picture.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@varnxy/logger": "^1.1.2",
|
||||
"eslint": "^5.0.1",
|
||||
"eslint-config-standard": "^11.0.0",
|
||||
"eslint-plugin-import": "^2.13.0",
|
||||
"eslint-plugin-node": "^6.0.1",
|
||||
"eslint-plugin-promise": "^3.8.0",
|
||||
"eslint-plugin-standard": "^3.1.0"
|
||||
}
|
||||
}
|
92
src/index.js
Normal file
92
src/index.js
Normal file
@ -0,0 +1,92 @@
|
||||
module.exports = (ctx) => {
|
||||
const register = () => {
|
||||
ctx.helper.uploader.register('light_picture', {
|
||||
handle,
|
||||
name: 'LightPicture图床',
|
||||
config: config
|
||||
})
|
||||
}
|
||||
|
||||
const postOptions = (Url, Key, fileName, image) => {
|
||||
return {
|
||||
method: 'POST',
|
||||
url: Url + `/api/upload`,
|
||||
headers: {
|
||||
contentType: 'multipart/form-data',
|
||||
'User-Agent': 'PicGo',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
formData: {
|
||||
file: {
|
||||
value: image,
|
||||
options: {
|
||||
filename: fileName
|
||||
}
|
||||
},
|
||||
key: Key,
|
||||
ssl: 'true'
|
||||
}
|
||||
}
|
||||
}
|
||||
const handle = async (ctx) => {
|
||||
let userConfig = ctx.getConfig('picBed.light_picture')
|
||||
if (!userConfig) {
|
||||
throw new Error('Can\'t find uploader config')
|
||||
}
|
||||
const Key = userConfig.Key
|
||||
const Url = userConfig.Url
|
||||
const imgList = ctx.output
|
||||
for (let i in imgList) {
|
||||
let image = imgList[i].buffer
|
||||
if (!image && imgList[i].base64Image) {
|
||||
image = Buffer.from(imgList[i].base64Image, 'base64')
|
||||
}
|
||||
const postConfig = postOptions(Url, Key, imgList[i].fileName, image)
|
||||
let body = await ctx.request(postConfig)
|
||||
body = JSON.parse(body)
|
||||
ctx.log.info(body)
|
||||
if (body.code === 200) {
|
||||
delete imgList[i].base64Image
|
||||
delete imgList[i].buffer
|
||||
ctx.log.info(body.data.url)
|
||||
imgList[i]['imgUrl'] = body.data.url
|
||||
} else {
|
||||
ctx.emit('notification', {
|
||||
title: '上传失败',
|
||||
body: body.message
|
||||
})
|
||||
throw new Error(body.message)
|
||||
}
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
const config = ctx => {
|
||||
let userConfig = ctx.getConfig('picBed.light_picture')
|
||||
if (!userConfig) {
|
||||
userConfig = {}
|
||||
}
|
||||
return [
|
||||
{
|
||||
name: 'Url',
|
||||
type: 'input',
|
||||
default: userConfig.Url,
|
||||
required: true,
|
||||
message: '服务器地址',
|
||||
alias: '服务器地址'
|
||||
},
|
||||
{
|
||||
name: 'Key',
|
||||
type: 'input',
|
||||
default: userConfig.Key,
|
||||
required: true,
|
||||
message: 'Key',
|
||||
alias: 'Key'
|
||||
}
|
||||
]
|
||||
}
|
||||
return {
|
||||
uploader: 'light_picture',
|
||||
config: config,
|
||||
register
|
||||
}
|
||||
}
|
29
tsconfig.json
Normal file
29
tsconfig.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"sourceMap": false,
|
||||
"target": "es2017",
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
// It's shit.
|
||||
// "baseUrl": "src",
|
||||
// "paths": {
|
||||
// "@core/*": ["core/*"],
|
||||
// "@lib/*": ["lib/*"],
|
||||
// "@plugins/*": ["plugins/*"],
|
||||
// "@utils/*": ["utils/*"]
|
||||
// },
|
||||
"lib": [
|
||||
"es2017",
|
||||
"es2015",
|
||||
"es6"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*"
|
||||
]
|
||||
}
|
13
tslint.json
Normal file
13
tslint.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "tslint-config-standard",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"sourceMap": true,
|
||||
"target": "es6",
|
||||
"types": [
|
||||
"mocha",
|
||||
"chai",
|
||||
"jest"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user