准备工作
安装 Typora,注意安装时选择 仅为当前用户安装
打开 Typora,点击 文件 菜单,进入 偏好设置 → 图像,上传服务选择 PicGo-Core,然后点击 下载或更新
点击下载 node18 并解压到 %APPDATA%\Typora\
重命名解压后目录为 node18 并添加path:
- 按
Win
+R
键打开运行窗口,输入sysdm.cpl
后回车 - 切换打开的窗口到“高级”选项,点击右下角的 环境变量
- 在上面的 用户变量 中,找到
Path
,选中后点击 编辑 - 在 编辑环境变量 窗口中 点击 新建,在新的输入行中粘贴
%APPDATA%\Typora\node18
然后一路点击确定即可
创建文本文档,命名为 InstallPicGoPlugins.bat
,粘贴以下内容保存后双击运行
@echo off
setlocal
set "NODE_PATH=%APPDATA%\Typora\node18"
set "PATH=%NODE_PATH%;%PATH%"
cd /d "%APPDATA%\Typora\picgo\win64"
picgo install gitlab
picgo install gitcode
picgo install s3@1.2.4
picgo install gitlab-files
picgo install gitee-uploader
picgo install super-prefix
pause
endlocal
基础配置
SMMS
注意: 目前smms已经关闭了注册功能,免费容量5G
点击这里 注册 smms 账户
点击这里 → Generate Secret Token 生成令牌后复制
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 token
后粘贴覆盖记事本原内容后保存
{
"picBed": {
"current": "smms",
"uploader": "smms",
"smms": {
"token": "",
"backupDomain": "smms.app"
}
},
"picgoPlugins": {}
}
Imgur
注意: Imgur 国内访问受限,需要设置代理
点击这里 注册 Imgur 账户
点击这里 新建应用,Application name 输入 PicGo
,Authorization type 勾选第二个,创建后复制保存 ClientID
的值
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 clientID
和 proxy
后粘贴覆盖记事本原内容后保存
{
"picBed": {
"current": "imgur",
"uploader": "imgur",
"imgur": {
"clientId": "",
"proxy": "http://127.0.0.1:7890"
}
},
"picgoPlugins": {}
}
Github
注意: Github 国内访问受限,需要设置代理
点击这里 注册 Github 账户
点击这里 新建仓库,Repository name 填写 PicGo
,勾选 Add a README file 后点击 Create repository
点击这里 新建令牌,Note 填写 picgo
,Expiration 选择 No expiration,勾选 repo 后下拉到底点击 Create token 后复制 token
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 用户名
和 token
后粘贴覆盖记事本原内容后保存
{
"picBed":{
"uploader":"github",
"current":"github",
"github":{
"branch":"main",
"customUrl":"https://cdn.jsdelivr.net/gh/用户名/picgo",
"repo":"用户名/picgo",
"path":"img",
"token":"**********"
}
},
"picgoPlugins":{
"picgo-plugin-super-prefix":true
},
"picgo-plugin-super-prefix":{
"prefixFormat":"YYYY/MM/DD/",
"fileFormat":"YYYYMMDDHHmmss"
}
}
Gitee
注意: Gitee 仓库已添加防盗链,只能在本地编辑器使用,无法作为网站的图床
点击这里 注册 Gitee 账户,点击这里 勾选 将个人资料设为私密并隐藏活动 后点击保存
点击这里 新建仓库,仓库名称 填写 Picgo
,点击 创建 → 初始化 readme 文件
点击这里 新建令牌,输入 私人令牌描述,取消全选,手动勾选 projects 点击 提交,输入密码验证后点击复制 token
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 用户名
和 token
后粘贴覆盖记事本原内容后保存
{
"picBed":{
"uploader":"gitee",
"current":"gitee",
"gitee":{
"branch":"master",
"customUrl":"",
"path":"img",
"repo":"用户名/picgo",
"token":"**************"
}
},
"picgoPlugins":{
"picgo-plugin-gitee-uploader":true,
"picgo-plugin-super-prefix":true
},
"picgo-plugin-super-prefix":{
"prefixFormat":"YYYY/MM/DD/",
"fileFormat":"YYYYMMDDHHmmss"
}
}
3 1pnpm pake-linux2pnpm pake-win3pnpm pake-macbash
注意: Gitlab 已过时,需要修改代码,建议直接使用 Gitlab-files
点击这里 注册 Gitlab 账户,验证邮箱后的表单勾选 Crate a new project 和 Just me 后点击 Continue,Group name 自定义 Project name 填写 PicGo
后无需选择框架直接点击 Create project
默认创建的仓库是私有的,要用做图床的话还需要设置为公开,注意组织需要先公开后才能公开仓库
-
公开组织:点击这里 → ⋮ → Edit,修改 Visibility level 为
Public
后点击 Save changes -
公开仓库: 点击这里 → ⋮ → Edit,首先复制 Project ID 保存,然后展开 Visibility, project features, permissions 修改 Project visibility 为
Public
后下拉到底点击 Save changes
点击这里 然后点击 Add new token,Token name 输入 picgo
, Expiration date最高只可选择一年后,直接点击 📅 然后点击年份选择后一年以及最大天数即可,权限勾选 api 后点击 Create personal access token 创建后,点击绿色高亮区域的 📋 复制 Token
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\node_modules\picgo-plugin-gitlab\src\index.js"
替换为以下内容后保存
// fork from : https://github.com/yuki-xin/picgo-plugin-web-uploader
// const logger = require('@varnxy/logger')
// logger.setDirectory('/Users/zhang/Work/WorkSpaces/WebWorkSpace/picgo-plugin-gitlab/logs')
// let log = logger('plugin')
module.exports = (ctx) => {
const register = () => {
ctx.helper.uploader.register('gitlab', {
handle,
name: 'GitLab图床',
config: config
})
}
const handle = async function (ctx) {
let userConfig = ctx.getConfig('picBed.gitlab')
if (!userConfig) {
throw new Error('Can\'t find uploader config')
}
const url = userConfig.URL
const group = userConfig.Group
const project = userConfig.Project
const token = userConfig.Token
const branch = userConfig.Branch
const path = userConfig.Path
const projectId = encodeURIComponent(`${group}/${project}`)
const realImgUrlPre = `${url}/${group}/${project}/-/raw/${branch}/${path}`
const commitUrl = `${url}/api/v4/projects/${projectId}/repository/commits`
try {
let 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 base64Content = image.toString('base64')
const targetPath = `${path}/${imgList[i].fileName}`
const commitConfig = {
method: 'POST',
url: commitUrl,
headers: {
'Content-Type': 'application/json',
'User-Agent': 'PicGo',
'PRIVATE-TOKEN': token
},
body: JSON.stringify({
branch: branch,
commit_message: `Upload image: ${imgList[i].fileName}`,
actions: [
{
action: 'create',
file_path: targetPath,
content: base64Content,
encoding: 'base64'
}
]
})
}
let body = await ctx.Request.request(commitConfig)
body = JSON.parse(body)
delete imgList[i].base64Image
delete imgList[i].buffer
imgList[i]['imgUrl'] = `${realImgUrlPre}/${imgList[i].fileName}`
}
} catch (err) {
ctx.emit('notification', {
title: '上传失败',
body: JSON.stringify(err)
})
throw err
}
}
const config = ctx => {
let userConfig = ctx.getConfig('picBed.gitlab')
if (!userConfig) {
userConfig = {}
}
return [
{
name: 'URL',
type: 'input',
default: userConfig.URL,
required: true,
message: 'https://gitlab.com',
alias: 'URL'
},
{
name: 'Group',
type: 'input',
default: userConfig.Group,
required: true,
message: 'Group',
alias: 'Group'
},
{
name: 'Project',
type: 'input',
default: userConfig.Project,
required: true,
message: 'Project',
alias: 'Project'
},
{
name: 'Token',
type: 'input',
default: userConfig.Token,
required: true,
message: 'aLS32eaxs1GLvKcv9f-k',
alias: 'Token'
},
{
name: 'Branch',
type: 'input',
default: userConfig.Branch,
required: false,
message: 'main',
alias: 'Branch'
},
{
name: 'Path',
type: 'input',
default: userConfig.Path,
required: false,
message: 'images',
alias: 'Path'
}
]
}
return {
uploader: 'gitlab',
// transformer: 'gitlab',
// config: config,
register
}
}
接着在终端粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 Group
和 Token
后粘贴覆盖记事本原内容后保存
{
"picBed":{
"current":"gitlab",
"uploader":"gitlab",
"gitlab": {
"URL": "https://gitlab.com",
"Group": "*******",
"Project": "picgo",
"Token": "*******",
"Branch": "main",
"Path": "img"
}
},
"picgoPlugins":{
"picgo-plugin-gitlab":true
}
}
Gitlab-files
注意: Gitlab-files 需要 PicGo-Core 版本 ≥ 1.5.0,Typora 维护版本还是 1.4.7,作者打包好了最新版本,可以发电获取:支持一下
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 projectId
和 gitToken
后粘贴覆盖记事本原内容后保存
{
"picBed": {
"current": "gitlab-files-uploader",
"uploader": "gitlab-files-uploader",
"gitlab-files-uploader": {
"gitUrl": "https://gitlab.com",
"projectId": "***************",
"branch": "main",
"gitToken": "******************",
"gitVersionUnderThirteen": false,
"fileName": "/img/{year}/{month}/{day}_{hour}_{minute}_{second}_{fileName}",
"commitMessage": "Upload {fileName} By Typora at {year}-{month}-{day}",
"deleteRemote": "false",
"deleteMessage": "Delete {fileName} By Typora at {year}-{month}-{day}",
"deleteInform": false,
"authorMail": "hi@typora.io",
"authorName": "Typora"
}
},
"picgoPlugins": {
"picgo-plugin-gitlab-files": true
}
}
Gitcode
点击这里,右上角点击注册创建账号
点击这里 创建仓库,项目名称 填写 PicGo
,勾选 添加初始化 README 文件 后 点击 创建项目
点击这里 创建令牌,令牌名称 填写 picgo
,到期时间最长可选择两年,点击 新建令牌,点击 ⧉ 复制 token
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 用户名
和 token
后粘贴覆盖记事本原内容后保存
{
"picBed": {
"current": "gitcode",
"uploader": "gitcode",
"gitcode": {
"owner": "用户名",
"repo": "picgo",
"branch": "main",
"path": "img",
"token": "*****************",
"message": "Upload by Typora"
}
},
"picgoPlugins": {
"picgo-plugin-gitcode": true,
"picgo-plugin-super-prefix": true
},
"picgo-plugin-super-prefix": {
"prefixFormat":"YYYY/MM/DD/",
"fileFormat": "YYYYMMDDHHmmss"
}
}
S3
注意: 因为 PicGo 的环境还在 node14,只支持 v1.2.4 版 s3,下面给出的是 Cloudflare R2 的配置教程
点击这里,然后点击 创建存储桶,输入名称并注意选择 标准存储 后创建,点击 设置,接着下滑找到 连接域,点击添加自定义域
再点一次,复制右侧 帐户详细信息 的 账户ID
保存,然后点击右侧 管理 R2 API 令牌,点击 创建 API 令牌,自定义令牌名称,权限选读写,然后选择 仅用于特定存储桶,选择方才创建的存储桶,其他设置不变,点击创建。复制ID和密钥并保存,如果忘记则需要删除令牌后重新添加
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码打开
notepad "%USERPROFILE%\.picgo\config.json"
修改 accessKeyID
, secretAccessKey
, bucketName
, 账户ID
以及 urlPrefix
后粘贴覆盖记事本原内容后保存
{
"picBed": {
"uploader": "aws-s3",
"current": "aws-s3",
"aws-s3": {
"accessKeyID": "********",
"secretAccessKey": "*************************",
"bucketName": "*********",
"uploadPath": "{year}/{month}/{md5}.{extName}",
"region": "",
"endpoint": "账户ID.r2.cloudflarestorage.com",
"proxy": "",
"urlPrefix": "https://example.com/",
"pathStyleAccess": false,
"rejectUnauthorized": true,
"bucketEndpoint": false,
"acl": "private"
},
"transformer": "path"
},
"picgoPlugins": {
"picgo-plugin-s3": true
}
}
快速配置
快捷键 Win+R,输入 cmd
回车然后粘贴下面这行代码回车进入 picgo 目录
cd %AppData%\Typora\picgo\win64
- 配置图床
.\picgo set uploader
上下键选择图床然后回车按提示输入值进行配置
- 切换图床
.\picgo use uploader
上下键选择图床然后回车切换图床
- 上传图片
- 上传剪贴板里的第一张图片
.\picgo u
- 上传特定图片
.\picgo u /path/to/img
- 安装插件
.\picgo add gitlab
这时候再执行 .\picgo set uploader
就可以看到 gitlab 了
- 升级插件
.\picgo update gitlab
- 卸载插件
.\picgo rm gitlab
参考链接
- PicGo-Core 官方文档Typora图片上传功能设置
-
[工具 Typora + PicGo-Core 自动上传图片到图床](https://www.cnblogs.com/skuld-yi/p/14533794.html) - Typora设置图片自动上传Github
- typora 使用gitlab当图床pigco-core
- Typora + Picgo + Imgur 自动上传图片
- https://github.com/PicGo/Awesome-PicGo