Skip to content
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

feat: Support Rename and Edit Staitc Files (#573) #819

Merged
merged 10 commits into from
May 11, 2020

Conversation

Arexh
Copy link
Contributor

@Arexh Arexh commented May 3, 2020

加入静态文件的重命名和编辑的API,以及测试单元 #573
前端支持重命名文件,能够编辑CodeMirror支持文件格式,不同的格式有相应的语法高亮 halo-admin #152

@JohnNiang JohnNiang requested review from ruibaby and JohnNiang May 4, 2020 02:08
Path path = Paths.get(staticDir.toString(), basePath);

try {
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
Copy link
Member

Choose a reason for hiding this comment

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

写入前是否需要检查一下该文件是否存在呢?

public void save(String basePath, String content) {
Assert.notNull(basePath, "Base path must not be null");

Path path = Paths.get(staticDir.toString(), basePath);
Copy link
Member

Choose a reason for hiding this comment

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

这里是否存在 Directory traversal 风险呢?

Assert.notNull(newName, "New name must not be null");

Path newPath = pathToRename.resolveSibling(newName);
log.info("Rename [{}] to [{}]", pathToRename.toString(), newPath.toString());
Copy link
Member

Choose a reason for hiding this comment

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

可以省略 toString() 方法,这样还可能会造成 NPE。

@Arexh
Copy link
Contributor Author

Arexh commented May 4, 2020

@JohnNiang @ruibaby 改好啦,就是不知道为啥我自己写一个StaticStorageServiceImpl.java就会导致PostServiceImplTest.java的失败。。

@@ -108,4 +109,90 @@ public void dbFileReadTest() throws IOException {
log.debug("Buffer String: [{}]", bufString);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

也许应该再增加一个关于 directory traversal 的测试。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Impl的测试单元要怎么写?上次我提交了一个测试,结果导致隔壁的测试挂了,估计是注解写的不对。可以给个ImplTest的样例代码吗?

Copy link
Member

Choose a reason for hiding this comment

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

早上给你回复。

@JohnNiang JohnNiang added the kind/feature Categorizes issue or PR as related to a new feature. label May 5, 2020
@JohnNiang JohnNiang added this to the 1.3.3 milestone May 5, 2020
@Arexh Arexh requested a review from JohnNiang May 6, 2020 14:31
@ruibaby ruibaby merged commit 4197ca3 into halo-dev:master May 11, 2020
@ruibaby
Copy link
Member

ruibaby commented May 11, 2020

感谢你的贡献!

@Arexh
Copy link
Contributor Author

Arexh commented May 11, 2020

谢谢!

ruibaby pushed a commit to ruibaby/halo that referenced this pull request Jun 11, 2021
* Add rename API

* Add save API

* Add unit test for rename API

* Fix an indentation

* Add a space before '{'

* Add a Param and some invalid checks

* Change comments

* Change test annotation

* Delete impl test unit

* Add directory traversal check for static file operations

Co-authored-by: Rokita <[email protected]>
JohnNiang pushed a commit to JohnNiang/halo that referenced this pull request Mar 2, 2023
#### What type of PR is this?

/kind improvement

#### What this PR does / why we need it:

升级 Vite 到 Vite 4,请看:

- https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#400-2022-12-09
- https://cn.vitejs.dev/guide/migration.html

无破坏更新。

#### Which issue(s) this PR fixes:

Fixes halo-dev#3134

#### Special notes for your reviewer:

测试方式:

1. 测试开发环境和生产环境是否加载正常即可。
2. 测试包含 Console 的插件是否正常加载。

#### Does this PR introduce a user-facing change?

```release-note
升级 Console 项目的 Vite 版本到 Vite 4
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants