From bd7b87aa5030de82b4504cbf9fb0555617eb8e68 Mon Sep 17 00:00:00 2001 From: johnniang Date: Thu, 30 May 2019 02:04:20 +0800 Subject: [PATCH] Enhance theme fetching api --- .../run/halo/app/service/impl/ThemeServiceImpl.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 579ab2b4c..11bf16cb6 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -440,10 +440,11 @@ public class ThemeServiceImpl implements ThemeService { // Create temp path Path themeTmpPath = tmpPath.resolve(HaloUtils.randomUUIDWithoutDash()); - if (StringUtils.endsWithIgnoreCase(uri, ".git")) { - cloneFromGit(uri, themeTmpPath); - } else { + if (StringUtils.endsWithIgnoreCase(uri, ".zip")) { downloadZipAndUnzip(uri, themeTmpPath); + } else { + uri = StringUtils.appendIfMissingIgnoreCase(uri, ".git", ".git"); + cloneFromGit(uri, themeTmpPath); } return add(themeTmpPath); @@ -464,7 +465,7 @@ public class ThemeServiceImpl implements ThemeService { * * @param gitUrl git url must not be blank * @param targetPath target path must not be null - * @throws GitAPIException + * @throws GitAPIException throws when clone error */ private void cloneFromGit(@NonNull String gitUrl, @NonNull Path targetPath) throws GitAPIException { Assert.hasText(gitUrl, "Git url must not be blank"); @@ -486,7 +487,7 @@ public class ThemeServiceImpl implements ThemeService { * * @param zipUrl zip url must not be null * @param targetPath target path must not be null - * @throws IOException + * @throws IOException throws when download zip or unzip error */ private void downloadZipAndUnzip(@NonNull String zipUrl, @NonNull Path targetPath) throws IOException { Assert.hasText(zipUrl, "Zip url must not be blank"); @@ -514,7 +515,7 @@ public class ThemeServiceImpl implements ThemeService { * Creates temporary path. * * @return temporary path - * @throws IOException + * @throws IOException if an I/O error occurs or the temporary-file directory does not exist */ @NonNull private Path createTempPath() throws IOException {