初始化:Typecho 版七牛云存储插件 2.9.0(含文件名前缀)

This commit is contained in:
XIGE
2026-12-03 21:35:24 +08:00
parent b89b4229f4
commit 8310fde59e
8 changed files with 2410 additions and 1 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Runtime data, cache and logs
data/
cache/
*.log
# Backups and temporary files
备份/
*.bak
*.tmp
.DS_Store
# Environment and secrets
.env
.env.*
*key*.txt
credentials*.json
# Editor and build artifacts
.idea/
.vscode/
node_modules/
vendor/
dist/
build/

50
CHANGELOG.md Normal file
View File

@@ -0,0 +1,50 @@
# Qiniu 更新日志
> 本文件记录本插件的所有修改与变化。仓库建立于 2026-12-03,此前历史见插件目录内的 `更新日志.MD`。
## 插件信息
- 名称:七牛云存储
- 版本:2.9.0
- 作者:石头厝
- 说明:七牛云存储 + CDN + WebP + 图片质量 + EXIF 信息 + 文件名前缀
## 记录格式约定
每次修改按如下格式在**最上方**追加一条记录(新的在上):
```
## YYYY-MM-DD · 版本号 —— 一句话概述
- 改动点 1
- 改动点 2
- 影响范围 / 注意事项(若有)
```
## 2026-12-03 · 2.9.0 —— 新增「文件名前缀」设置
- 设置页新增「文件名前缀」(`prefix`),最终对象键为 `保存路径前缀/前缀_原文件名.扩展名`;留空不启用
- 新增 `renderPrefix()`:变量替换(`{year}` `{month}` `{day}`)→ 空白剔除 → 非法字符抹平 → 连续下划线归一 → 40 字符截断
- 前缀只加在文件名上:`/` `\` 会抹成 `_`,不会把前缀变成新目录层级
- 表单侧用闭包按字符数校验(Typecho 内置 `maxLength` 按字节计,中文会被误判超限)
- 「替换附件」沿用原对象键、不加前缀:改名等于换地址,正文已插入的图片会失效
- 升级无需停用再启用;前缀缺省为空,升级后行为与 2.8.3 一致
## 2026-12-03 · 2.8.3 —— 密钥加密存储,后台不再明文回显
- AccessKey / SecretKey 改为 AES-256-GCM 密文存库,表单只回填 `enc:v1:` 密文占位
- 新增 `configHandle()` 接管保存:空值 = 保持原值,新值 = 加密写入
- `getConfig()` 内解密,调用点零改动;历史明文原样兼容
- 回滚到 2.8.3 之前需先把密钥改回明文
## 2026-12-03 · 2.8.2 —— 修复设置保存的 regexp 校验 TypeError
- 「图片质量」的 `regexp` 规则改为闭包(`Typecho\Validate` 无 `regexp` 方法,PHP 8 下直接抛 `TypeError`)
## 2026-11-22 · 2.8.1 —— PHP 8.5 兼容
- 七牛 SDK 4 处隐式可空参数(`Type $x = null`)改为显式可空(`?Type`),消除 `E_DEPRECATED`
## 2026-11-22 · 2.8.0 —— 统一作者与链接
- `Plugin.php` 头部 `@author` 统一为「石头厝」,`@link` 统一为 `https://www.shitoucuo.com/`

19
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,19 @@
# 贡献指南
欢迎对本项目提出改进建议或提交代码。
## 提交前检查
- 仅提交插件实现代码、静态资源与必要文档;不要提交 `data/`、`cache/`、调试日志、备份目录或 API Key 等敏感信息。
- 变更涉及 Typecho 钩子或 PHP 版本兼容时,请确认兼容 Typecho 1.3 与 PHP 8.5。
- 影响用户配置或后台展示的改动,请同步更新 `README.md` 与 `CHANGELOG.md`。
## 提交流程
1. Fork 仓库并创建功能分支。
2. 完成修改后提交 Pull Request,说明改动目的与影响范围。
3. 重要变更请补充变更记录。
## 问题反馈
请通过仓库 Issue 反馈问题,并附上插件版本、Typecho / PHP 版本与复现步骤。

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 石头厝
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.

2095
Plugin.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,2 +1,55 @@
# typecho-qiniu
# Qiniu(七牛云存储)
> 仓库:`typecho-qiniu` · 类型:Typecho 插件 · 版本:`2.9.0` · 作者:石头厝
把附件上传到七牛云对象存储,并用绑定域名走 CDN 输出;支持 WebP 自动转换、图片质量压缩、EXIF 拍摄信息展示,以及可配置的文件名前缀。本仓库仅包含插件实现代码与必要文档,不包含备份目录、运行时数据与 `vendor/` 依赖。
> 命名说明:`XIGE/Qiniu` 已被 Obsidian 版同名插件占用,Typecho 版单独建仓为 `typecho-qiniu`,避免两个项目的源码互相覆盖。
## 功能
- **上传接管**:接管 Typecho 的 `Widget_Upload` 四个钩子(上传、修改、删除、地址),附件存到七牛,正文与后台列表统一输出 CDN 地址。
- **路径与前缀**:`保存路径前缀` 决定目录层级(支持 `{year}` `{month}` `{day}` `{random}`);`文件名前缀` 决定文件名前缀(支持 `{year}` `{month}` `{day}`),最终对象键为 `路径前缀/文件名前缀_原文件名.扩展名`。
- **WebP 与压缩**:开启后 JPEG/PNG 上传即转 WebP(GIF 保持原格式),并可按 1-100 的质量值压缩;非 85 的取值或 WebP 输出会通过七牛图片处理参数在访问时生效。
- **EXIF 展示**:开启后文章详情页图片悬停显示相机型号、快门、光圈、ISO、焦距。
- **密钥加密**:AccessKey / SecretKey 以 AES-256-GCM 密文存库,后台表单只回填密文占位,页面与源码中不出现明文。
- **设置备份 / 恢复**:设置页顶部可一键备份当前配置,保留最近 5 份,可从历史备份任选恢复;备份文件位于插件内 `data/backup/`,带 `.htaccess` 与空 `index.html` 禁止公网读取。
- **未配置降级**:已启用但未填写配置时,附件回退本地地址与本地删除,不会出现「地址空、文件孤儿」。
## 环境要求
- Typecho 1.3.0 及以上(1.2.x 需要类名兼容层,本版本以 1.3 为基线)。
- PHP 7.1 及以上,推荐 8.x;WebP 转换需要 GD 且开启 WebP 支持。
- 七牛 PHP SDK(`qiniu/php-sdk`)通过 Composer 安装,`vendor/` 不入库。
## 安装与升级
1. 首次安装:把本仓库放到 `usr/plugins/Qiniu/`,在插件目录执行 `composer install` 安装 SDK,然后在后台启用。
2. 升级:直接覆盖 `Plugin.php` 即可,无需停用再启用。
3. 从 2.8.x 升级到 2.9.0:默认前缀为空,行为不变;填好「文件名前缀」并保存后才对新上传生效。
## 配置项说明
- **空间名称 / 绑定域名**:必填;域名需带协议,例如 `https://cdn.example.com`。
- **AccessKey / SecretKey**:留空表示保持原值;框内若显示 `enc:v1:` 开头的密文,直接保存不会改动。
- **保存路径前缀**:目录层级,默认 `typecho/{year}/{month}/`。
- **文件名前缀**:只加在文件名上,不作为目录;斜杠与非法字符会被抹成下划线,空白字符直接删除,连续下划线归一,最长 40 个字符;留空不启用。
- **WebP / 图片质量 / EXIF**:见上文功能说明。
## 行为边界
- 文件名前缀只作用于**新上传**。「替换附件」沿用原对象键,因为改名等于换地址,正文中已引用的图片会立即失效。
- 修改前缀不会重命名历史文件;需要存量对象也带前缀时,应在七牛侧 `copy` + `delete` 迁移并同步更新 `contents` 表的 `path`。
- 密钥由站点 `options.secret` 派生加密,换域名或换 secret 后旧密文失效,此时插件回退本地存储并在设置页提示重填。
## 开发与贡献
详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
## 授权
授权条款见 [LICENSE](LICENSE)(MIT License)。七牛 PHP SDK 版权归其作者所有。
## 变更记录
详见 [CHANGELOG.md](CHANGELOG.md)。

5
composer.json Normal file
View File

@@ -0,0 +1,5 @@
{
"require": {
"qiniu/php-sdk": "^7.14"
}
}

142
composer.lock generated Normal file
View File

@@ -0,0 +1,142 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e53b7aa650906cf4c75020ac18b97155",
"packages": [
{
"name": "myclabs/php-enum",
"version": "1.8.5",
"source": {
"type": "git",
"url": "https://github.com/myclabs/php-enum.git",
"reference": "e7be26966b7398204a234f8673fdad5ac6277802"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/php-enum/zipball/e7be26966b7398204a234f8673fdad5ac6277802",
"reference": "e7be26966b7398204a234f8673fdad5ac6277802",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": "^7.3 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "1.*",
"vimeo/psalm": "^4.6.2 || ^5.2"
},
"type": "library",
"autoload": {
"psr-4": {
"MyCLabs\\Enum\\": "src/"
},
"classmap": [
"stubs/Stringable.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP Enum contributors",
"homepage": "https://github.com/myclabs/php-enum/graphs/contributors"
}
],
"description": "PHP Enum implementation",
"homepage": "https://github.com/myclabs/php-enum",
"keywords": [
"enum"
],
"support": {
"issues": "https://github.com/myclabs/php-enum/issues",
"source": "https://github.com/myclabs/php-enum/tree/1.8.5"
},
"funding": [
{
"url": "https://github.com/mnapoli",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/php-enum",
"type": "tidelift"
}
],
"time": "2025-01-14T11:49:03+00:00"
},
{
"name": "qiniu/php-sdk",
"version": "v7.14.0",
"source": {
"type": "git",
"url": "https://github.com/qiniu/php-sdk.git",
"reference": "ee752ffa7263ce99fca0bd7340cf13c486a3516c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/ee752ffa7263ce99fca0bd7340cf13c486a3516c",
"reference": "ee752ffa7263ce99fca0bd7340cf13c486a3516c",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-xml": "*",
"myclabs/php-enum": "~1.5.2 || ~1.6.6 || ~1.7.7 || ~1.8.4",
"php": ">=5.3.3"
},
"require-dev": {
"paragonie/random_compat": ">=2",
"phpunit/phpunit": "^4.8 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4",
"squizlabs/php_codesniffer": "^2.3 || ~3.6"
},
"type": "library",
"autoload": {
"files": [
"src/Qiniu/functions.php",
"src/Qiniu/Http/Middleware/Middleware.php"
],
"psr-4": {
"Qiniu\\": "src/Qiniu"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Qiniu",
"email": "sdk@qiniu.com",
"homepage": "http://www.qiniu.com"
}
],
"description": "Qiniu Resource (Cloud) Storage SDK for PHP",
"homepage": "http://developer.qiniu.com/",
"keywords": [
"cloud",
"qiniu",
"sdk",
"storage"
],
"support": {
"issues": "https://github.com/qiniu/php-sdk/issues",
"source": "https://github.com/qiniu/php-sdk/tree/v7.14.0"
},
"time": "2024-10-25T08:39:01+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.0.0"
}