mirror of https://github.com/halo-dev/halo
feat: support preset post meta field.
parent
ddef7e09d2
commit
0400911941
|
@ -58,6 +58,7 @@ ext {
|
|||
thumbnailatorVersion = '0.4.8'
|
||||
image4jVersion = '0.7zensight1'
|
||||
flywayVersion = '6.1.0'
|
||||
h2Version = '1.4.196'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -101,7 +102,7 @@ dependencies {
|
|||
implementation "net.sf.image4j:image4j:$image4jVersion"
|
||||
implementation "org.flywaydb:flyway-core:$flywayVersion"
|
||||
|
||||
runtimeOnly 'com.h2database:h2:1.4.196'
|
||||
runtimeOnly "com.h2database:h2:$h2Version"
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,6 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import run.halo.app.config.properties.HaloProperties;
|
||||
import run.halo.app.model.entity.User;
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.security.filter.AdminAuthenticationFilter;
|
||||
import run.halo.app.security.filter.ApiAuthenticationFilter;
|
||||
import run.halo.app.security.support.UserDetail;
|
||||
import springfox.documentation.builders.*;
|
||||
import springfox.documentation.schema.AlternateTypeRule;
|
||||
|
|
|
@ -41,16 +41,16 @@ public class HaloProperties {
|
|||
*/
|
||||
private String adminPath = "admin";
|
||||
|
||||
/**
|
||||
* Halo backup directory.(Not recommended to modify this config);
|
||||
*/
|
||||
private String backupDir = ensureSuffix(TEMP_DIR, FILE_SEPARATOR) + "halo-backup" + FILE_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Work directory.
|
||||
*/
|
||||
private String workDir = ensureSuffix(USER_HOME, FILE_SEPARATOR) + ".halo" + FILE_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Halo backup directory.(Not recommended to modify this config);
|
||||
*/
|
||||
private String backupDir = ensureSuffix(TEMP_DIR, FILE_SEPARATOR) + "halo-backup" + FILE_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Upload prefix.
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.springframework.data.web.PageableDefault;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import run.halo.app.cache.lock.CacheLock;
|
||||
import run.halo.app.model.dto.AttachmentDTO;
|
||||
import run.halo.app.model.entity.Attachment;
|
||||
import run.halo.app.model.params.AttachmentParam;
|
||||
|
|
|
@ -13,9 +13,7 @@ import run.halo.app.cache.StringCacheStore;
|
|||
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
||||
import run.halo.app.model.entity.Post;
|
||||
import run.halo.app.model.entity.PostMeta;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.params.PostMetaParam;
|
||||
import run.halo.app.model.params.PostParam;
|
||||
import run.halo.app.model.params.PostQuery;
|
||||
import run.halo.app.model.vo.PostDetailVO;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package run.halo.app.controller.admin.api;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import run.halo.app.model.support.StaticFile;
|
||||
import run.halo.app.service.StaticStorageService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ryan0up
|
||||
* @date 2019/12/6
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/admin/statics")
|
||||
public class StaticStorageController {
|
||||
|
||||
private final StaticStorageService staticStorageService;
|
||||
|
||||
public StaticStorageController(StaticStorageService staticStorageService) {
|
||||
this.staticStorageService = staticStorageService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<StaticFile> list() {
|
||||
return staticStorageService.listStaticFolder();
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ import run.halo.app.model.vo.PostListVO;
|
|||
import run.halo.app.service.*;
|
||||
import run.halo.app.utils.MarkdownUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package run.halo.app.event.logger;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.context.support.ServletContextScope;
|
||||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.model.params.LogParam;
|
||||
import run.halo.app.utils.ServletUtils;
|
||||
import run.halo.app.utils.ValidationUtils;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* @author johnniang
|
||||
* @date 19-4-20
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.cors.CorsUtils;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
import run.halo.app.security.filter.AdminAuthenticationFilter;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.handler.file;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
import net.sf.image4j.codec.ico.ICODecoder;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
|
@ -23,10 +24,8 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import net.sf.image4j.codec.ico.ICODecoder;
|
||||
|
||||
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||
|
||||
|
@ -57,12 +56,9 @@ public class LocalFileHandler implements FileHandler {
|
|||
* Thumbnail height.
|
||||
*/
|
||||
private final static int THUMB_HEIGHT = 256;
|
||||
|
||||
ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
private final OptionService optionService;
|
||||
|
||||
private final String workDir;
|
||||
ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public LocalFileHandler(OptionService optionService,
|
||||
HaloProperties haloProperties) {
|
||||
|
|
|
@ -2,7 +2,6 @@ package run.halo.app.handler.theme.config.impl;
|
|||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
|
|
@ -3,12 +3,13 @@ package run.halo.app.handler.theme.config.support;
|
|||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Theme property.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @date : 2019-03-22
|
||||
* @date 2019-03-22
|
||||
*/
|
||||
@Data
|
||||
public class ThemeProperty {
|
||||
|
@ -83,6 +84,16 @@ public class ThemeProperty {
|
|||
*/
|
||||
private String screenshots;
|
||||
|
||||
/**
|
||||
* Post preset metas.
|
||||
*/
|
||||
private Set<String> postMetaField;
|
||||
|
||||
/**
|
||||
* Sheet preset metas.
|
||||
*/
|
||||
private Set<String> sheetMetaField;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
@ -101,7 +112,7 @@ public class ThemeProperty {
|
|||
}
|
||||
|
||||
@Data
|
||||
public static class Author {
|
||||
private static class Author {
|
||||
|
||||
/**
|
||||
* Author name.
|
||||
|
|
|
@ -4,8 +4,6 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Http trace dto.
|
||||
*
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* Post meta output dto.
|
||||
*
|
||||
* @author guqing
|
||||
* @date 2019-11-30
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,6 @@ import lombok.ToString;
|
|||
import run.halo.app.model.dto.base.OutputConverter;
|
||||
import run.halo.app.model.entity.BasePost;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.enums.PostType;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.utils.ServletUtils;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public class Menu extends BaseEntity {
|
|||
parentId = 0;
|
||||
}
|
||||
|
||||
if(team == null){
|
||||
if (team == null) {
|
||||
team = "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
|
|
@ -16,11 +16,6 @@ public enum Mode {
|
|||
DEVELOPMENT,
|
||||
TEST;
|
||||
|
||||
@JsonValue
|
||||
String getValue() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode from value.
|
||||
*
|
||||
|
@ -44,4 +39,9 @@ public enum Mode {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
String getValue() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public abstract class BaseCommentParam<COMMENT> implements InputConverter<COMMEN
|
|||
private String email;
|
||||
|
||||
@Size(max = 127, message = "评论者博客链接的字符长度不能超过 {max}")
|
||||
@URL(message= "博客链接格式不正确")
|
||||
@URL(message = "博客链接格式不正确")
|
||||
private String authorUrl;
|
||||
|
||||
@NotBlank(message = "评论内容不能为空")
|
||||
|
|
|
@ -88,11 +88,11 @@ public class PostParam implements InputConverter<Post> {
|
|||
|
||||
public Set<PostMeta> getPostMetas() {
|
||||
Set<PostMeta> postMetaSet = new HashSet<>();
|
||||
if(CollectionUtils.isEmpty(postMetas)) {
|
||||
if (CollectionUtils.isEmpty(postMetas)) {
|
||||
return postMetaSet;
|
||||
}
|
||||
|
||||
for(PostMetaParam postMetaParam : postMetas) {
|
||||
for (PostMetaParam postMetaParam : postMetas) {
|
||||
PostMeta postMeta = postMetaParam.convertTo();
|
||||
postMetaSet.add(postMeta);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package run.halo.app.model.params;
|
|||
import lombok.Data;
|
||||
import run.halo.app.model.dto.base.InputConverter;
|
||||
import run.halo.app.model.entity.User;
|
||||
import run.halo.app.model.support.AllCheck;
|
||||
import run.halo.app.model.support.CreateCheck;
|
||||
import run.halo.app.model.support.UpdateCheck;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public enum PostProperties implements PropertyEnum {
|
|||
|
||||
INDEX_PAGE_SIZE("post_index_page_size", Integer.class, "10"),
|
||||
|
||||
INDEX_SORT("post_index_sort",String.class,"createTime");
|
||||
INDEX_SORT("post_index_sort", String.class, "createTime");
|
||||
|
||||
private final String value;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public enum UpOssProperties implements PropertyEnum {
|
|||
/**
|
||||
* upyun oss domain protocol
|
||||
*/
|
||||
OSS_PROTOCOL("oss_upyun_domain_protocol",String.class,"https://"),
|
||||
OSS_PROTOCOL("oss_upyun_domain_protocol", String.class, "https://"),
|
||||
|
||||
/**
|
||||
* upyun oss domain
|
||||
|
@ -47,7 +47,7 @@ public enum UpOssProperties implements PropertyEnum {
|
|||
/**
|
||||
* upyun oss thumbnail style rule
|
||||
*/
|
||||
OSS_THUMBNAIL_STYLE_RULE("oss_upyun_thumbnail_style_rule",String.class,"");
|
||||
OSS_THUMBNAIL_STYLE_RULE("oss_upyun_thumbnail_style_rule", String.class, "");
|
||||
|
||||
private final String defaultValue;
|
||||
private String value;
|
||||
|
|
|
@ -90,51 +90,41 @@ public class HaloConst {
|
|||
* YouTube 视频正则表达式
|
||||
*/
|
||||
public static final String YOUTUBE_VIDEO_REG_PATTERN = "\\[youtube:(\\w+)\\,(\\d+)\\,(\\d+)\\]";
|
||||
/**
|
||||
* user_session
|
||||
*/
|
||||
public static String USER_SESSION_KEY = "user_session";
|
||||
|
||||
/**
|
||||
* Github Api url for halo-admin release.
|
||||
*/
|
||||
public final static String HALO_ADMIN_RELEASES_LATEST = "https://api.github.com/repos/halo-dev/halo-admin/releases/latest";
|
||||
|
||||
/**
|
||||
* Halo admin version regex.
|
||||
*/
|
||||
public final static String HALO_ADMIN_VERSION_REGEX = "halo-admin-\\d+\\.\\d+(\\.\\d+)?(-\\S*)?\\.zip";
|
||||
|
||||
public final static String HALO_ADMIN_RELATIVE_PATH = "templates/admin/";
|
||||
|
||||
public final static String HALO_ADMIN_RELATIVE_BACKUP_PATH = "templates/admin-backup/";
|
||||
|
||||
/**
|
||||
* Content token header name.
|
||||
*/
|
||||
public final static String API_ACCESS_KEY_HEADER_NAME = "API-" + HttpHeaders.AUTHORIZATION;
|
||||
|
||||
/**
|
||||
* Admin token header name.
|
||||
*/
|
||||
public final static String ADMIN_TOKEN_HEADER_NAME = "ADMIN-" + HttpHeaders.AUTHORIZATION;
|
||||
|
||||
/**
|
||||
* Admin token param name.
|
||||
*/
|
||||
public final static String ADMIN_TOKEN_QUERY_NAME = "admin_token";
|
||||
|
||||
/**
|
||||
* Temporary token.
|
||||
*/
|
||||
public final static String TEMP_TOKEN = "temp_token";
|
||||
|
||||
/**
|
||||
* Content api token param name
|
||||
*/
|
||||
public final static String API_ACCESS_KEY_QUERY_NAME = "api_access_key";
|
||||
|
||||
public final static Duration TEMP_TOKEN_EXPIRATION = Duration.ofDays(7);
|
||||
/**
|
||||
* user_session
|
||||
*/
|
||||
public static String USER_SESSION_KEY = "user_session";
|
||||
|
||||
static {
|
||||
// Set version
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package run.halo.app.model.support;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Static file.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @date 2019-12-06
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
public class StaticFile implements Comparator<StaticFile> {
|
||||
|
||||
private String name;
|
||||
|
||||
private String path;
|
||||
|
||||
private String relativePath;
|
||||
|
||||
private Boolean isFile;
|
||||
|
||||
private String mediaType;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
private List<StaticFile> children;
|
||||
|
||||
@Override
|
||||
public int compare(StaticFile leftFile, StaticFile rightFile) {
|
||||
if (leftFile.isFile && !rightFile.isFile) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!leftFile.isFile && rightFile.isFile) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return leftFile.getName().compareTo(rightFile.getName());
|
||||
}
|
||||
}
|
|
@ -7,9 +7,6 @@ import run.halo.app.model.dto.CategoryDTO;
|
|||
import run.halo.app.model.dto.PostMetaDTO;
|
||||
import run.halo.app.model.dto.TagDTO;
|
||||
import run.halo.app.model.dto.post.BasePostDetailDTO;
|
||||
import run.halo.app.model.entity.Category;
|
||||
import run.halo.app.model.entity.PostMeta;
|
||||
import run.halo.app.model.entity.Tag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
|
@ -6,7 +6,6 @@ import run.halo.app.model.dto.CategoryDTO;
|
|||
import run.halo.app.model.dto.PostMetaDTO;
|
||||
import run.halo.app.model.dto.TagDTO;
|
||||
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
||||
import run.halo.app.model.entity.PostMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static run.halo.app.model.support.HaloConst.*;
|
||||
import static run.halo.app.model.support.HaloConst.ADMIN_TOKEN_HEADER_NAME;
|
||||
import static run.halo.app.model.support.HaloConst.ADMIN_TOKEN_QUERY_NAME;
|
||||
|
||||
/**
|
||||
* Api authentication Filter
|
||||
|
|
|
@ -67,6 +67,7 @@ public interface CategoryService extends CrudService<Category, Integer> {
|
|||
|
||||
/**
|
||||
* List categories by parent id.
|
||||
*
|
||||
* @param id parent id.
|
||||
* @return list of category.
|
||||
*/
|
||||
|
|
|
@ -18,5 +18,5 @@ public interface MigrateService {
|
|||
* @param file multipart file must not be null
|
||||
* @param migrateType migrate type
|
||||
*/
|
||||
void migrate(@NonNull MultipartFile file,@NonNull MigrateType migrateType);
|
||||
void migrate(@NonNull MultipartFile file, @NonNull MigrateType migrateType);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package run.halo.app.service;
|
||||
|
||||
import run.halo.app.model.support.StaticFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Static storage service interface class.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @date 2019-12-06
|
||||
*/
|
||||
public interface StaticStorageService {
|
||||
|
||||
/**
|
||||
* Static folder location.
|
||||
*/
|
||||
String STATIC_FOLDER = "static";
|
||||
|
||||
/**
|
||||
* Lists static folder.
|
||||
*
|
||||
* @return List<StaticFile>
|
||||
*/
|
||||
List<StaticFile> listStaticFolder();
|
||||
}
|
|
@ -24,7 +24,6 @@ import run.halo.app.service.AttachmentService;
|
|||
import run.halo.app.service.OptionService;
|
||||
import run.halo.app.service.base.AbstractCrudService;
|
||||
import run.halo.app.utils.HaloUtils;
|
||||
import run.halo.app.utils.ServiceUtils;
|
||||
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.util.*;
|
||||
|
|
|
@ -50,7 +50,8 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static run.halo.app.model.support.HaloConst.*;
|
||||
import static run.halo.app.model.support.HaloConst.TEMP_TOKEN;
|
||||
import static run.halo.app.model.support.HaloConst.TEMP_TOKEN_EXPIRATION;
|
||||
|
||||
/**
|
||||
* Backup service implementation.
|
||||
|
@ -63,9 +64,8 @@ import static run.halo.app.model.support.HaloConst.*;
|
|||
@Slf4j
|
||||
public class BackupServiceImpl implements BackupService {
|
||||
|
||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
public static final String BACKUP_TOKEN_KEY_PREFIX = "backup-token-";
|
||||
|
||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
private final PostService postService;
|
||||
private final PostTagService postTagService;
|
||||
private final OptionService optionService;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -56,8 +57,10 @@ public class PostMetaServiceImpl extends BaseMetaServiceImpl<PostMeta> implement
|
|||
|
||||
// Save post metas
|
||||
postMetas.forEach(postMeta -> {
|
||||
postMeta.setPostId(postId);
|
||||
postMetaRepository.save(postMeta);
|
||||
if (StringUtils.isNotEmpty(postMeta.getValue()) && StringUtils.isNotEmpty(postMeta.getKey())) {
|
||||
postMeta.setPostId(postId);
|
||||
postMetaRepository.save(postMeta);
|
||||
}
|
||||
});
|
||||
return new ArrayList<>(postMetas);
|
||||
}
|
||||
|
|
|
@ -473,9 +473,9 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
/**
|
||||
* Converts to post detail vo.
|
||||
*
|
||||
* @param post post must not be null
|
||||
* @param tags tags
|
||||
* @param categories categories
|
||||
* @param post post must not be null
|
||||
* @param tags tags
|
||||
* @param categories categories
|
||||
* @param postMetaList postMetas
|
||||
* @return post detail vo
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package run.halo.app.service.impl;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import run.halo.app.config.properties.HaloProperties;
|
||||
import run.halo.app.exception.ServiceException;
|
||||
import run.halo.app.model.support.StaticFile;
|
||||
import run.halo.app.service.StaticStorageService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* StaticStorageService implementation class.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @date 2019-12-06
|
||||
*/
|
||||
@Service
|
||||
public class StaticStorageServiceImpl implements StaticStorageService {
|
||||
|
||||
private final Path staticDir;
|
||||
|
||||
private final HaloProperties haloProperties;
|
||||
|
||||
public StaticStorageServiceImpl(HaloProperties haloProperties) {
|
||||
staticDir = Paths.get(haloProperties.getWorkDir(), STATIC_FOLDER);
|
||||
this.haloProperties = haloProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StaticFile> listStaticFolder() {
|
||||
System.out.println(staticDir);
|
||||
return listStaticFileTree(staticDir);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<StaticFile> listStaticFileTree(@NonNull Path topPath) {
|
||||
Assert.notNull(topPath, "Top path must not be null");
|
||||
|
||||
if (!Files.isDirectory(topPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Stream<Path> pathStream = Files.list(topPath)) {
|
||||
List<StaticFile> staticFiles = new LinkedList<>();
|
||||
|
||||
pathStream.forEach(path -> {
|
||||
StaticFile staticFile = new StaticFile();
|
||||
staticFile.setName(path.getFileName().toString());
|
||||
staticFile.setPath(path.toString());
|
||||
staticFile.setRelativePath(StringUtils.removeStart(path.toString(), staticDir.toString()));
|
||||
staticFile.setIsFile(Files.isRegularFile(path));
|
||||
try {
|
||||
staticFile.setCreateTime(Files.getLastModifiedTime(path).toMillis());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (Files.isDirectory(path)) {
|
||||
staticFile.setChildren(listStaticFileTree(path));
|
||||
}
|
||||
|
||||
staticFiles.add(staticFile);
|
||||
});
|
||||
|
||||
staticFiles.sort(new StaticFile());
|
||||
return staticFiles;
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException("Failed to list sub files", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
|
|
@ -5,13 +5,9 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||
|
@ -26,9 +22,8 @@ import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
|||
@Slf4j
|
||||
public class HaloUtils {
|
||||
|
||||
private static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
|
||||
|
||||
public static final String URL_SEPARATOR = "/";
|
||||
private static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
|
||||
|
||||
@NonNull
|
||||
public static String ensureBoth(@NonNull String string, @NonNull String bothfix) {
|
||||
|
|
Loading…
Reference in New Issue