mirror of https://github.com/halo-dev/halo
Update readme.
parent
b97628f4a8
commit
85013b9b1e
|
@ -2,11 +2,13 @@
|
|||
|
||||
> Halo 是一款现代化的个人独立博客系统,给习惯写博客的同学多一个选择。
|
||||
|
||||
|
||||
|
||||
<p align="center">
|
||||
<a href="#"><img alt="JDK" src="https://img.shields.io/badge/JDK-1.8-yellow.svg?style=flat-square"/></a>
|
||||
<a href="https://github.com/halo-dev/halo/releases"><img alt="GitHub release" src="https://img.shields.io/github/release/halo-dev/halo.svg?style=flat-square"/></a>
|
||||
<a href="https://github.com/halo-dev/halo/releases"><img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/halo-dev/halo/total.svg?style=flat-square"></a>
|
||||
<a href="https://github.com/halo-dev/halo/commits"><img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/w/halo-dev/halo.svg?style=flat-square"></a>
|
||||
<a href="https://hub.docker.com/r/ruibaby/halo"><img alt="Docker pulls" src="https://img.shields.io/docker/pulls/ruibaby/halo?style=flat-square"></a>
|
||||
<a href="https://github.com/halo-dev/halo/commits"><img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/halo-dev/halo.svg?style=flat-square"></a>
|
||||
<a href="https://travis-ci.org/halo-dev/halo"><img alt="Travis CI" src="https://img.shields.io/travis/halo-dev/halo.svg?style=flat-square"/></a>
|
||||
</p>
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ThemeController {
|
|||
}
|
||||
|
||||
@GetMapping("{themeId}/files")
|
||||
public List<ThemeFile> listFiles(@PathVariable("themeId") String themeId){
|
||||
public List<ThemeFile> listFiles(@PathVariable("themeId") String themeId) {
|
||||
return themeService.listThemeFolderBy(themeId);
|
||||
}
|
||||
|
||||
|
@ -63,11 +63,23 @@ public class ThemeController {
|
|||
return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), themeService.getTemplateContent(path));
|
||||
}
|
||||
|
||||
@GetMapping("{themeId}/files/content")
|
||||
public BaseResponse<String> getContentBy(@PathVariable("themeId") String themeId,
|
||||
@RequestParam(name = "path") String path) {
|
||||
return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), themeService.getTemplateContent(themeId, path));
|
||||
}
|
||||
|
||||
@PutMapping("files/content")
|
||||
public void updateContentBy(@RequestBody ThemeContentParam param) {
|
||||
themeService.saveTemplateContent(param.getPath(), param.getContent());
|
||||
}
|
||||
|
||||
@PutMapping("{themeId}/files/content")
|
||||
public void updateContentBy(@PathVariable("themeId") String themeId,
|
||||
@RequestBody ThemeContentParam param) {
|
||||
themeService.saveTemplateContent(themeId, param.getPath(), param.getContent());
|
||||
}
|
||||
|
||||
@GetMapping("files/custom")
|
||||
public Set<String> customTemplate() {
|
||||
return themeService.listCustomTemplates(themeService.getActivatedThemeId());
|
||||
|
|
|
@ -165,6 +165,15 @@ public interface ThemeService {
|
|||
*/
|
||||
String getTemplateContent(@NonNull String absolutePath);
|
||||
|
||||
/**
|
||||
* Gets template content by template absolute path and themeId.
|
||||
*
|
||||
* @param themeId themeId
|
||||
* @param absolutePath absolute path
|
||||
* @return template content
|
||||
*/
|
||||
String getTemplateContent(@NonNull String themeId, @NonNull String absolutePath);
|
||||
|
||||
/**
|
||||
* Saves template content by template absolute path.
|
||||
*
|
||||
|
@ -173,6 +182,15 @@ public interface ThemeService {
|
|||
*/
|
||||
void saveTemplateContent(@NonNull String absolutePath, @NonNull String content);
|
||||
|
||||
/**
|
||||
* Saves template content by template absolute path and themeId.
|
||||
*
|
||||
* @param themeId themeId
|
||||
* @param absolutePath absolute path
|
||||
* @param content new content
|
||||
*/
|
||||
void saveTemplateContent(@NonNull String themeId, @NonNull String absolutePath, @NonNull String content);
|
||||
|
||||
/**
|
||||
* Deletes a theme by key.
|
||||
*
|
||||
|
|
|
@ -227,6 +227,19 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateContent(String themeId, String absolutePath) {
|
||||
checkDirectory(themeId, absolutePath);
|
||||
|
||||
// Read file
|
||||
Path path = Paths.get(absolutePath);
|
||||
try {
|
||||
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException("读取模板内容失败 " + absolutePath, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTemplateContent(String absolutePath, String content) {
|
||||
// Check the path
|
||||
|
@ -241,6 +254,20 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTemplateContent(String themeId, String absolutePath, String content) {
|
||||
// Check the path
|
||||
checkDirectory(themeId, absolutePath);
|
||||
|
||||
// Write file
|
||||
Path path = Paths.get(absolutePath);
|
||||
try {
|
||||
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException("保存模板内容失败 " + absolutePath, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTheme(String themeId) {
|
||||
// Get the theme property
|
||||
|
@ -704,6 +731,17 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
FileUtils.checkDirectoryTraversal(activeThemeProperty.getThemePath(), absoluteName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory is valid or not.
|
||||
*
|
||||
* @param themeId themeId must not be blank
|
||||
* @param absoluteName throws when the given absolute directory name is invalid
|
||||
*/
|
||||
private void checkDirectory(@NonNull String themeId, @NonNull String absoluteName) {
|
||||
ThemeProperty themeProperty = getThemeOfNonNullBy(themeId);
|
||||
FileUtils.checkDirectoryTraversal(themeProperty.getThemePath(), absoluteName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets property path of nullable.
|
||||
*
|
||||
|
|
|
@ -235,7 +235,7 @@ public class FileUtils {
|
|||
return;
|
||||
}
|
||||
|
||||
throw new ForbiddenException("You cannot access " + pathToCheck).setErrorData(pathToCheck);
|
||||
throw new ForbiddenException("你没有权限访问 " + pathToCheck).setErrorData(pathToCheck);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue