同步插件源代码并补齐标准项目文件
This commit is contained in:
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# Dependencies and build output
|
||||
node_modules/
|
||||
vendor/
|
||||
dist/
|
||||
build/
|
||||
out/
|
||||
main.js
|
||||
*.apk
|
||||
|
||||
# Build tools and IDE
|
||||
.gradle/
|
||||
.idea/
|
||||
*.iml
|
||||
gradle/
|
||||
gradlew
|
||||
gradlew.bat
|
||||
|
||||
# Environment and secrets
|
||||
.env
|
||||
.env.*
|
||||
keystore.properties
|
||||
*.jks
|
||||
credentials*.json
|
||||
|
||||
# Runtime data and backups
|
||||
data/
|
||||
备份/
|
||||
*.log
|
||||
.DS_Store
|
||||
2631
Action.php
Normal file
2631
Action.php
Normal file
File diff suppressed because it is too large
Load Diff
54
CHANGELOG.md
Normal file
54
CHANGELOG.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# TypechoToObsidian 更新日志
|
||||
|
||||
> 本文件记录本插件的所有修改与变化。本次整理(2026-11-22)为规范化记录起点。
|
||||
|
||||
## 插件信息
|
||||
|
||||
- 名称:TypechoToObsidian
|
||||
- 版本:2.0.9
|
||||
- 作者:石头厝
|
||||
- 说明:文章、分类、标签、评论REST_API接口
|
||||
|
||||
## 记录格式约定
|
||||
|
||||
每次修改按如下格式在**最上方**追加一条记录(新的在上):
|
||||
|
||||
```
|
||||
## YYYY-MM-DD · 版本号 —— 一句话概述
|
||||
|
||||
- 改动点 1
|
||||
- 改动点 2
|
||||
- 影响范围 / 注意事项(若有)
|
||||
- 对应备份:备份/YYYY-MM-DD-修改内容简短说明修改前/
|
||||
```
|
||||
|
||||
## 2026-11-23 · 2.0.9 —— postArticle 支持 files,把客户端上传的附件认领到文章
|
||||
|
||||
- `Action.php`:`postArticleAction` 新增可选参数 `files`(逗号分隔的附件 cid)
|
||||
- 写完文章拿到 cid 后,执行 `UPDATE ... table.contents SET parent = cid WHERE type='attachment' AND cid IN (...)`,把客户端上传时 `parent` 仍为 0 的附件挂到本文
|
||||
- 解决的问题:App 先传图再发文,图能在正文里显示,但网页端编辑页右侧「附件」列表按 `parent` 查,看不到这些图,也没法在后台删除或复用
|
||||
- 兼容性:不传 `files` 时整段跳过,Obsidian 插件等既有客户端行为完全不变;`$fileIds` 全部经 `(int)` 过滤后拼接,不引入注入面
|
||||
- 同日另有一处已在上方记录的改动:`postArticle` 支持可选 `status`(publish / waiting / hidden),App 用它把文章发成「待审核」
|
||||
- 对应备份:`备份/2026-11-23-postArticle绑定附件修改前/`
|
||||
- 部署:只需覆盖上传 `usr/plugins/TypechoToObsidian/Action.php`,无需重新启用插件
|
||||
|
||||
## 2026-11-22 · 2.0.8 —— 补齐头部版本与链接
|
||||
|
||||
- `Plugin.php` 文件头注释(Typecho 后台插件信息读取的第一段)补齐 `@version 2.0.8`、`@link https://www.shitoucuo.com/`
|
||||
- 版本号取自本插件更新日志既有版本(类注释中已有同值),后台插件列表版本显示不再为空
|
||||
- 对应备份:`备份/2026-11-22-补版本和链接修改前/`
|
||||
|
||||
## 2026-11-22 · 2.0.8 —— 统一作者与链接
|
||||
|
||||
- `Plugin.php` 头部 `@author` 统一为「石头厝」
|
||||
- `@link` 统一为 `https://www.shitoucuo.com/`
|
||||
- 影响范围:仅头部元信息,不涉及功能代码
|
||||
- 对应备份:`备份/2026-11-22-统一作者和链接修改前/`
|
||||
|
||||
---
|
||||
|
||||
## 2026-11-22 · 2.0.8 —— 建立规范化备份与更新日志
|
||||
|
||||
- 建立 `备份/` 文件夹并生成本次整理前全量备份 `备份/2026-11-22-规范化整理修改前/`
|
||||
- 创建本更新日志,作为后续所有修改的记录起点
|
||||
- 说明:本次仅做规范化整理,未改动插件功能代码
|
||||
19
CONTRIBUTING.md
Normal file
19
CONTRIBUTING.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# 贡献指南
|
||||
|
||||
欢迎对本插件提出改进建议或提交代码。
|
||||
|
||||
## 提交前检查
|
||||
|
||||
- 仅提交插件实现代码、资源与必要文档,不提交依赖目录、编译产物、运行时数据或备份文件。
|
||||
- 保持现有目录结构;如新增平台适配代码,请在 `README.md` 的目录结构中说明。
|
||||
- 涉及对外服务或凭据的配置不要写入代码或文档。
|
||||
|
||||
## 提交流程
|
||||
|
||||
1. Fork 仓库并创建功能分支。
|
||||
2. 完成修改后提交 Pull Request,说明改动目的与影响范围。
|
||||
3. 重要功能变更请同步更新 `CHANGELOG.md`。
|
||||
|
||||
## 问题反馈
|
||||
|
||||
请通过仓库 Issue 反馈问题,并尽可能提供插件类型、版本与复现步骤。
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal 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.
|
||||
1264
Plugin.php
Normal file
1264
Plugin.php
Normal file
File diff suppressed because it is too large
Load Diff
28
README.md
28
README.md
@@ -1,2 +1,30 @@
|
||||
# TypechoToObsidian
|
||||
|
||||
> 仓库:`TypechoToObsidian` · 类型:Typecho 插件 · 版本:`2.0.9` · 作者:石头厝
|
||||
|
||||
文章、分类、标签、评论 REST API 接口插件。
|
||||
|
||||
本仓库同步自本地插件源码,**仅包含插件实现代码与必要资源**;不包含依赖、构建工具、编译产物、环境配置或备份数据。
|
||||
|
||||
## 目录结构
|
||||
|
||||
- `Action.php`
|
||||
- `Plugin.php`
|
||||
- `Util.php`
|
||||
|
||||
## 安装与使用
|
||||
|
||||
1. 将本仓库目录复制到 Typecho 站点的 `usr/plugins/<仓库名>/`。
|
||||
2. 在 Typecho 后台「插件」管理中启用并按站点配置。
|
||||
|
||||
## 开发与贡献
|
||||
|
||||
详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
|
||||
|
||||
## 授权
|
||||
|
||||
授权条款见 [LICENSE](LICENSE)(MIT License)。第三方组件版权归各自作者所有。
|
||||
|
||||
## 变更记录
|
||||
|
||||
详见 [CHANGELOG.md](CHANGELOG.md)。
|
||||
|
||||
98
Util.php
Normal file
98
Util.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace TypechoPlugin\TypechoToObsidian;
|
||||
|
||||
class Util
|
||||
{
|
||||
/**
|
||||
* 获取前端上传文件(兼容多种格式)
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getUploadFile($files, $request)
|
||||
{
|
||||
$file = '';
|
||||
if (empty($files)) {
|
||||
// 兼容前端以 Uint8Array 通过 POST 发送的文件数据
|
||||
$exists = '';
|
||||
// 1) 尝试从请求参数中取
|
||||
$postBytes = $request->get('file', null, $exists);
|
||||
$fileNameParam = $request->get('fileName') ?: $request->get('name');
|
||||
|
||||
// 2) 若取不到,则尝试解析原始请求体(常见于 application/json)
|
||||
if (!$exists || $postBytes === null) {
|
||||
$raw = file_get_contents('php://input');
|
||||
if (is_string($raw) && $raw !== '') {
|
||||
$json = json_decode($raw, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($json)) {
|
||||
if (isset($json['file'])) {
|
||||
$postBytes = $json['file'];
|
||||
}
|
||||
if (!$fileNameParam && isset($json['fileName'])) {
|
||||
$fileNameParam = $json['fileName'];
|
||||
} elseif (!$fileNameParam && isset($json['name'])) {
|
||||
$fileNameParam = $json['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($postBytes === null) {
|
||||
throw new \Exception('missing file');
|
||||
}
|
||||
|
||||
// 3) 处理可能的多种表示形式
|
||||
// - 数字数组(Uint8Array)
|
||||
// - base64 字符串(data:*;base64,xxx 或纯 base64)
|
||||
// - 纯二进制字符串(不推荐,但做兜底)
|
||||
$binary = null;
|
||||
if (is_array($postBytes)) {
|
||||
if (empty($postBytes)) {
|
||||
throw new \Exception('missing file');
|
||||
}
|
||||
$bytes = array_map(static function ($v) {
|
||||
$v = (int)$v;
|
||||
if ($v < 0) {
|
||||
$v = 0;
|
||||
}
|
||||
if ($v > 255) {
|
||||
$v = 255;
|
||||
}
|
||||
return $v;
|
||||
}, $postBytes);
|
||||
$binary = pack('C*', ...$bytes);
|
||||
} elseif (is_string($postBytes)) {
|
||||
// data URL 或 base64
|
||||
if (strpos($postBytes, 'base64,') !== false) {
|
||||
$base64 = substr($postBytes, strpos($postBytes, 'base64,') + 7);
|
||||
$binary = base64_decode($base64, true);
|
||||
} else {
|
||||
// 尝试按 base64 解码,不合法则当作原始二进制
|
||||
$decoded = base64_decode($postBytes, true);
|
||||
$binary = ($decoded !== false) ? $decoded : $postBytes;
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('missing file');
|
||||
}
|
||||
|
||||
$name = $fileNameParam ?: 'upload.bin';
|
||||
if ($request->isAjax() && $name) {
|
||||
$name = urldecode($name);
|
||||
}
|
||||
|
||||
$file = array(
|
||||
'name' => $name,
|
||||
'bytes' => $binary,
|
||||
'size' => strlen($binary),
|
||||
);
|
||||
} else {
|
||||
$file = array_pop($files);
|
||||
if (!isset($file['error']) || 0 !== (int)$file['error'] || !is_uploaded_file($file['tmp_name'])) {
|
||||
throw new \Exception('upload failed');
|
||||
}
|
||||
if ($request->isAjax() && isset($file['name'])) {
|
||||
$file['name'] = urldecode($file['name']);
|
||||
}
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user