-
Notifications
You must be signed in to change notification settings - Fork 28
适配typecho1.3+新增文件管理接口 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
新增接口:用户列表、发表文章、新增分类/标签 新增apiToken校验
发表评论/发表文章/新增分类接口增加校验csrfToken、 文章详情不返回csrfToken、 单元测试修改
发布文章、新增标签/分类接口修改 增加可选校验高敏接口设置
Action.php
Outdated
| protected \Typecho\Widget\Response $response; | ||
|
|
||
|
|
||
| protected $version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里 $version 始终是常量?常量不会变,不需要作为类成员
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里具体做了什么适配呢,是向前兼容的吗
There was a problem hiding this comment.
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不会调用、手动调用方法 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是需要判断下 1.3 版本才走这个逻辑?
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 了
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L154-L167 这段逻辑的作用是什么?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些解析请求体上传文件的逻辑单独拆到一个文件里,插件 controller 只要关心最终解析出来的文件结果即可。
不要把复杂逻辑耦合在这里。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已拆分到Util
| /** | ||
| * 上传文件 | ||
| */ | ||
| public function uploadAction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要补充单元测试
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种类似的检测登录的逻辑应该抽出来变成公共方法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已抽成公共方法
| # 变更日志 | ||
|
|
||
| ### 2025-09-15 | ||
| - 新增文件管理接口 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里引入文件管理接口,想要解决的问题是什么?
个人觉得引入操作文件的 API 很可能有安全风险。
|
有个问题,引入文件管理接口,想要解决的问题是什么呢?我似乎不能推导出这个功能使用的场景。 而且引入操作文件的 API 很可能有安全风险,需要有严格的权限控制和校验,很容易引入漏洞。感觉 ROI 并不高。 |
我写的一个插件需要用到文件管理功能,所以加了这几个api |
既然同样是插件,这个不能实现在你的插件中吗? |
不行啊,是一个笔记软件的插件,是用来同步本地笔记到typecho上的 |
#31