mirror of https://github.com/halo-dev/halo
chore: remove deprecated code. (#1334)
parent
359c01c361
commit
9ba9dc40cc
|
@ -18,9 +18,6 @@ checkstyle {
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
// maven {
|
|
||||||
// url "https://maven.aliyun.com/nexus/content/groups/public"
|
|
||||||
// }
|
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url 'https://repo.spring.io/milestone' }
|
maven { url 'https://repo.spring.io/milestone' }
|
||||||
jcenter()
|
jcenter()
|
||||||
|
@ -99,13 +96,11 @@ ext {
|
||||||
annotationsVersion = "3.0.1u2"
|
annotationsVersion = "3.0.1u2"
|
||||||
zxingVersion = "3.4.0"
|
zxingVersion = "3.4.0"
|
||||||
huaweiObsVersion = "3.19.7"
|
huaweiObsVersion = "3.19.7"
|
||||||
githubApiVersion = "1.84"
|
|
||||||
templateInheritanceVersion = "0.4.RELEASE"
|
templateInheritanceVersion = "0.4.RELEASE"
|
||||||
jsoupVersion = "1.13.1"
|
jsoupVersion = "1.13.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.kohsuke:github-api:$githubApiVersion"
|
|
||||||
implementation "org.springframework.boot:spring-boot-starter-actuator"
|
implementation "org.springframework.boot:spring-boot-starter-actuator"
|
||||||
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
|
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
|
||||||
implementation "org.springframework.boot:spring-boot-starter-web"
|
implementation "org.springframework.boot:spring-boot-starter-web"
|
||||||
|
|
|
@ -16,7 +16,6 @@ import run.halo.app.annotation.DisableOnCondition;
|
||||||
import run.halo.app.cache.lock.CacheLock;
|
import run.halo.app.cache.lock.CacheLock;
|
||||||
import run.halo.app.model.dto.EnvironmentDTO;
|
import run.halo.app.model.dto.EnvironmentDTO;
|
||||||
import run.halo.app.model.dto.LoginPreCheckDTO;
|
import run.halo.app.model.dto.LoginPreCheckDTO;
|
||||||
import run.halo.app.model.dto.StatisticDTO;
|
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
import run.halo.app.model.enums.MFAType;
|
import run.halo.app.model.enums.MFAType;
|
||||||
import run.halo.app.model.params.LoginParam;
|
import run.halo.app.model.params.LoginParam;
|
||||||
|
@ -100,13 +99,6 @@ public class AdminController {
|
||||||
return adminService.refreshToken(refreshToken);
|
return adminService.refreshToken(refreshToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("counts")
|
|
||||||
@ApiOperation("Gets count info")
|
|
||||||
@Deprecated
|
|
||||||
public StatisticDTO getCount() {
|
|
||||||
return adminService.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("environments")
|
@GetMapping("environments")
|
||||||
@ApiOperation("Gets environments info")
|
@ApiOperation("Gets environments info")
|
||||||
public EnvironmentDTO getEnvironments() {
|
public EnvironmentDTO getEnvironments() {
|
||||||
|
|
|
@ -190,43 +190,6 @@ public class ThemeController {
|
||||||
return themeService.fetch(uri);
|
return themeService.fetch(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = {"fetchingBranches", "/fetching/git/branches"})
|
|
||||||
@ApiOperation("Fetches all branches")
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
public List<ThemeProperty> fetchBranches(@RequestParam("uri") String uri) {
|
|
||||||
return themeService.fetchBranches(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("fetchingReleases")
|
|
||||||
@ApiOperation("Fetches all releases")
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
public List<ThemeProperty> fetchReleases(@RequestParam("uri") String uri) {
|
|
||||||
return themeService.fetchReleases(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("fetchingRelease")
|
|
||||||
@ApiOperation("Fetches a specific release")
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
public ThemeProperty fetchRelease(@RequestParam("uri") String uri,
|
|
||||||
@RequestParam("tag") String tagName) {
|
|
||||||
return themeService.fetchRelease(uri, tagName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("fetchBranch")
|
|
||||||
@ApiOperation("Fetch specific branch")
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
public ThemeProperty fetchBranch(@RequestParam("uri") String uri,
|
|
||||||
@RequestParam("branch") String branchName) {
|
|
||||||
return themeService.fetchBranch(uri, branchName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("fetchLatestRelease")
|
|
||||||
@ApiOperation("Fetch latest release")
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
public ThemeProperty fetchLatestRelease(@RequestParam("uri") String uri) {
|
|
||||||
return themeService.fetchLatestRelease(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("fetching/{themeId:.+}")
|
@PutMapping("fetching/{themeId:.+}")
|
||||||
@ApiOperation("Upgrades theme from remote")
|
@ApiOperation("Upgrades theme from remote")
|
||||||
public ThemeProperty updateThemeByFetching(@PathVariable("themeId") String themeId) {
|
public ThemeProperty updateThemeByFetching(@PathVariable("themeId") String themeId) {
|
||||||
|
|
|
@ -18,9 +18,6 @@ public class StatisticDTO {
|
||||||
|
|
||||||
private Long categoryCount;
|
private Long categoryCount;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private Long attachmentCount;
|
|
||||||
|
|
||||||
private Long tagCount;
|
private Long tagCount;
|
||||||
|
|
||||||
private Long journalCount;
|
private Long journalCount;
|
||||||
|
|
|
@ -3,7 +3,6 @@ package run.halo.app.service;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import run.halo.app.model.dto.EnvironmentDTO;
|
import run.halo.app.model.dto.EnvironmentDTO;
|
||||||
import run.halo.app.model.dto.LoginPreCheckDTO;
|
import run.halo.app.model.dto.LoginPreCheckDTO;
|
||||||
import run.halo.app.model.dto.StatisticDTO;
|
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
import run.halo.app.model.params.LoginParam;
|
import run.halo.app.model.params.LoginParam;
|
||||||
import run.halo.app.model.params.ResetPasswordParam;
|
import run.halo.app.model.params.ResetPasswordParam;
|
||||||
|
@ -64,15 +63,6 @@ public interface AdminService {
|
||||||
*/
|
*/
|
||||||
void resetPasswordByCode(@NonNull ResetPasswordParam param);
|
void resetPasswordByCode(@NonNull ResetPasswordParam param);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get system counts.
|
|
||||||
*
|
|
||||||
* @return count dto
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated
|
|
||||||
StatisticDTO getCount();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get system environments
|
* Get system environments
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package run.halo.app.service;
|
package run.halo.app.service;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -19,19 +18,6 @@ import run.halo.app.model.support.ThemeFile;
|
||||||
*/
|
*/
|
||||||
public interface ThemeService {
|
public interface ThemeService {
|
||||||
|
|
||||||
/**
|
|
||||||
* Theme property file name.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String THEME_PROPERTY_FILE_NAME = "theme.yaml";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Theme property file name.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String[] THEME_PROPERTY_FILE_NAMES = {"theme.yaml", "theme.yml"};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration file name.
|
* Configuration file name.
|
||||||
*/
|
*/
|
||||||
|
@ -42,34 +28,11 @@ public interface ThemeService {
|
||||||
*/
|
*/
|
||||||
String[] CAN_EDIT_SUFFIX = {".ftl", ".css", ".js", ".yaml", ".yml", ".properties"};
|
String[] CAN_EDIT_SUFFIX = {".ftl", ".css", ".js", ".yaml", ".yml", ".properties"};
|
||||||
|
|
||||||
/**
|
|
||||||
* These file names cannot be displayed.
|
|
||||||
*/
|
|
||||||
String[] FILTER_FILES =
|
|
||||||
{".git", ".DS_Store", "theme.yaml", "theme.yml", "settings.yaml", "settings.yml"};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Theme folder location.
|
* Theme folder location.
|
||||||
*/
|
*/
|
||||||
String THEME_FOLDER = "templates/themes";
|
String THEME_FOLDER = "templates/themes";
|
||||||
|
|
||||||
/**
|
|
||||||
* Theme screenshots name.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String THEME_SCREENSHOTS_NAME = "screenshot";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render template.
|
|
||||||
*/
|
|
||||||
String RENDER_TEMPLATE = "themes/%s/%s";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render template with suffix.
|
|
||||||
*/
|
|
||||||
String RENDER_TEMPLATE_SUFFIX = "themes/%s/%s.ftl";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Theme cache key.
|
* Theme cache key.
|
||||||
*/
|
*/
|
||||||
|
@ -85,26 +48,6 @@ public interface ThemeService {
|
||||||
*/
|
*/
|
||||||
String CUSTOM_POST_PREFIX = "post_";
|
String CUSTOM_POST_PREFIX = "post_";
|
||||||
|
|
||||||
/**
|
|
||||||
* Theme provider remote name.
|
|
||||||
*/
|
|
||||||
String THEME_PROVIDER_REMOTE_NAME = "origin";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default remote branch name.
|
|
||||||
*/
|
|
||||||
String DEFAULT_REMOTE_BRANCH = "master";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Key to access the zip file url which is in the http response
|
|
||||||
*/
|
|
||||||
String ZIP_FILE_KEY = "zipball_url";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Key to access the tag name which is in the http response
|
|
||||||
*/
|
|
||||||
String TAG_KEY = "tag_name";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get theme property by theme id.
|
* Get theme property by theme id.
|
||||||
*
|
*
|
||||||
|
@ -140,16 +83,6 @@ public interface ThemeService {
|
||||||
@NonNull
|
@NonNull
|
||||||
List<ThemeFile> listThemeFolderBy(@NonNull String themeId);
|
List<ThemeFile> listThemeFolderBy(@NonNull String themeId);
|
||||||
|
|
||||||
/**
|
|
||||||
* Lists a set of custom template, such as sheet_xxx.ftl, and xxx will be template name
|
|
||||||
*
|
|
||||||
* @param themeId theme id must not be blank
|
|
||||||
* @return a set of templates
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@NonNull
|
|
||||||
List<String> listCustomTemplates(@NonNull String themeId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists a set of custom template, such as sheet_xxx.ftl/post_xxx.ftl, and xxx will be
|
* Lists a set of custom template, such as sheet_xxx.ftl/post_xxx.ftl, and xxx will be
|
||||||
* template name
|
* template name
|
||||||
|
@ -296,17 +229,6 @@ public interface ThemeService {
|
||||||
@NonNull
|
@NonNull
|
||||||
ThemeProperty upload(@NonNull MultipartFile file);
|
ThemeProperty upload(@NonNull MultipartFile file);
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new theme.
|
|
||||||
*
|
|
||||||
* @param themeTmpPath theme temporary path must not be null
|
|
||||||
* @return theme property
|
|
||||||
* @throws IOException IOException
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated
|
|
||||||
ThemeProperty add(@NonNull Path themeTmpPath) throws IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a new theme.
|
* Fetches a new theme.
|
||||||
*
|
*
|
||||||
|
@ -316,58 +238,6 @@ public interface ThemeService {
|
||||||
@NonNull
|
@NonNull
|
||||||
ThemeProperty fetch(@NonNull String uri);
|
ThemeProperty fetch(@NonNull String uri);
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches the latest release
|
|
||||||
*
|
|
||||||
* @param uri theme remote uri must not be null
|
|
||||||
* @return theme property
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
ThemeProperty fetchLatestRelease(@NonNull String uri);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches all the branches info
|
|
||||||
*
|
|
||||||
* @param uri theme remote uri must not be null
|
|
||||||
* @return list of theme properties
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
List<ThemeProperty> fetchBranches(@NonNull String uri);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches all the release info
|
|
||||||
*
|
|
||||||
* @param uri theme remote uri must not be null
|
|
||||||
* @return list of theme properties
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
List<ThemeProperty> fetchReleases(@NonNull String uri);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches a specific release
|
|
||||||
*
|
|
||||||
* @param uri theme remote uri must not be null
|
|
||||||
* @param tagName release tag name must not be null
|
|
||||||
* @return theme property
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
ThemeProperty fetchRelease(@NonNull String uri, @NonNull String tagName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches a specific branch (clone)
|
|
||||||
*
|
|
||||||
* @param uri theme remote uri must not be null
|
|
||||||
* @param branchName wanted branch must not be null
|
|
||||||
* @return theme property
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
ThemeProperty fetchBranch(@NonNull String uri, @NonNull String branchName);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads themes
|
* Reloads themes
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -16,7 +16,6 @@ import run.halo.app.service.base.CrudService;
|
||||||
*/
|
*/
|
||||||
public interface ThemeSettingService extends CrudService<ThemeSetting, Integer> {
|
public interface ThemeSettingService extends CrudService<ThemeSetting, Integer> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves theme setting.
|
* Saves theme setting.
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,14 +28,6 @@ import run.halo.app.model.vo.CommentWithHasChildrenVO;
|
||||||
public interface BaseCommentService<COMMENT extends BaseComment>
|
public interface BaseCommentService<COMMENT extends BaseComment>
|
||||||
extends CrudService<COMMENT, Long> {
|
extends CrudService<COMMENT, Long> {
|
||||||
|
|
||||||
/**
|
|
||||||
* %d: parent commentator id
|
|
||||||
* %s: parent commentator author name
|
|
||||||
* %s: comment content
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String COMMENT_TEMPLATE = "<a href='#comment-id-%d'>@%s</a> %s";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists comments by post id.
|
* Lists comments by post id.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
import run.halo.app.cache.AbstractStringCacheStore;
|
import run.halo.app.cache.AbstractStringCacheStore;
|
||||||
import run.halo.app.config.properties.HaloProperties;
|
import run.halo.app.config.properties.HaloProperties;
|
||||||
import run.halo.app.event.logger.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
|
@ -30,12 +29,9 @@ import run.halo.app.exception.ServiceException;
|
||||||
import run.halo.app.mail.MailService;
|
import run.halo.app.mail.MailService;
|
||||||
import run.halo.app.model.dto.EnvironmentDTO;
|
import run.halo.app.model.dto.EnvironmentDTO;
|
||||||
import run.halo.app.model.dto.LoginPreCheckDTO;
|
import run.halo.app.model.dto.LoginPreCheckDTO;
|
||||||
import run.halo.app.model.dto.StatisticDTO;
|
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
import run.halo.app.model.enums.CommentStatus;
|
|
||||||
import run.halo.app.model.enums.LogType;
|
import run.halo.app.model.enums.LogType;
|
||||||
import run.halo.app.model.enums.MFAType;
|
import run.halo.app.model.enums.MFAType;
|
||||||
import run.halo.app.model.enums.PostStatus;
|
|
||||||
import run.halo.app.model.params.LoginParam;
|
import run.halo.app.model.params.LoginParam;
|
||||||
import run.halo.app.model.params.ResetPasswordParam;
|
import run.halo.app.model.params.ResetPasswordParam;
|
||||||
import run.halo.app.model.properties.EmailProperties;
|
import run.halo.app.model.properties.EmailProperties;
|
||||||
|
@ -45,14 +41,7 @@ import run.halo.app.security.context.SecurityContextHolder;
|
||||||
import run.halo.app.security.token.AuthToken;
|
import run.halo.app.security.token.AuthToken;
|
||||||
import run.halo.app.security.util.SecurityUtils;
|
import run.halo.app.security.util.SecurityUtils;
|
||||||
import run.halo.app.service.AdminService;
|
import run.halo.app.service.AdminService;
|
||||||
import run.halo.app.service.AttachmentService;
|
|
||||||
import run.halo.app.service.JournalCommentService;
|
|
||||||
import run.halo.app.service.LinkService;
|
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.PostCommentService;
|
|
||||||
import run.halo.app.service.PostService;
|
|
||||||
import run.halo.app.service.SheetCommentService;
|
|
||||||
import run.halo.app.service.SheetService;
|
|
||||||
import run.halo.app.service.UserService;
|
import run.halo.app.service.UserService;
|
||||||
import run.halo.app.utils.HaloUtils;
|
import run.halo.app.utils.HaloUtils;
|
||||||
import run.halo.app.utils.TwoFactorAuthUtils;
|
import run.halo.app.utils.TwoFactorAuthUtils;
|
||||||
|
@ -68,60 +57,29 @@ import run.halo.app.utils.TwoFactorAuthUtils;
|
||||||
@Service
|
@Service
|
||||||
public class AdminServiceImpl implements AdminService {
|
public class AdminServiceImpl implements AdminService {
|
||||||
|
|
||||||
private final PostService postService;
|
|
||||||
|
|
||||||
private final SheetService sheetService;
|
|
||||||
|
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
|
|
||||||
private final PostCommentService postCommentService;
|
|
||||||
|
|
||||||
private final SheetCommentService sheetCommentService;
|
|
||||||
|
|
||||||
private final JournalCommentService journalCommentService;
|
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
private final LinkService linkService;
|
|
||||||
|
|
||||||
private final MailService mailService;
|
private final MailService mailService;
|
||||||
|
|
||||||
private final AbstractStringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
private final RestTemplate restTemplate;
|
|
||||||
|
|
||||||
private final HaloProperties haloProperties;
|
private final HaloProperties haloProperties;
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
public AdminServiceImpl(PostService postService,
|
public AdminServiceImpl(
|
||||||
SheetService sheetService,
|
|
||||||
AttachmentService attachmentService,
|
|
||||||
PostCommentService postCommentService,
|
|
||||||
SheetCommentService sheetCommentService,
|
|
||||||
JournalCommentService journalCommentService,
|
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
LinkService linkService,
|
|
||||||
MailService mailService,
|
MailService mailService,
|
||||||
AbstractStringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
RestTemplate restTemplate,
|
|
||||||
HaloProperties haloProperties,
|
HaloProperties haloProperties,
|
||||||
ApplicationEventPublisher eventPublisher) {
|
ApplicationEventPublisher eventPublisher) {
|
||||||
this.postService = postService;
|
|
||||||
this.sheetService = sheetService;
|
|
||||||
this.attachmentService = attachmentService;
|
|
||||||
this.postCommentService = postCommentService;
|
|
||||||
this.sheetCommentService = sheetCommentService;
|
|
||||||
this.journalCommentService = journalCommentService;
|
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.linkService = linkService;
|
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
this.restTemplate = restTemplate;
|
|
||||||
this.haloProperties = haloProperties;
|
this.haloProperties = haloProperties;
|
||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
@ -290,48 +248,21 @@ public class AdminServiceImpl implements AdminService {
|
||||||
cacheStore.delete("code");
|
cacheStore.delete("code");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public StatisticDTO getCount() {
|
|
||||||
StatisticDTO statisticDTO = new StatisticDTO();
|
|
||||||
statisticDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED)
|
|
||||||
+ sheetService.countByStatus(PostStatus.PUBLISHED));
|
|
||||||
statisticDTO.setAttachmentCount(attachmentService.count());
|
|
||||||
|
|
||||||
// Handle comment count
|
|
||||||
long postCommentCount = postCommentService.countByStatus(CommentStatus.PUBLISHED);
|
|
||||||
long sheetCommentCount = sheetCommentService.countByStatus(CommentStatus.PUBLISHED);
|
|
||||||
long journalCommentCount = journalCommentService.countByStatus(CommentStatus.PUBLISHED);
|
|
||||||
|
|
||||||
statisticDTO.setCommentCount(postCommentCount + sheetCommentCount + journalCommentCount);
|
|
||||||
|
|
||||||
long birthday = optionService.getBirthday();
|
|
||||||
long days = (System.currentTimeMillis() - birthday) / (1000 * 24 * 3600);
|
|
||||||
statisticDTO.setEstablishDays(days);
|
|
||||||
statisticDTO.setBirthday(birthday);
|
|
||||||
|
|
||||||
statisticDTO.setLinkCount(linkService.count());
|
|
||||||
|
|
||||||
statisticDTO.setVisitCount(postService.countVisit() + sheetService.countVisit());
|
|
||||||
statisticDTO.setLikeCount(postService.countLike() + sheetService.countLike());
|
|
||||||
return statisticDTO;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public EnvironmentDTO getEnvironments() {
|
public EnvironmentDTO getEnvironments() {
|
||||||
EnvironmentDTO environmentDTO = new EnvironmentDTO();
|
EnvironmentDTO environmentDto = new EnvironmentDTO();
|
||||||
|
|
||||||
// Get application start time.
|
// Get application start time.
|
||||||
environmentDTO.setStartTime(ManagementFactory.getRuntimeMXBean().getStartTime());
|
environmentDto.setStartTime(ManagementFactory.getRuntimeMXBean().getStartTime());
|
||||||
|
|
||||||
environmentDTO.setDatabase(DATABASE_PRODUCT_NAME);
|
environmentDto.setDatabase(DATABASE_PRODUCT_NAME);
|
||||||
|
|
||||||
environmentDTO.setVersion(HaloConst.HALO_VERSION);
|
environmentDto.setVersion(HaloConst.HALO_VERSION);
|
||||||
|
|
||||||
environmentDTO.setMode(haloProperties.getMode());
|
environmentDto.setMode(haloProperties.getMode());
|
||||||
|
|
||||||
return environmentDTO;
|
return environmentDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -398,7 +329,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
|
|
||||||
List<String> linesArray = new ArrayList<>();
|
List<String> linesArray = new ArrayList<>();
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
|
|
|
@ -6,13 +6,11 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.exception.AlreadyExistsException;
|
|
||||||
import run.halo.app.model.dto.MenuDTO;
|
import run.halo.app.model.dto.MenuDTO;
|
||||||
import run.halo.app.model.entity.Menu;
|
import run.halo.app.model.entity.Menu;
|
||||||
import run.halo.app.model.params.MenuParam;
|
import run.halo.app.model.params.MenuParam;
|
||||||
|
@ -40,14 +38,16 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull List<MenuDTO> listDtos(@NonNull Sort sort) {
|
public @NonNull
|
||||||
|
List<MenuDTO> listDtos(@NonNull Sort sort) {
|
||||||
Assert.notNull(sort, "Sort info must not be null");
|
Assert.notNull(sort, "Sort info must not be null");
|
||||||
|
|
||||||
return convertTo(listAll(sort));
|
return convertTo(listAll(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull List<MenuTeamVO> listTeamVos(@NonNull Sort sort) {
|
public @NonNull
|
||||||
|
List<MenuTeamVO> listTeamVos(@NonNull Sort sort) {
|
||||||
Assert.notNull(sort, "Sort info must not be null");
|
Assert.notNull(sort, "Sort info must not be null");
|
||||||
|
|
||||||
// List all menus
|
// List all menus
|
||||||
|
@ -101,7 +101,8 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Menu createBy(@NonNull MenuParam menuParam) {
|
public @NonNull
|
||||||
|
Menu createBy(@NonNull MenuParam menuParam) {
|
||||||
Assert.notNull(menuParam, "Menu param must not be null");
|
Assert.notNull(menuParam, "Menu param must not be null");
|
||||||
|
|
||||||
// Create an return
|
// Create an return
|
||||||
|
@ -141,12 +142,14 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Menu create(@NonNull Menu menu) {
|
public @NonNull
|
||||||
|
Menu create(@NonNull Menu menu) {
|
||||||
return super.create(menu);
|
return super.create(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Menu update(@NonNull Menu menu) {
|
public @NonNull
|
||||||
|
Menu update(@NonNull Menu menu) {
|
||||||
return super.update(menu);
|
return super.update(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,23 +218,4 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
|
||||||
.map(menu -> (MenuDTO) new MenuDTO().convertFrom(menu))
|
.map(menu -> (MenuDTO) new MenuDTO().convertFrom(menu))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private void nameMustNotExist(@NonNull Menu menu) {
|
|
||||||
Assert.notNull(menu, "Menu must not be null");
|
|
||||||
|
|
||||||
boolean exist = false;
|
|
||||||
|
|
||||||
if (ServiceUtils.isEmptyId(menu.getId())) {
|
|
||||||
// Create action
|
|
||||||
exist = menuRepository.existsByName(menu.getName());
|
|
||||||
} else {
|
|
||||||
// Update action
|
|
||||||
exist = menuRepository.existsByIdNotAndName(menu.getId(), menu.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exist) {
|
|
||||||
throw new AlreadyExistsException("菜单 " + menu.getName() + " 已存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -620,17 +620,5 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
|
||||||
|
|
||||||
return new OptionSimpleDTO().convertFrom(option);
|
return new OptionSimpleDTO().convertFrom(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private void cleanCache() {
|
|
||||||
cacheStore.delete(OPTIONS_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private void publishOptionUpdatedEvent() {
|
|
||||||
flush();
|
|
||||||
cleanCache();
|
|
||||||
eventPublisher.publishEvent(new OptionUpdatedEvent(this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,42 +78,42 @@ public class StatisticServiceImpl implements StatisticService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StatisticDTO getStatistic() {
|
public StatisticDTO getStatistic() {
|
||||||
StatisticDTO statisticDTO = new StatisticDTO();
|
StatisticDTO statisticDto = new StatisticDTO();
|
||||||
statisticDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED));
|
statisticDto.setPostCount(postService.countByStatus(PostStatus.PUBLISHED));
|
||||||
|
|
||||||
// Handle comment count
|
// Handle comment count
|
||||||
long postCommentCount = postCommentService.countByStatus(CommentStatus.PUBLISHED);
|
long postCommentCount = postCommentService.countByStatus(CommentStatus.PUBLISHED);
|
||||||
long sheetCommentCount = sheetCommentService.countByStatus(CommentStatus.PUBLISHED);
|
long sheetCommentCount = sheetCommentService.countByStatus(CommentStatus.PUBLISHED);
|
||||||
long journalCommentCount = journalCommentService.countByStatus(CommentStatus.PUBLISHED);
|
long journalCommentCount = journalCommentService.countByStatus(CommentStatus.PUBLISHED);
|
||||||
|
|
||||||
statisticDTO.setCommentCount(postCommentCount + sheetCommentCount + journalCommentCount);
|
statisticDto.setCommentCount(postCommentCount + sheetCommentCount + journalCommentCount);
|
||||||
statisticDTO.setTagCount(tagService.count());
|
statisticDto.setTagCount(tagService.count());
|
||||||
statisticDTO.setCategoryCount(categoryService.count());
|
statisticDto.setCategoryCount(categoryService.count());
|
||||||
statisticDTO.setJournalCount(journalService.count());
|
statisticDto.setJournalCount(journalService.count());
|
||||||
|
|
||||||
long birthday = optionService.getBirthday();
|
long birthday = optionService.getBirthday();
|
||||||
long days = (System.currentTimeMillis() - birthday) / (1000 * 24 * 3600);
|
long days = (System.currentTimeMillis() - birthday) / (1000 * 24 * 3600);
|
||||||
statisticDTO.setEstablishDays(days);
|
statisticDto.setEstablishDays(days);
|
||||||
statisticDTO.setBirthday(birthday);
|
statisticDto.setBirthday(birthday);
|
||||||
|
|
||||||
statisticDTO.setLinkCount(linkService.count());
|
statisticDto.setLinkCount(linkService.count());
|
||||||
statisticDTO.setVisitCount(postService.countVisit() + sheetService.countVisit());
|
statisticDto.setVisitCount(postService.countVisit() + sheetService.countVisit());
|
||||||
statisticDTO.setLikeCount(postService.countLike() + sheetService.countLike());
|
statisticDto.setLikeCount(postService.countLike() + sheetService.countLike());
|
||||||
return statisticDTO;
|
return statisticDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StatisticWithUserDTO getStatisticWithUser() {
|
public StatisticWithUserDTO getStatisticWithUser() {
|
||||||
|
|
||||||
StatisticDTO statisticDTO = getStatistic();
|
StatisticDTO statisticDto = getStatistic();
|
||||||
|
|
||||||
StatisticWithUserDTO statisticWithUserDTO = new StatisticWithUserDTO();
|
StatisticWithUserDTO statisticWithUserDto = new StatisticWithUserDTO();
|
||||||
statisticWithUserDTO.convertFrom(statisticDTO);
|
statisticWithUserDto.convertFrom(statisticDto);
|
||||||
|
|
||||||
User user =
|
User user =
|
||||||
userService.getCurrentUser().orElseThrow(() -> new ServiceException("未查询到博主信息"));
|
userService.getCurrentUser().orElseThrow(() -> new ServiceException("未查询到博主信息"));
|
||||||
statisticWithUserDTO.setUser(new UserDTO().convertFrom(user));
|
statisticWithUserDto.setUser(new UserDTO().convertFrom(user));
|
||||||
|
|
||||||
return statisticWithUserDTO;
|
return statisticWithUserDto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,17 @@
|
||||||
package run.halo.app.service.impl;
|
package run.halo.app.service.impl;
|
||||||
|
|
||||||
import static run.halo.app.utils.FileUtils.copyFolder;
|
|
||||||
import static run.halo.app.utils.FileUtils.deleteFolderQuietly;
|
|
||||||
import static run.halo.app.utils.VersionUtil.compareVersion;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
@ -30,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import run.halo.app.config.properties.HaloProperties;
|
import run.halo.app.config.properties.HaloProperties;
|
||||||
import run.halo.app.event.theme.ThemeActivatedEvent;
|
import run.halo.app.event.theme.ThemeActivatedEvent;
|
||||||
import run.halo.app.event.theme.ThemeUpdatedEvent;
|
import run.halo.app.event.theme.ThemeUpdatedEvent;
|
||||||
import run.halo.app.exception.AlreadyExistsException;
|
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.exception.ForbiddenException;
|
import run.halo.app.exception.ForbiddenException;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
|
@ -55,9 +47,6 @@ import run.halo.app.theme.ThemeFileScanner;
|
||||||
import run.halo.app.theme.ThemePropertyScanner;
|
import run.halo.app.theme.ThemePropertyScanner;
|
||||||
import run.halo.app.theme.ZipThemeFetcher;
|
import run.halo.app.theme.ZipThemeFetcher;
|
||||||
import run.halo.app.utils.FileUtils;
|
import run.halo.app.utils.FileUtils;
|
||||||
import run.halo.app.utils.GitUtils;
|
|
||||||
import run.halo.app.utils.GithubUtils;
|
|
||||||
import run.halo.app.utils.HaloUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Theme service implementation.
|
* Theme service implementation.
|
||||||
|
@ -134,12 +123,6 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
.orElse(Collections.emptyList());
|
.orElse(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public List<String> listCustomTemplates(@NonNull String themeId) {
|
|
||||||
return listCustomTemplates(themeId, CUSTOM_SHEET_PREFIX);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<String> listCustomTemplates(@NonNull String themeId, @NonNull String prefix) {
|
public List<String> listCustomTemplates(@NonNull String themeId, @NonNull String prefix) {
|
||||||
|
@ -365,54 +348,6 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
return this.themeRepository.attemptToAdd(newThemeProperty);
|
return this.themeRepository.attemptToAdd(newThemeProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
@Deprecated
|
|
||||||
public ThemeProperty add(@NonNull Path themeTmpPath) throws IOException {
|
|
||||||
Assert.notNull(themeTmpPath, "Theme temporary path must not be null");
|
|
||||||
Assert.isTrue(Files.isDirectory(themeTmpPath), "Theme temporary path must be a directory");
|
|
||||||
|
|
||||||
if (log.isTraceEnabled()) {
|
|
||||||
log.trace("Children path of [{}]:", themeTmpPath);
|
|
||||||
|
|
||||||
try (Stream<Path> pathStream = Files.list(themeTmpPath)) {
|
|
||||||
pathStream.forEach(path -> log.trace(path.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check property config
|
|
||||||
ThemeProperty tmpThemeProperty = getProperty(themeTmpPath);
|
|
||||||
|
|
||||||
// Check theme existence
|
|
||||||
boolean isExist = getThemes().stream()
|
|
||||||
.anyMatch(themeProperty -> themeProperty.getId()
|
|
||||||
.equalsIgnoreCase(tmpThemeProperty.getId()));
|
|
||||||
|
|
||||||
if (isExist) {
|
|
||||||
throw new AlreadyExistsException("当前安装的主题已存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not support current halo version.
|
|
||||||
if (StringUtils.isNotEmpty(tmpThemeProperty.getRequire())
|
|
||||||
&& !compareVersion(HaloConst.HALO_VERSION, tmpThemeProperty.getRequire())) {
|
|
||||||
throw new ThemeNotSupportException(
|
|
||||||
"当前主题仅支持 Halo " + tmpThemeProperty.getRequire() + " 以上的版本");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the temporary path to current theme folder
|
|
||||||
Path targetThemePath = themeWorkDir.resolve(tmpThemeProperty.getId());
|
|
||||||
copyFolder(themeTmpPath, targetThemePath);
|
|
||||||
|
|
||||||
// Get property again
|
|
||||||
ThemeProperty property = getProperty(targetThemePath);
|
|
||||||
|
|
||||||
// Clear theme cache
|
|
||||||
this.eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
|
||||||
|
|
||||||
// Delete cache
|
|
||||||
return property;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ThemeProperty fetch(@NonNull String uri) {
|
public ThemeProperty fetch(@NonNull String uri) {
|
||||||
Assert.hasText(uri, "Theme remote uri must not be blank");
|
Assert.hasText(uri, "Theme remote uri must not be blank");
|
||||||
|
@ -421,114 +356,6 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
return this.themeRepository.attemptToAdd(themeProperty);
|
return this.themeRepository.attemptToAdd(themeProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ThemeProperty fetchBranch(String uri, String branchName) {
|
|
||||||
Assert.hasText(uri, "Theme remote uri must not be blank");
|
|
||||||
|
|
||||||
Path tmpPath = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Create temp path
|
|
||||||
tmpPath = FileUtils.createTempDirectory();
|
|
||||||
// Create temp path
|
|
||||||
Path themeTmpPath = tmpPath.resolve(HaloUtils.randomUUIDWithoutDash());
|
|
||||||
|
|
||||||
String repoUrl = StringUtils.appendIfMissingIgnoreCase(uri, ".git", ".git");
|
|
||||||
GitUtils.cloneFromGit(repoUrl, themeTmpPath, branchName);
|
|
||||||
|
|
||||||
return add(themeTmpPath);
|
|
||||||
} catch (IOException | GitAPIException e) {
|
|
||||||
throw new ServiceException("主题拉取失败 " + uri + "。" + e.getMessage(), e);
|
|
||||||
} finally {
|
|
||||||
deleteFolderQuietly(tmpPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ThemeProperty fetchRelease(@NonNull String uri, @NonNull String tagName) {
|
|
||||||
Assert.hasText(uri, "Theme remote uri must not be blank");
|
|
||||||
Assert.hasText(tagName, "Theme remote tagName must not be blank");
|
|
||||||
|
|
||||||
Path tmpPath = null;
|
|
||||||
try {
|
|
||||||
tmpPath = FileUtils.createTempDirectory();
|
|
||||||
|
|
||||||
Path themeTmpPath = tmpPath.resolve(HaloUtils.randomUUIDWithoutDash());
|
|
||||||
|
|
||||||
Map<String, Object> releaseInfo = GithubUtils.getRelease(uri, tagName);
|
|
||||||
|
|
||||||
if (releaseInfo == null) {
|
|
||||||
throw new ServiceException("主题拉取失败" + uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
String zipUrl = (String) releaseInfo.get(ZIP_FILE_KEY);
|
|
||||||
|
|
||||||
downloadZipAndUnzip(zipUrl, themeTmpPath);
|
|
||||||
|
|
||||||
// find root theme folder
|
|
||||||
Path themeRootPath = getThemeRootPath(themeTmpPath);
|
|
||||||
log.debug("Got theme root path: [{}]", themeRootPath);
|
|
||||||
return add(themeRootPath);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new ServiceException("主题拉取失败 " + uri, e);
|
|
||||||
} finally {
|
|
||||||
deleteFolderQuietly(tmpPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ThemeProperty fetchLatestRelease(@NonNull String uri) {
|
|
||||||
Assert.hasText(uri, "Theme remote uri must not be blank");
|
|
||||||
|
|
||||||
Map<String, Object> releaseInfo = GithubUtils.getLatestRelease(uri);
|
|
||||||
if (releaseInfo == null) {
|
|
||||||
throw new ServiceException("主题拉取失败" + uri);
|
|
||||||
}
|
|
||||||
String zipUrl = (String) releaseInfo.get(ZIP_FILE_KEY);
|
|
||||||
|
|
||||||
final var themeProperty = this.fetcherComposite.fetch(zipUrl);
|
|
||||||
return this.themeRepository.attemptToAdd(themeProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ThemeProperty> fetchBranches(String uri) {
|
|
||||||
Assert.hasText(uri, "Theme remote uri must not be blank");
|
|
||||||
|
|
||||||
String repoUrl = StringUtils.appendIfMissingIgnoreCase(uri, ".git", ".git");
|
|
||||||
List<String> branches = GitUtils.getAllBranchesFromRemote(repoUrl);
|
|
||||||
|
|
||||||
List<ThemeProperty> themeProperties = new ArrayList<>();
|
|
||||||
|
|
||||||
branches.forEach(branch -> {
|
|
||||||
ThemeProperty themeProperty = new ThemeProperty();
|
|
||||||
themeProperty.setBranch(branch);
|
|
||||||
themeProperties.add(themeProperty);
|
|
||||||
});
|
|
||||||
|
|
||||||
return themeProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ThemeProperty> fetchReleases(@NonNull String uri) {
|
|
||||||
Assert.hasText(uri, "Theme remote uri must not be blank");
|
|
||||||
|
|
||||||
List<String> releases = GithubUtils.getReleases(uri);
|
|
||||||
|
|
||||||
List<ThemeProperty> themeProperties = new ArrayList<>();
|
|
||||||
|
|
||||||
if (releases == null) {
|
|
||||||
throw new ServiceException("主题拉取失败!可能原因:当前服务器无法链接到对方服务器或连接超时。");
|
|
||||||
}
|
|
||||||
|
|
||||||
releases.forEach(tagName -> {
|
|
||||||
ThemeProperty themeProperty = new ThemeProperty();
|
|
||||||
themeProperty.setBranch(tagName);
|
|
||||||
themeProperties.add(themeProperty);
|
|
||||||
});
|
|
||||||
|
|
||||||
return themeProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
||||||
|
@ -630,21 +457,4 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
.orElseThrow(() -> new ThemePropertyMissingException(themePath + " 没有说明文件")
|
.orElseThrow(() -> new ThemePropertyMissingException(themePath + " 没有说明文件")
|
||||||
.setErrorData(themePath));
|
.setErrorData(themePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get theme root path.
|
|
||||||
*
|
|
||||||
* @param themePath theme folder path
|
|
||||||
* @return real theme root path
|
|
||||||
* @throws IOException IO exception
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
private Path getThemeRootPath(@NonNull Path themePath) throws IOException {
|
|
||||||
return FileUtils.findRootPath(themePath,
|
|
||||||
path -> StringUtils.equalsAny(path.getFileName().toString(),
|
|
||||||
"theme.yaml", "theme.yml"))
|
|
||||||
.orElseThrow(() ->
|
|
||||||
new BadRequestException("无法准确定位到主题根目录,请确认主题目录中包含 theme.yml(theme.yaml)。"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
//package run.halo.app.service.impl;
|
|
||||||
//
|
|
||||||
//import org.springframework.boot.actuate.trace.http.HttpTrace;
|
|
||||||
//import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
|
|
||||||
//import org.springframework.stereotype.Service;
|
|
||||||
//import run.halo.app.service.TraceService;
|
|
||||||
//
|
|
||||||
//import java.util.List;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * TraceService implementation class.
|
|
||||||
// *
|
|
||||||
// * @author johnniang
|
|
||||||
// * @date 2019-06-18
|
|
||||||
// */
|
|
||||||
//@Service
|
|
||||||
//public class TraceServiceImpl implements TraceService {
|
|
||||||
//
|
|
||||||
// private final HttpTraceRepository httpTraceRepository;
|
|
||||||
//
|
|
||||||
// public TraceServiceImpl(HttpTraceRepository httpTraceRepository) {
|
|
||||||
// this.httpTraceRepository = httpTraceRepository;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public List<HttpTrace> listHttpTraces() {
|
|
||||||
// return httpTraceRepository.findAll();
|
|
||||||
// }
|
|
||||||
//}
|
|
|
@ -11,7 +11,6 @@ import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.cache.AbstractStringCacheStore;
|
|
||||||
import run.halo.app.cache.lock.CacheLock;
|
import run.halo.app.cache.lock.CacheLock;
|
||||||
import run.halo.app.event.logger.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.event.user.UserUpdatedEvent;
|
import run.halo.app.event.user.UserUpdatedEvent;
|
||||||
|
@ -41,16 +40,12 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
private final AbstractStringCacheStore stringCacheStore;
|
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
public UserServiceImpl(UserRepository userRepository,
|
public UserServiceImpl(UserRepository userRepository,
|
||||||
AbstractStringCacheStore stringCacheStore,
|
|
||||||
ApplicationEventPublisher eventPublisher) {
|
ApplicationEventPublisher eventPublisher) {
|
||||||
super(userRepository);
|
super(userRepository);
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
this.stringCacheStore = stringCacheStore;
|
|
||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package run.halo.app.utils;
|
package run.halo.app.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -23,7 +21,6 @@ import org.eclipse.jgit.transport.RemoteConfig;
|
||||||
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,24 +35,6 @@ public class GitUtils {
|
||||||
private GitUtils() {
|
private GitUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(since = "1.4.2", forRemoval = true)
|
|
||||||
public static void cloneFromGit(@NonNull String repoUrl, @NonNull Path targetPath,
|
|
||||||
@NonNull String branchName) throws GitAPIException {
|
|
||||||
Assert.hasText(repoUrl, "Repository remote url must not be blank");
|
|
||||||
Assert.notNull(targetPath, "Target path must not be null");
|
|
||||||
|
|
||||||
try (
|
|
||||||
Git ignored = Git.cloneRepository()
|
|
||||||
.setURI(repoUrl)
|
|
||||||
.setDirectory(targetPath.toFile())
|
|
||||||
.setBranchesToClone(Collections.singletonList("refs/heads/" + branchName))
|
|
||||||
.setCloneSubmodules(true)
|
|
||||||
.setBranch("refs/heads/" + branchName)
|
|
||||||
.call()) {
|
|
||||||
// empty block placeholder
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getAllBranchesFromRemote(@NonNull String repoUrl) {
|
public static List<String> getAllBranchesFromRemote(@NonNull String repoUrl) {
|
||||||
List<String> branches = new ArrayList<>();
|
List<String> branches = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,384 +0,0 @@
|
||||||
package run.halo.app.utils;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.kohsuke.github.GHContent;
|
|
||||||
import org.kohsuke.github.GHRelease;
|
|
||||||
import org.kohsuke.github.GHRepository;
|
|
||||||
import org.kohsuke.github.GitHub;
|
|
||||||
import org.kohsuke.github.HttpException;
|
|
||||||
import run.halo.app.service.ThemeService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GithubUtils send request to api.github.com
|
|
||||||
*
|
|
||||||
* @author bigbang019
|
|
||||||
* @date 2020-05-31
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class GithubUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The prefix need to remove
|
|
||||||
*/
|
|
||||||
static final String PREFIX = "https://github.com/";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get latest release
|
|
||||||
*
|
|
||||||
* @param uri repository url must not be null
|
|
||||||
* @return the map object containning tagname and zipfile url
|
|
||||||
*/
|
|
||||||
public static Map<String, Object> getLatestRelease(String uri) {
|
|
||||||
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
|
|
||||||
|
|
||||||
try {
|
|
||||||
GithubLatestRelease githubLatestRelease = new GithubLatestRelease(repoUrl);
|
|
||||||
|
|
||||||
Thread thread = new Thread(githubLatestRelease);
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
thread.join(10 * 1000);
|
|
||||||
|
|
||||||
return githubLatestRelease.result;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Interrupted", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get release information
|
|
||||||
*
|
|
||||||
* @param uri repository url must not be null
|
|
||||||
* @return list of tagname of releases
|
|
||||||
*/
|
|
||||||
public static List<String> getReleases(String uri) {
|
|
||||||
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
|
|
||||||
|
|
||||||
try {
|
|
||||||
GithubReleases githubReleases = new GithubReleases(repoUrl);
|
|
||||||
|
|
||||||
Thread thread = new Thread(githubReleases);
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
thread.join(10 * 1000);
|
|
||||||
|
|
||||||
return githubReleases.result;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Getting releases from github interrupted", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get release information
|
|
||||||
*
|
|
||||||
* @param uri repository url must not be null
|
|
||||||
* @param tagName tag must not be null
|
|
||||||
* @return the map object containning tagname and zipfile url
|
|
||||||
*/
|
|
||||||
public static Map<String, Object> getRelease(String uri, String tagName) {
|
|
||||||
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
|
|
||||||
|
|
||||||
try {
|
|
||||||
GithubRelease githubRelease = new GithubRelease(repoUrl, tagName);
|
|
||||||
|
|
||||||
Thread thread = new Thread(githubRelease);
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
thread.join(10 * 1000);
|
|
||||||
|
|
||||||
return githubRelease.result;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Interrupted", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the content of theme.yaml/theme.yml
|
|
||||||
*
|
|
||||||
* @param uri repository url must not be null
|
|
||||||
* @param branch branch must not be null
|
|
||||||
* @return content of the file
|
|
||||||
*/
|
|
||||||
public static String accessThemeProperty(String uri, String branch) {
|
|
||||||
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
|
|
||||||
|
|
||||||
try {
|
|
||||||
GithubFile githubFile = new GithubFile(repoUrl, branch);
|
|
||||||
|
|
||||||
Thread thread = new Thread(githubFile);
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
thread.join(10 * 1000);
|
|
||||||
|
|
||||||
return githubFile.result;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Interrupted", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class GithubRelease implements Runnable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* should be in format of "username/reponame"
|
|
||||||
*/
|
|
||||||
private final String repoUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* repository tag name
|
|
||||||
*/
|
|
||||||
private final String tagName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The return result is zip url and tag name etc.
|
|
||||||
*/
|
|
||||||
private HashMap<String, Object> result;
|
|
||||||
|
|
||||||
public GithubRelease(String repoUrl, String tagName) {
|
|
||||||
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
|
|
||||||
this.tagName = tagName;
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
GitHub gitHub = GitHub.connectAnonymously();
|
|
||||||
GHRepository ghRepository = gitHub.getRepository(repoUrl);
|
|
||||||
List<GHRelease> ghReleaseList = ghRepository.getReleases();
|
|
||||||
|
|
||||||
if (ghReleaseList.size() == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<GHRelease> res = ghReleaseList.stream()
|
|
||||||
.filter(
|
|
||||||
release -> StringUtils.equalsIgnoreCase(release.getTagName(), tagName))
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
if (res.isPresent()) {
|
|
||||||
GHRelease ghRelease = res.get();
|
|
||||||
|
|
||||||
result = new HashMap<String, Object>() {
|
|
||||||
{
|
|
||||||
put(ThemeService.ZIP_FILE_KEY, ghRelease.getZipballUrl());
|
|
||||||
put(ThemeService.TAG_KEY, ghRelease.getTagName());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (e instanceof HttpException) {
|
|
||||||
int code = ((HttpException) e).getResponseCode();
|
|
||||||
if (code != -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class GithubReleases implements Runnable {
|
|
||||||
|
|
||||||
private final String repoUrl;
|
|
||||||
private List<String> result;
|
|
||||||
|
|
||||||
public GithubReleases(String repoUrl) {
|
|
||||||
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
GitHub gitHub = GitHub.connectAnonymously();
|
|
||||||
GHRepository ghRepository = gitHub.getRepository(repoUrl);
|
|
||||||
List<GHRelease> ghReleaseList = ghRepository.getReleases();
|
|
||||||
|
|
||||||
result = new ArrayList<>();
|
|
||||||
|
|
||||||
for (GHRelease ghRelease : ghReleaseList) {
|
|
||||||
result.add(ghRelease.getTagName());
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (log.isErrorEnabled()) {
|
|
||||||
log.error("Failed to react with github.", e);
|
|
||||||
}
|
|
||||||
if (e instanceof HttpException) {
|
|
||||||
int code = ((HttpException) e).getResponseCode();
|
|
||||||
if (code != -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class GithubLatestRelease implements Runnable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* should be in format of "username/reponame"
|
|
||||||
*/
|
|
||||||
private final String repoUrl;
|
|
||||||
/**
|
|
||||||
* The return result is zip url and tag name etc.
|
|
||||||
*/
|
|
||||||
private HashMap<String, Object> result;
|
|
||||||
|
|
||||||
public GithubLatestRelease(String repoUrl) {
|
|
||||||
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
GitHub gitHub = GitHub.connectAnonymously();
|
|
||||||
GHRepository ghRepository = gitHub.getRepository(repoUrl);
|
|
||||||
List<GHRelease> ghReleaseList = ghRepository.getReleases();
|
|
||||||
|
|
||||||
if (ghReleaseList.size() == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GHRelease ghRelease = ghReleaseList.get(0);
|
|
||||||
|
|
||||||
result = new HashMap<String, Object>() {
|
|
||||||
{
|
|
||||||
put(ThemeService.ZIP_FILE_KEY, ghRelease.getZipballUrl());
|
|
||||||
put(ThemeService.TAG_KEY, ghRelease.getTagName());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (e instanceof HttpException) {
|
|
||||||
int code = ((HttpException) e).getResponseCode();
|
|
||||||
if (code != -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
TimeUnit.SECONDS.sleep(2);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class GithubFile implements Runnable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* should be in format of "username/reponame"
|
|
||||||
*/
|
|
||||||
private final String repoUrl;
|
|
||||||
/**
|
|
||||||
* the branch name
|
|
||||||
*/
|
|
||||||
private final String branch;
|
|
||||||
/**
|
|
||||||
* result is file content
|
|
||||||
*/
|
|
||||||
private String result;
|
|
||||||
|
|
||||||
public GithubFile(String repoUrl, String branch) {
|
|
||||||
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
|
|
||||||
this.branch = branch;
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
GitHub gitHub = GitHub.connectAnonymously();
|
|
||||||
|
|
||||||
GHRepository ghRepository = gitHub.getRepository(repoUrl);
|
|
||||||
|
|
||||||
GHContent ghContent = null;
|
|
||||||
|
|
||||||
for (String themePropertyFile : ThemeService.THEME_PROPERTY_FILE_NAMES) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
ghContent = ghRepository.getFileContent(themePropertyFile, branch);
|
|
||||||
} catch (FileNotFoundException ignored) {
|
|
||||||
// ignore this exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ghContent == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = ghContent.getContent();
|
|
||||||
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (e instanceof HttpException) {
|
|
||||||
int code = ((HttpException) e).getResponseCode();
|
|
||||||
if (code != -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
// ignore this exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -23,7 +23,7 @@ import run.halo.app.security.service.OneTimeTokenService;
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
class OneTimeTokenTest {
|
class OneTimeTokenTest {
|
||||||
|
|
||||||
static final String REQUEST_URI = "/api/admin/counts";
|
static final String REQUEST_URI = "/api/admin/statistics";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
MockMvc mvc;
|
MockMvc mvc;
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
package run.halo.app.utils;
|
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Disabled("Dut to time-consumption")
|
|
||||||
class GithubUtilsTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getLatestReleasesWithValidURL() {
|
|
||||||
Map<String, Object> map =
|
|
||||||
GithubUtils.getLatestRelease("https://github.com/halo-dev/halo-theme-hux");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getLatestReleasesWithInvalidURL() {
|
|
||||||
Map<String, Object> map =
|
|
||||||
GithubUtils.getLatestRelease("https://github.com/halo-dev/halo-theme-hu");
|
|
||||||
assertNull(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void accessThemePropertyWithValidURL() {
|
|
||||||
String content =
|
|
||||||
GithubUtils.accessThemeProperty("https://github.com/halo-dev/halo-theme-hux", "master");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void accessThemePropertyWithInvalidURL() {
|
|
||||||
String content =
|
|
||||||
GithubUtils.accessThemeProperty("https://github.com/halo-dev/halo-theme-hu", "master");
|
|
||||||
assertNull(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getReleasesTest() {
|
|
||||||
List<String> list = GithubUtils.getReleases("https://github.com/halo-dev/halo-theme-hux");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue