diff --git a/build.gradle b/build.gradle index e8952638b5..7e9d72bfe3 100644 --- a/build.gradle +++ b/build.gradle @@ -18,9 +18,6 @@ checkstyle { repositories { mavenLocal() -// maven { -// url "https://maven.aliyun.com/nexus/content/groups/public" -// } mavenCentral() maven { url 'https://repo.spring.io/milestone' } jcenter() @@ -99,13 +96,11 @@ ext { annotationsVersion = "3.0.1u2" zxingVersion = "3.4.0" huaweiObsVersion = "3.19.7" - githubApiVersion = "1.84" templateInheritanceVersion = "0.4.RELEASE" jsoupVersion = "1.13.1" } dependencies { - implementation "org.kohsuke:github-api:$githubApiVersion" implementation "org.springframework.boot:spring-boot-starter-actuator" implementation "org.springframework.boot:spring-boot-starter-data-jpa" implementation "org.springframework.boot:spring-boot-starter-web" diff --git a/src/main/java/run/halo/app/controller/admin/api/AdminController.java b/src/main/java/run/halo/app/controller/admin/api/AdminController.java index 1cdf19ba98..c9d1f48c30 100644 --- a/src/main/java/run/halo/app/controller/admin/api/AdminController.java +++ b/src/main/java/run/halo/app/controller/admin/api/AdminController.java @@ -16,7 +16,6 @@ import run.halo.app.cache.lock.CacheLock; import run.halo.app.model.dto.EnvironmentDTO; 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.enums.MFAType; import run.halo.app.model.params.LoginParam; @@ -100,13 +99,6 @@ public AuthToken refresh(@PathVariable("refreshToken") String refreshToken) { return adminService.refreshToken(refreshToken); } - @GetMapping("counts") - @ApiOperation("Gets count info") - @Deprecated - public StatisticDTO getCount() { - return adminService.getCount(); - } - @GetMapping("environments") @ApiOperation("Gets environments info") public EnvironmentDTO getEnvironments() { diff --git a/src/main/java/run/halo/app/controller/admin/api/ThemeController.java b/src/main/java/run/halo/app/controller/admin/api/ThemeController.java index 87230f8661..4fe33a4b63 100644 --- a/src/main/java/run/halo/app/controller/admin/api/ThemeController.java +++ b/src/main/java/run/halo/app/controller/admin/api/ThemeController.java @@ -190,43 +190,6 @@ public ThemeProperty fetchTheme(@RequestParam("uri") String uri) { return themeService.fetch(uri); } - @PostMapping(value = {"fetchingBranches", "/fetching/git/branches"}) - @ApiOperation("Fetches all branches") - @Deprecated(since = "1.4.2", forRemoval = true) - public List fetchBranches(@RequestParam("uri") String uri) { - return themeService.fetchBranches(uri); - } - - @PostMapping("fetchingReleases") - @ApiOperation("Fetches all releases") - @Deprecated(since = "1.4.2", forRemoval = true) - public List 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:.+}") @ApiOperation("Upgrades theme from remote") public ThemeProperty updateThemeByFetching(@PathVariable("themeId") String themeId) { diff --git a/src/main/java/run/halo/app/model/dto/StatisticDTO.java b/src/main/java/run/halo/app/model/dto/StatisticDTO.java index a2ee103f88..b64bd0e246 100644 --- a/src/main/java/run/halo/app/model/dto/StatisticDTO.java +++ b/src/main/java/run/halo/app/model/dto/StatisticDTO.java @@ -18,9 +18,6 @@ public class StatisticDTO { private Long categoryCount; - @Deprecated - private Long attachmentCount; - private Long tagCount; private Long journalCount; diff --git a/src/main/java/run/halo/app/service/AdminService.java b/src/main/java/run/halo/app/service/AdminService.java index d58dd38f02..d888b184f5 100644 --- a/src/main/java/run/halo/app/service/AdminService.java +++ b/src/main/java/run/halo/app/service/AdminService.java @@ -3,7 +3,6 @@ import org.springframework.lang.NonNull; import run.halo.app.model.dto.EnvironmentDTO; 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.params.LoginParam; import run.halo.app.model.params.ResetPasswordParam; @@ -64,15 +63,6 @@ public interface AdminService { */ void resetPasswordByCode(@NonNull ResetPasswordParam param); - /** - * Get system counts. - * - * @return count dto - */ - @NonNull - @Deprecated - StatisticDTO getCount(); - /** * Get system environments * diff --git a/src/main/java/run/halo/app/service/ThemeService.java b/src/main/java/run/halo/app/service/ThemeService.java index fb46276cdf..509469b088 100644 --- a/src/main/java/run/halo/app/service/ThemeService.java +++ b/src/main/java/run/halo/app/service/ThemeService.java @@ -1,6 +1,5 @@ package run.halo.app.service; -import java.io.IOException; import java.nio.file.Path; import java.util.List; import java.util.Optional; @@ -19,19 +18,6 @@ */ 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. */ @@ -42,34 +28,11 @@ public interface ThemeService { */ 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. */ 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. */ @@ -85,26 +48,6 @@ public interface ThemeService { */ 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. * @@ -140,16 +83,6 @@ public interface ThemeService { @NonNull List 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 listCustomTemplates(@NonNull String themeId); - /** * Lists a set of custom template, such as sheet_xxx.ftl/post_xxx.ftl, and xxx will be * template name @@ -296,17 +229,6 @@ void saveTemplateContent(@NonNull String themeId, @NonNull String absolutePath, @NonNull 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. * @@ -316,58 +238,6 @@ void saveTemplateContent(@NonNull String themeId, @NonNull String absolutePath, @NonNull 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 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 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 */ diff --git a/src/main/java/run/halo/app/service/ThemeSettingService.java b/src/main/java/run/halo/app/service/ThemeSettingService.java index 85a44ed1f1..283aed09f2 100644 --- a/src/main/java/run/halo/app/service/ThemeSettingService.java +++ b/src/main/java/run/halo/app/service/ThemeSettingService.java @@ -16,7 +16,6 @@ */ public interface ThemeSettingService extends CrudService { - /** * Saves theme setting. * diff --git a/src/main/java/run/halo/app/service/base/BaseCommentService.java b/src/main/java/run/halo/app/service/base/BaseCommentService.java index ddacd7b572..0aab6c6c7d 100644 --- a/src/main/java/run/halo/app/service/base/BaseCommentService.java +++ b/src/main/java/run/halo/app/service/base/BaseCommentService.java @@ -27,15 +27,7 @@ */ public interface BaseCommentService extends CrudService { - - /** - * %d: parent commentator id - * %s: parent commentator author name - * %s: comment content - */ - @Deprecated - String COMMENT_TEMPLATE = "@%s %s"; - + /** * Lists comments by post id. * diff --git a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java index 437e3a0f04..7407642e88 100644 --- a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java @@ -20,7 +20,6 @@ import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import org.springframework.web.client.RestTemplate; import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.event.logger.LogEvent; @@ -30,12 +29,9 @@ import run.halo.app.mail.MailService; import run.halo.app.model.dto.EnvironmentDTO; 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.enums.CommentStatus; import run.halo.app.model.enums.LogType; 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.ResetPasswordParam; import run.halo.app.model.properties.EmailProperties; @@ -45,14 +41,7 @@ import run.halo.app.security.token.AuthToken; import run.halo.app.security.util.SecurityUtils; 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.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.utils.HaloUtils; import run.halo.app.utils.TwoFactorAuthUtils; @@ -68,60 +57,29 @@ @Service 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 UserService userService; - private final LinkService linkService; - private final MailService mailService; private final AbstractStringCacheStore cacheStore; - private final RestTemplate restTemplate; - private final HaloProperties haloProperties; private final ApplicationEventPublisher eventPublisher; - public AdminServiceImpl(PostService postService, - SheetService sheetService, - AttachmentService attachmentService, - PostCommentService postCommentService, - SheetCommentService sheetCommentService, - JournalCommentService journalCommentService, + public AdminServiceImpl( OptionService optionService, UserService userService, - LinkService linkService, MailService mailService, AbstractStringCacheStore cacheStore, - RestTemplate restTemplate, HaloProperties haloProperties, ApplicationEventPublisher eventPublisher) { - this.postService = postService; - this.sheetService = sheetService; - this.attachmentService = attachmentService; - this.postCommentService = postCommentService; - this.sheetCommentService = sheetCommentService; - this.journalCommentService = journalCommentService; this.optionService = optionService; this.userService = userService; - this.linkService = linkService; this.mailService = mailService; this.cacheStore = cacheStore; - this.restTemplate = restTemplate; this.haloProperties = haloProperties; this.eventPublisher = eventPublisher; } @@ -290,48 +248,21 @@ public void resetPasswordByCode(ResetPasswordParam param) { 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 @NonNull public EnvironmentDTO getEnvironments() { - EnvironmentDTO environmentDTO = new EnvironmentDTO(); + EnvironmentDTO environmentDto = new EnvironmentDTO(); // 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 @@ -398,7 +329,7 @@ public String getLogFiles(@NonNull Long lines) { List linesArray = new ArrayList<>(); - StringBuilder result = new StringBuilder(); + final StringBuilder result = new StringBuilder(); if (!file.exists()) { return StringUtils.EMPTY; diff --git a/src/main/java/run/halo/app/service/impl/MenuServiceImpl.java b/src/main/java/run/halo/app/service/impl/MenuServiceImpl.java index 2105f35c43..7cc9eb5370 100644 --- a/src/main/java/run/halo/app/service/impl/MenuServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/MenuServiceImpl.java @@ -6,13 +6,11 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.jetbrains.annotations.NotNull; import org.springframework.data.domain.Sort; import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; -import run.halo.app.exception.AlreadyExistsException; import run.halo.app.model.dto.MenuDTO; import run.halo.app.model.entity.Menu; import run.halo.app.model.params.MenuParam; @@ -40,14 +38,16 @@ public MenuServiceImpl(MenuRepository menuRepository) { } @Override - public @NonNull List listDtos(@NonNull Sort sort) { + public @NonNull + List listDtos(@NonNull Sort sort) { Assert.notNull(sort, "Sort info must not be null"); return convertTo(listAll(sort)); } @Override - public @NonNull List listTeamVos(@NonNull Sort sort) { + public @NonNull + List listTeamVos(@NonNull Sort sort) { Assert.notNull(sort, "Sort info must not be null"); // List all menus @@ -101,7 +101,8 @@ public List listByTeamAsTree(@NonNull String team, Sort sort) { } @Override - public @NonNull Menu createBy(@NonNull MenuParam menuParam) { + public @NonNull + Menu createBy(@NonNull MenuParam menuParam) { Assert.notNull(menuParam, "Menu param must not be null"); // Create an return @@ -141,12 +142,14 @@ public List listAllTeams() { } @Override - public @NonNull Menu create(@NonNull Menu menu) { + public @NonNull + Menu create(@NonNull Menu menu) { return super.create(menu); } @Override - public @NonNull Menu update(@NonNull Menu menu) { + public @NonNull + Menu update(@NonNull Menu menu) { return super.update(menu); } @@ -215,23 +218,4 @@ private List convertTo(List menus) { .map(menu -> (MenuDTO) new MenuDTO().convertFrom(menu)) .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() + " 已存在"); - } - } } diff --git a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java index 40a7c2b01d..829e9f8e5f 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -620,17 +620,5 @@ public OptionSimpleDTO convertToDto(Option 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)); - } } diff --git a/src/main/java/run/halo/app/service/impl/StatisticServiceImpl.java b/src/main/java/run/halo/app/service/impl/StatisticServiceImpl.java index f3d34691f5..3415885c4e 100644 --- a/src/main/java/run/halo/app/service/impl/StatisticServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/StatisticServiceImpl.java @@ -78,42 +78,42 @@ public StatisticServiceImpl(PostService postService, @Override public StatisticDTO getStatistic() { - StatisticDTO statisticDTO = new StatisticDTO(); - statisticDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED)); + StatisticDTO statisticDto = new StatisticDTO(); + statisticDto.setPostCount(postService.countByStatus(PostStatus.PUBLISHED)); // 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); - statisticDTO.setTagCount(tagService.count()); - statisticDTO.setCategoryCount(categoryService.count()); - statisticDTO.setJournalCount(journalService.count()); + statisticDto.setCommentCount(postCommentCount + sheetCommentCount + journalCommentCount); + statisticDto.setTagCount(tagService.count()); + statisticDto.setCategoryCount(categoryService.count()); + statisticDto.setJournalCount(journalService.count()); long birthday = optionService.getBirthday(); long days = (System.currentTimeMillis() - birthday) / (1000 * 24 * 3600); - statisticDTO.setEstablishDays(days); - statisticDTO.setBirthday(birthday); + statisticDto.setEstablishDays(days); + statisticDto.setBirthday(birthday); - statisticDTO.setLinkCount(linkService.count()); - statisticDTO.setVisitCount(postService.countVisit() + sheetService.countVisit()); - statisticDTO.setLikeCount(postService.countLike() + sheetService.countLike()); - return statisticDTO; + statisticDto.setLinkCount(linkService.count()); + statisticDto.setVisitCount(postService.countVisit() + sheetService.countVisit()); + statisticDto.setLikeCount(postService.countLike() + sheetService.countLike()); + return statisticDto; } @Override public StatisticWithUserDTO getStatisticWithUser() { - StatisticDTO statisticDTO = getStatistic(); + StatisticDTO statisticDto = getStatistic(); - StatisticWithUserDTO statisticWithUserDTO = new StatisticWithUserDTO(); - statisticWithUserDTO.convertFrom(statisticDTO); + StatisticWithUserDTO statisticWithUserDto = new StatisticWithUserDTO(); + statisticWithUserDto.convertFrom(statisticDto); User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("未查询到博主信息")); - statisticWithUserDTO.setUser(new UserDTO().convertFrom(user)); + statisticWithUserDto.setUser(new UserDTO().convertFrom(user)); - return statisticWithUserDTO; + return statisticWithUserDto; } } diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java index b6144d687c..1219ed8b49 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -1,24 +1,17 @@ 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.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.eclipse.jgit.api.errors.GitAPIException; import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.ResponseEntity; import org.springframework.lang.NonNull; @@ -30,7 +23,6 @@ import run.halo.app.config.properties.HaloProperties; import run.halo.app.event.theme.ThemeActivatedEvent; import run.halo.app.event.theme.ThemeUpdatedEvent; -import run.halo.app.exception.AlreadyExistsException; import run.halo.app.exception.BadRequestException; import run.halo.app.exception.ForbiddenException; import run.halo.app.exception.NotFoundException; @@ -55,9 +47,6 @@ import run.halo.app.theme.ThemePropertyScanner; import run.halo.app.theme.ZipThemeFetcher; 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. @@ -134,12 +123,6 @@ public List listThemeFolderBy(@NonNull String themeId) { .orElse(Collections.emptyList()); } - @Override - @NonNull - public List listCustomTemplates(@NonNull String themeId) { - return listCustomTemplates(themeId, CUSTOM_SHEET_PREFIX); - } - @Override @NonNull public List listCustomTemplates(@NonNull String themeId, @NonNull String prefix) { @@ -365,54 +348,6 @@ public ThemeProperty upload(@NonNull MultipartFile file) { 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 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 public ThemeProperty fetch(@NonNull String uri) { Assert.hasText(uri, "Theme remote uri must not be blank"); @@ -421,114 +356,6 @@ public ThemeProperty fetch(@NonNull String uri) { 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 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 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 fetchBranches(String uri) { - Assert.hasText(uri, "Theme remote uri must not be blank"); - - String repoUrl = StringUtils.appendIfMissingIgnoreCase(uri, ".git", ".git"); - List branches = GitUtils.getAllBranchesFromRemote(repoUrl); - - List themeProperties = new ArrayList<>(); - - branches.forEach(branch -> { - ThemeProperty themeProperty = new ThemeProperty(); - themeProperty.setBranch(branch); - themeProperties.add(themeProperty); - }); - - return themeProperties; - } - - @Override - public List fetchReleases(@NonNull String uri) { - Assert.hasText(uri, "Theme remote uri must not be blank"); - - List releases = GithubUtils.getReleases(uri); - - List 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 public void reload() { eventPublisher.publishEvent(new ThemeUpdatedEvent(this)); @@ -630,21 +457,4 @@ private ThemeProperty getProperty(@NonNull Path themePath) { .orElseThrow(() -> new ThemePropertyMissingException(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)。")); - } } diff --git a/src/main/java/run/halo/app/service/impl/TraceServiceImpl.java b/src/main/java/run/halo/app/service/impl/TraceServiceImpl.java deleted file mode 100644 index a7045ce31b..0000000000 --- a/src/main/java/run/halo/app/service/impl/TraceServiceImpl.java +++ /dev/null @@ -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 listHttpTraces() { -// return httpTraceRepository.findAll(); -// } -//} diff --git a/src/main/java/run/halo/app/service/impl/UserServiceImpl.java b/src/main/java/run/halo/app/service/impl/UserServiceImpl.java index 91a76c99aa..140c3f4da5 100644 --- a/src/main/java/run/halo/app/service/impl/UserServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/UserServiceImpl.java @@ -11,7 +11,6 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; -import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.cache.lock.CacheLock; import run.halo.app.event.logger.LogEvent; import run.halo.app.event.user.UserUpdatedEvent; @@ -41,16 +40,12 @@ public class UserServiceImpl extends AbstractCrudService implemen private final UserRepository userRepository; - private final AbstractStringCacheStore stringCacheStore; - private final ApplicationEventPublisher eventPublisher; public UserServiceImpl(UserRepository userRepository, - AbstractStringCacheStore stringCacheStore, ApplicationEventPublisher eventPublisher) { super(userRepository); this.userRepository = userRepository; - this.stringCacheStore = stringCacheStore; this.eventPublisher = eventPublisher; } diff --git a/src/main/java/run/halo/app/utils/GitUtils.java b/src/main/java/run/halo/app/utils/GitUtils.java index 55a80b06c6..0c0de3b650 100644 --- a/src/main/java/run/halo/app/utils/GitUtils.java +++ b/src/main/java/run/halo/app/utils/GitUtils.java @@ -1,10 +1,8 @@ package run.halo.app.utils; import java.io.IOException; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; @@ -23,7 +21,6 @@ import org.eclipse.jgit.treewalk.filter.TreeFilter; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; -import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** @@ -38,24 +35,6 @@ public class 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 getAllBranchesFromRemote(@NonNull String repoUrl) { List branches = new ArrayList<>(); try { diff --git a/src/main/java/run/halo/app/utils/GithubUtils.java b/src/main/java/run/halo/app/utils/GithubUtils.java deleted file mode 100644 index 7abdece738..0000000000 --- a/src/main/java/run/halo/app/utils/GithubUtils.java +++ /dev/null @@ -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 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 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 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 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 ghReleaseList = ghRepository.getReleases(); - - if (ghReleaseList.size() == 0) { - break; - } - - Optional res = ghReleaseList.stream() - .filter( - release -> StringUtils.equalsIgnoreCase(release.getTagName(), tagName)) - .findFirst(); - - if (res.isPresent()) { - GHRelease ghRelease = res.get(); - - result = new HashMap() { - { - 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 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 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 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 ghReleaseList = ghRepository.getReleases(); - - if (ghReleaseList.size() == 0) { - break; - } - GHRelease ghRelease = ghReleaseList.get(0); - - result = new HashMap() { - { - 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 - } - } - } - } -} diff --git a/src/test/java/run/halo/app/security/OneTimeTokenTest.java b/src/test/java/run/halo/app/security/OneTimeTokenTest.java index 55d0051992..be1e783a1f 100644 --- a/src/test/java/run/halo/app/security/OneTimeTokenTest.java +++ b/src/test/java/run/halo/app/security/OneTimeTokenTest.java @@ -23,7 +23,7 @@ @AutoConfigureMockMvc class OneTimeTokenTest { - static final String REQUEST_URI = "/api/admin/counts"; + static final String REQUEST_URI = "/api/admin/statistics"; @Autowired MockMvc mvc; diff --git a/src/test/java/run/halo/app/utils/GithubUtilsTest.java b/src/test/java/run/halo/app/utils/GithubUtilsTest.java deleted file mode 100644 index 013d45a65c..0000000000 --- a/src/test/java/run/halo/app/utils/GithubUtilsTest.java +++ /dev/null @@ -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 map = - GithubUtils.getLatestRelease("https://github.com/halo-dev/halo-theme-hux"); - } - - @Test - void getLatestReleasesWithInvalidURL() { - Map 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 list = GithubUtils.getReleases("https://github.com/halo-dev/halo-theme-hux"); - } -}