Skip to content

Conversation

Chen2226
Copy link
Contributor

#31

@Chen2226 Chen2226 changed the title 适配typecho1.3 适配typecho1.3+新增文件管理接口 Sep 16, 2025
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 始终是常量?常量不会变,不需要作为类成员


### 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.

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

$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 版本才走这个逻辑?

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 了

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 这段逻辑的作用是什么?

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 只要关心最终解析出来的文件结果即可。
不要把复杂逻辑耦合在这里。

/**
* 上传文件
*/
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.

需要补充单元测试

{
$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.

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

# 变更日志

### 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 并不高。

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