Deprecate some dangerous services

pull/146/head
johnniang 2019-04-08 11:34:54 +08:00
parent 8860a3270e
commit 99e12d7941
3 changed files with 68 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import run.halo.app.model.support.ThemeProperties;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
* @author : RYAN0UP
@ -27,6 +28,7 @@ public interface ThemeService {
* @param absolutePath absolutePath
* @return List<ThemeFile>
*/
@Deprecated
List<ThemeFile> listThemeFolder(@NonNull String absolutePath);
/**
@ -82,6 +84,7 @@ public interface ThemeService {
* @param absolutePath absolute path
* @return template content
*/
@Deprecated
String getTemplateContent(@NonNull String absolutePath);
/**
@ -98,4 +101,13 @@ public interface ThemeService {
* @param key theme key
*/
void deleteTheme(@NonNull String key);
/**
* Fetchs theme configuration.
*
* @param themeName theme name must not be blank
* @return theme configuration
*/
@NonNull
Map<String, Object> fetchConfig(@NonNull String themeName);
}

View File

@ -7,6 +7,7 @@ import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import run.halo.app.config.properties.HaloProperties;
import run.halo.app.exception.NotFoundException;
import run.halo.app.model.support.HaloConst;
@ -20,6 +21,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
/**
* @author : RYAN0UP
@ -256,4 +258,12 @@ public class ThemeServiceImpl implements ThemeService {
FileUtil.del(file);
HaloConst.THEMES = this.getThemes();
}
@Override
public Map<String, Object> fetchConfig(String themeName) {
Assert.hasText(themeName, "Theme name must not be blank");
return null;
}
}

View File

@ -0,0 +1,46 @@
package run.halo.app.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.junit.Test;
import java.io.IOException;
/**
* Yaml test.
*
* @author johnniang
* @date 4/8/19
*/
public class YamlTest {
private final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
private final ObjectMapper jsonMapper = new ObjectMapper();
@Test
public void readYamlTest() throws IOException {
String yaml = "style:\n" +
" name: Style settings\n" +
" items:\n" +
" post_title_lower:\n" +
" name: post_title_lower\n" +
" description: Post title lower\n" +
" type: radio\n" +
" defaultValue: true\n" +
" options:\n" +
" - value: true\n" +
" label: Enabled\n" +
" - value: false\n" +
" label: Disabled\n" +
" custom_style:\n" +
" name: custom_style\n" +
" description: Custom style\n" +
" type: textarea\n";
Object config = yamlMapper.readValue(yaml, Object.class);
System.out.println(jsonMapper.writeValueAsString(config));
}
}