pcigo-command设置lskypro

1. 准备工作

1.1 Curl的安装与配置

下载完成后,我解压到了这样一个目录

D:\Compile_Tool\curl-8.4.0
  • 配置环境变量

新建一个环境变量

CURL_HOME
D:\Compile_Tool\curl-8.4.0

然后Path中追加这个环境变量即可

%CURL_HOME%\bin\

1.2 picgo的安装

文件—>偏好的设置—>图像—>上传服务 PicGo-Core(command line)

image-20231118233605962

1.3 获取lsky的信息

  • 使用 cURL(推荐)获取认证 token 信息
curl -X POST -F "email=354769733@qq.com" -F "password=wsj123wsj" https://img.daitcc.top:8090/api/v1/tokens

提示:

此命令仅适用于 V2,V1 用户只需要进入个人设置页面复制、粘贴使用即可。

  • 打开终端输入命令
C:\Users\35476\AppData\Roaming\Typora\picgo\win64>curl -X POST -F "email=354769733@qq.com" -F "password=wsj123wsj" https://img.daitcc.top:8090/api/v1/tokens
{"status":true,"message":"success","data":{"token":"1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx"}}
  • 保存获取的认证token信息
Bearer 1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx

提示:

通过设置请求 header 标头来验证请求(Bearer Token),所以Bearer不可少

  • 使用cURL(推荐)获取默认上传的相册ID
curl -H "Authorization:Bearer 1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx" -H "Accept:application/json" https://img.daitcc.top:8090/api/v1/albums

提示:

Authorization后面填刚保存的认证token信息

  • 打开终端输入命令
D:\Users\35476\Desktop>curl -H "Authorization:Bearer 1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx" -H "Accept:application/json" https://img.daitcc.top:8090/api/v1/albums
{"status":true,"message":"success","data":{"current_page":1,"data":[{"id":3,"name":"\u65c5\u6e38","intro":"","image_num":0},{"id":2,"name":"\u65e5\u5e38","intro":"","image_num":0},{"id":1,"name":"\u56fe\u5e8a","intro":"","image_num":0}],"first_page_url":"http:\/\/www.daitcc.top:8089\/api\/v1\/albums?page=1","from":1,"last_page":1,"last_page_url":"http:\/\/www.daitcc.top:8089\/api\/v1\/albums?page=1","links":[{"url":null,"label":"« \u4e0a\u4e00\u9875","active":false},{"url":"http:\/\/www.daitcc.top:8089\/api\/v1\/albums?page=1","label":"1","active":true},{"url":null,"label":"\u4e0b\u4e00\u9875 »","active":false}],"next_page_url":null,"path":"http:\/\/www.daitcc.top:8089\/api\/v1\/albums","per_page":40,"prev_page_url":null,"to":3,"total":3}}

将返回的参数整理之后可得

{
	"status": true,
	"message": "success",
	"data": {
		"current_page": 1,
		"data": [
			{
				"id": 3,
				"name": "旅游",
				"intro": "",
				"image_num": 0
			},
			{
				"id": 2,
				"name": "日常",
				"intro": "",
				"image_num": 0
			},
			{
				"id": 1,
				"name": "图床",
				"intro": "",
				"image_num": 0
			}
		],
		"first_page_url": "https://img.daitcc.top:8090/api/v1/albums?page=1",
		"from": 1,
		"last_page": 1,
		"last_page_url": "https://img.daitcc.top:8090/api/v1/albums?page=1",
		"links": [
			{
				"url": null,
				"label": "« 上一页",
				"active": false
			},
			{
				"url": "https://img.daitcc.top:8090/api/v1/albums?page=1",
				"label": "1",
				"active": true
			},
			{
				"url": null,
				"label": "下一页 »",
				"active": false
			}
		],
		"next_page_url": null,
		"path": "https://img.daitcc.top:8090/api/v1/albums",
		"per_page": 40,
		"prev_page_url": null,
		"to": 3,
		"total": 3
	}
}

提示:

返回参数 data.data.name 相册名称 需要经过Unicode转中文

返回参数 data.data.id 相册自增 ID

  • 保存获取的相册ID
图床 1
日常 2
旅游 3

2.修改lskypro源码可以指定默认上传相册

  • 修改文件/app/Services/ImageService.php第139行:

原代码为:

// 图片保存至默认相册(若有)
            if ($albumId = $user->configs->get(UserConfigKey::DefaultAlbum)) {
                if ($user->albums()->where('id', $albumId)->exists()) {
                    $image->album_id = $albumId;
                }
            }

修改为:

if ($request->has('album_id')) {
               $image->album_id = $request->input('album_id');
           } else {
           // 图片保存至默认相册(若有)
           if ($albumId = $user->configs->get(UserConfigKey::DefaultAlbum)) {
               if ($user->albums()->where('id', $albumId)->exists()) {
                   $image->album_id = $albumId;
               }
           }
       }

3. 安装lsky图床插件

  • lsky图床插件

    官方地址

  • 安装方式
    在对应系统的PicGo程序配置文件路径下执行 npm i picgo-plugin-lankong,然后重启应用即可。

4. 修改配置文件

这一步需要找到第1.2步中下载的picgo二进制文件,不同系统文件名略有不同:

  • windows系统一般在C:\Users\用户名\AppData\Roaming\Typora\picgo\win64\文件夹,文件名为picgo.exe
  • linux系统一般在~/.config/Typora/picgo/linux/文件夹,文件名为picgo

接下来执行命令:

  • linux系统,打开终端,在home目录下执行./.config/Typora/picgo/linux/picgo install gitee-uploader

  • windows系统,打开终端,可以在包含picgo.exe文件的路径下执行.\picgo.exe install picgo-plugin-lankong

在终端中打开你的picgo.exe路径,你可以通过picgo -h来查看所有命令:

$ picgo -h

  Usage: picgo [options] [command]

  Options:

    -v, --version                 output the version number
    -d, --debug                   debug mode
    -s, --silent                  silent mode
    -c, --config <path>           set config path
    -h, --help                    output usage information

  Commands:

    install|add [options] <plugins...>   install picgo plugin
    uninstall|rm <plugins...>            uninstall picgo plugin
    update [options] <plugins...>        update picgo plugin
    set|config <module> [name]           configure config of picgo modules
    upload|u [input...]                  upload, go go go
    use [module]                         use modules of picgo
    init [options] <template> [project]  create picgo plugin's development templates
    i18n [lang]                          change picgo language
    help [command]                       display help for command

提示

其中,命令选项如果是用<>包围起来的为必须输入项,如果是用[]包围起来的则为可选输入项。 有些命令支持简写,比如picgo upload可以写为picgo u

使用use命令为picgo选择lsky图床

C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo use
? Use an uploader (Use arrow keys)
> lankong
  smms
  tcyun
  github
  qiniu
  imgur
  aliyun
(Move up and down to reveal more choices)
C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo use
? Use an uploader lankong
? Use a transformer (Use arrow keys)
> path
  base64
C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo use
? Use an uploader lankong
? Use a transformer path
? Use plugins (Press <space> to select, <a> to toggle all, <i> to invert selection)
>(*) picgo-plugin-lankong
C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo use
? Use an uploader lankong
? Use a transformer path
? Use plugins (Press <space> to select, <a> to toggle all, <i> to invert selection)picgo-plugin-lankong
[PicGo SUCCESS]: Configure config successfully!

picgo 需要配置文件来启动。当你未指定配置文件的时候,picgo 将会使用默认配置文件来启动。

自动生成

通常来说你只需要配置 Uploader 即可,所以你可以通过 picgo set uploader 来进入交互式命令行,

C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo set uploader
? Choose a(n) uploader (Use arrow keys)
> lankong
  smms
  tcyun
  github
  qiniu
  imgur
  aliyun
(Move up and down to reveal more choices)
C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo set uploader
? Choose a(n) uploader lankong
? Choose a version (Use arrow keys)
  V1
> V2
C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo set uploader
? Choose a(n) uploader lankong
? Choose a version V2
? 示例: https://example.com https://img.daitcc.top:8090

这里的认证 token 信息为第1.3节保存的token值

C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo set uploader
? Choose a(n) uploader lankong
? Choose a version V2
? 示例: https://example.com www.daitcc.top:8089
? 认证 token 信息 Bearer 1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx

这里albumId为第1.3节保存的相册ID (选择需要默认上传的 这里我选择的是 图床)

C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo set uploader
? Choose a(n) uploader lankong
? Choose a version V2
? 示例: https://example.com www.daitcc.top:8089
? 认证 token 信息 Bearer 1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx
? 选填, V1以及V2使用默认存储策略时请留空 1
? 选填, V2生效 1
C:\Users\35476\AppData\Roaming\Typora\picgo\win64>picgo set uploader
? Choose a(n) uploader lankong
? Choose a version V2
? 示例: https://example.com www.daitcc.top:8089
? 认证 token 信息 Bearer 1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx
? 选填, V1以及V2使用默认存储策略时请留空 1
? 选填, V2生效 1
? set permission private(default)
? 是否忽略证书错误, 如果上传失败提示证书过期请设为true No
? 是否同步删除, 只支持V2 No
[PicGo SUCCESS]: Configure config successfully

默认配置文件

picgo 的默认配置文件为~/.picgo/config.json。其中~为用户目录。不同系统的用户目录不太一样。

linux 和 macOS 均为~/.picgo/config.json

windows 则为C:\Users\你的用户名\.picgo\config.json

可以用写字板打开

可以参考如下配置:

{
  "picBed": {
    "uploader": "lankong",
    "current": "lankong",
    "lankong": {
      "lskyProVersion": "V2",
      "server": "https://img.daitcc.top:8090",
      "token": "Bearer 1|ykngSEREfC7uM2yID8liqidRImfZSwJDIpmLlQPx",
      "strategyId": "1",
      "albumId": "1",
      "permission": 0,
      "ignoreCertErr": false,
      "syncDelete": false
    },
    "transformer": "path"
  },
  "picgoPlugins": {
    "picgo-plugin-lankong": true
  }
}

5.验证上传

image-20231119014836303

image-20231119015652256