Skip to content

Conversation

@Chen2226
Copy link
Contributor

#31

@Chen2226 Chen2226 changed the title 适配typecho1.3 适配typecho1.3+新增文件管理接口 Sep 16, 2025
Action.php Outdated
protected \Typecho\Widget\Response $response;


protected $version;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 $version 始终是常量?常量不会变,不需要作为类成员

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改


### 2025-07-21

- 适配typecho1.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里具体做了什么适配呢,是向前兼容的吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是一些方法传参在1.2可以,1.3会报错

Action.php Outdated
$this->sendCORS();
$this->parseRequest();

// 1.3不会调用、手动调用方法
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是需要判断下 1.3 版本才走这个逻辑?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要判断,测试发现1.2.1跟1.3都需要这样写才会生效

Action.php Outdated
private function sendCORS()
{
$httpOrigin = $this->request->getServer('HTTP_ORIGIN');
$httpHost = $this->request->getServer('HTTP_HOST');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

origin 和 host 不是一个概念吧?origin 会包含协议,这里改成 host 是不是 breaking change 了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

private function parseRequest()
{
if ($this->request->isPost()) {
$pathInfo = (string)$this->request->getPathInfo();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L154-L167 这段逻辑的作用是什么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upload上传file时解析会报错,所以加了一个配置跳过解析

Action.php Outdated
if ($this->config->validateLogin == 1 && !$this->widget('Widget_User')->hasLogin()) {
$this->throwError('User must be logged in', 401);
}
if (empty($_FILES)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些解析请求体上传文件的逻辑单独拆到一个文件里,插件 controller 只要关心最终解析出来的文件结果即可。
不要把复杂逻辑耦合在这里。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已拆分到Util

/**
* 上传文件
*/
public function uploadAction()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要补充单元测试

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已补充

Action.php Outdated
{
$this->lockMethod('post');
$this->checkState('deleteFile');
if ($this->config->validateLogin == 1 && !$this->widget('Widget_User')->hasLogin()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种类似的检测登录的逻辑应该抽出来变成公共方法

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已抽成公共方法

# 变更日志

### 2025-09-15
- 新增文件管理接口
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里引入文件管理接口,想要解决的问题是什么?

个人觉得引入操作文件的 API 很可能有安全风险。

@kirainmoe
Copy link
Member

有个问题,引入文件管理接口,想要解决的问题是什么呢?我似乎不能推导出这个功能使用的场景。

而且引入操作文件的 API 很可能有安全风险,需要有严格的权限控制和校验,很容易引入漏洞。感觉 ROI 并不高。

@Chen2226
Copy link
Contributor Author

有问题,导入文件管理接口,想要解决的问题是吗?我似乎无法推导出该功能使用的场景。

而且引入操作文件的API很可能存在安全风险,需要严格的权限控制和校验,很容易引入漏洞。感觉投资回报率并不高。

我写的一个插件需要用到文件管理功能,所以加了这几个api

@kirainmoe
Copy link
Member

我写的一个插件需要用到文件管理功能

既然同样是插件,这个不能实现在你的插件中吗?

@Chen2226
Copy link
Contributor Author

Chen2226 commented Nov 19, 2025

我写了一个插件需要用到文件管理功能

同样是插件,这个不能在你的插件中实现吗?

不行啊,是一个笔记软件的插件,是用来同步本地笔记到typecho上的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants