提供删除主题的接口

pull/146/head
ruibaby 2019-04-07 17:44:34 +08:00
parent eeb06ca9bb
commit e5abaefc37
3 changed files with 33 additions and 2 deletions

View File

@ -90,4 +90,11 @@ public interface ThemeService {
* @param content new content * @param content new content
*/ */
void saveTemplateContent(String absolutePath, String content); void saveTemplateContent(String absolutePath, String content);
/**
* Delete a theme by key.
*
* @param key theme key
*/
void deleteTheme(String key);
} }

View File

@ -1,5 +1,6 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader; import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.file.FileWriter; import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.text.StrBuilder; import cn.hutool.core.text.StrBuilder;
@ -239,4 +240,16 @@ public class ThemeServiceImpl implements ThemeService {
final FileWriter fileWriter = new FileWriter(absolutePath); final FileWriter fileWriter = new FileWriter(absolutePath);
fileWriter.write(content); fileWriter.write(content);
} }
/**
* Delete a theme by key.
*
* @param key theme key
*/
@Override
public void deleteTheme(String key) {
File file = new File(this.getThemeBasePath(),key);
FileUtil.del(file);
HaloConst.THEMES = this.getThemes();
}
} }

View File

@ -74,12 +74,12 @@ public class ThemeController {
} }
@GetMapping("files/custom") @GetMapping("files/custom")
public List<String> customTemplate(){ public List<String> customTemplate() {
return themeService.getCustomTpl(HaloConst.ACTIVATED_THEME_NAME); return themeService.getCustomTpl(HaloConst.ACTIVATED_THEME_NAME);
} }
/** /**
* Active theme * Active theme.
* *
* @param theme theme name * @param theme theme name
* @throws TemplateModelException TemplateModelException * @throws TemplateModelException TemplateModelException
@ -95,4 +95,15 @@ public class ThemeController {
configuration.setSharedVariable("themeName", theme); configuration.setSharedVariable("themeName", theme);
configuration.setSharedVariable("options", optionService.listOptions()); configuration.setSharedVariable("options", optionService.listOptions());
} }
/**
* Deletes a theme.
*
* @param key theme key
*/
@DeleteMapping("{key}")
@ApiOperation("Deletes a theme")
public void deleteBy(@PathVariable("key") String key) {
themeService.deleteTheme(key);
}
} }