提供删除主题的接口

pull/146/head
ruibaby 2019-04-07 17:49:32 +08:00
parent e5abaefc37
commit c42203ac20
2 changed files with 15 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package run.halo.app.service; package run.halo.app.service;
import org.springframework.lang.NonNull;
import run.halo.app.model.support.Theme; import run.halo.app.model.support.Theme;
import run.halo.app.model.support.ThemeFile; import run.halo.app.model.support.ThemeFile;
import run.halo.app.model.support.ThemeProperties; import run.halo.app.model.support.ThemeProperties;
@ -26,7 +27,7 @@ public interface ThemeService {
* @param absolutePath absolutePath * @param absolutePath absolutePath
* @return List<ThemeFile> * @return List<ThemeFile>
*/ */
List<ThemeFile> listThemeFolder(String absolutePath); List<ThemeFile> listThemeFolder(@NonNull String absolutePath);
/** /**
* Lists theme folder by theme name. * Lists theme folder by theme name.
@ -34,7 +35,7 @@ public interface ThemeService {
* @param theme theme * @param theme theme
* @return List<ThemeFile> * @return List<ThemeFile>
*/ */
List<ThemeFile> listThemeFolderBy(String theme); List<ThemeFile> listThemeFolderBy(@NonNull String theme);
/** /**
* Gets custom template, such as page_xxx.ftl, and xxx will be template name * Gets custom template, such as page_xxx.ftl, and xxx will be template name
@ -42,7 +43,7 @@ public interface ThemeService {
* @param theme theme name * @param theme theme name
* @return List * @return List
*/ */
List<String> getCustomTpl(String theme); List<String> getCustomTpl(@NonNull String theme);
/** /**
* Judging whether template exists under the specified theme * Judging whether template exists under the specified theme
@ -50,7 +51,7 @@ public interface ThemeService {
* @param template template * @param template template
* @return boolean * @return boolean
*/ */
boolean isTemplateExist(String template); boolean isTemplateExist(@NonNull String template);
/** /**
* Judging whether theme exists under template path * Judging whether theme exists under template path
@ -58,7 +59,7 @@ public interface ThemeService {
* @param theme theme name * @param theme theme name
* @return boolean * @return boolean
*/ */
boolean isThemeExist(String theme); boolean isThemeExist(@NonNull String theme);
/** /**
* Gets theme base path. * Gets theme base path.
@ -73,7 +74,7 @@ public interface ThemeService {
* @param path path * @param path path
* @return ThemeProperties * @return ThemeProperties
*/ */
ThemeProperties getProperties(File path); ThemeProperties getProperties(@NonNull File path);
/** /**
* Get template content by template absolute path. * Get template content by template absolute path.
@ -81,7 +82,7 @@ public interface ThemeService {
* @param absolutePath absolute path * @param absolutePath absolute path
* @return template content * @return template content
*/ */
String getTemplateContent(String absolutePath); String getTemplateContent(@NonNull String absolutePath);
/** /**
* Save template content by template absolute path. * Save template content by template absolute path.
@ -89,12 +90,12 @@ public interface ThemeService {
* @param absolutePath absolute path * @param absolutePath absolute path
* @param content new content * @param content new content
*/ */
void saveTemplateContent(String absolutePath, String content); void saveTemplateContent(@NonNull String absolutePath, @NonNull String content);
/** /**
* Delete a theme by key. * Delete a theme by key.
* *
* @param key theme key * @param key theme key
*/ */
void deleteTheme(String key); void deleteTheme(@NonNull String key);
} }

View File

@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props; import cn.hutool.setting.dialect.Props;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import run.halo.app.config.properties.HaloProperties; import run.halo.app.config.properties.HaloProperties;
import run.halo.app.exception.NotFoundException;
import run.halo.app.model.support.HaloConst; import run.halo.app.model.support.HaloConst;
import run.halo.app.model.support.Theme; import run.halo.app.model.support.Theme;
import run.halo.app.model.support.ThemeFile; import run.halo.app.model.support.ThemeFile;
@ -248,7 +249,10 @@ public class ThemeServiceImpl implements ThemeService {
*/ */
@Override @Override
public void deleteTheme(String key) { public void deleteTheme(String key) {
File file = new File(this.getThemeBasePath(),key); if (!this.isThemeExist(key)) {
throw new NotFoundException("该主题不存在!").setErrorData(key);
}
File file = new File(this.getThemeBasePath(), key);
FileUtil.del(file); FileUtil.del(file);
HaloConst.THEMES = this.getThemes(); HaloConst.THEMES = this.getThemes();
} }