使用Picgo上传图片到Chevereto 图床
使用Picgo上传图片到Chevereto 图床

使用Picgo上传图片到Chevereto 图床

内容纲要

使用Picgo上传图片到Chevereto 图床

1.前言

在以前,我记得我介绍了一个如何使用Protainer来搭建一个Chevereto 图床。

http://204.9.39.111:8082/?p=2274

最近看了一下大佬的帖子,发现能够使用Picgo搭配插件+Typora来实现图片自动上传到图床,然后自动转换成图片链接,非常方便。

之前我也设置过,但是发现只能默认用访客模式上传,不能上传到指定用户的相册下面。

偶然看到苯苯大佬的文章,让我成功配置了,受益匪浅,记录一下配置方法。

2.环境

  • MacOS 13.1

3.前提条件

  • 在Docker中安装好Chevereto

4.正式配置

4.1 下载安装Picgo.app

下载地址:https://molunerfinn.com/PicGo/

如果macOS系统安装完PicGo显示「文件已损坏」或者安装完打开没有反应

因为 PicGo 没有签名,所以会被 macOS 的安全检查所拦下。

1.安装后打开遇到「文件已损坏」的情况,请按如下方式操作:

信任开发者,会要求输入密码:

sudo spctl --master-disable

2.然后放行 PicGo :

xattr -cr /Applications/PicGo.app

然后就能正常打开。

如果提示以下内容

option -r not recognized

usage: xattr [-slz] file [file ...]
       xattr -p [-slz] attr_name file [file ...]
       xattr -w [-sz] attr_name attr_value file [file ...]
       xattr -d [-s] attr_name file [file ...]
       xattr -c [-s] file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to attr_value.
The fourth form (-d) deletes the xattr attr_name.
The fifth form (-c) deletes (clears) all xattrs.

options:
  -h: print this help
  -s: act on symbolic links themselves rather than their targets
  -l: print long format (attr_name: attr_value)
  -z: compress or decompress (if compressed) attribute value in zip format

执行命令

xattr -c /Applications/PicGo.app/*

4.2 配置Picgo.app

打开Picgo的主界面,找到最下面的插件设置

搜索下载:web-uploader 1.1.1

打开插件配置如下

API 地址: https://your-site/api/1/upload
POST 参数名: source
JSON 路径: image.url
自定义 Body: {"key":"API Key"}

PicGo 追加用户名和相册 ID,格式为{"key":"your key", "user":"username", "album":"albumid"}

相册ID可以点进对应相册的详情界面查找albumid即可。

4.3 配置Chevereto

来到我们图床进入容器内部进行操作。

docker exec -it 容器ID /bin/bash

sudo cp /app/routes/route.api.php /app/routes/overrides

# 将文件改为www-data所有
sudo chown -R 33:33 /app/routes/overrides 

#然后修改这个复制后的文件:
sudo vim /app/routes/overrides/route.api.php

#在下面两行下面新增
$version = $handler->request[0];
$action = $handler->request[1];
#新增
$user = $_REQUEST['user'];  // 新增
$album = $_REQUEST['album'];    //新增

#修改下面这行
$uploaded_id = CHV\Image::uploadToWebsite($source);
#修改为
$uploaded_id = CHV\Image::uploadToWebsite($source, $user, array('album_id'=>$album));

该步骤将接受来自客户端的用户名和相册 ID 参数,避免上传至访客相册。

保存退出重启Chevereto

测试上传图片

完成!✅

参考

参考大佬的教程配置成功,非常感谢!

https://blognas.hwb0307.com/linux/docker/526

https://tyzhang.top/article/autoupload/

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注