diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java index db32159..667dec5 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java @@ -93,6 +93,7 @@ public class GitServiceImpl implements IGitService { return Git.init() .setBare(true) .setDirectory(repoDir) + .setInitialBranch("main") .call(); } @@ -110,6 +111,7 @@ public class GitServiceImpl implements IGitService { return Git.init() .setBare(true) .setDirectory(repoDir) + .setInitialBranch("main") .call(); } } catch (GitAPIException | IOException e) { @@ -212,6 +214,7 @@ public class GitServiceImpl implements IGitService { treeWalk.setFilter(PathFilter.create("applications/")); treeWalk.setRecursive(true); + Map appIconDataMapping = T.MapUtil.newHashMap(); while (treeWalk.next()) { String fileName = treeWalk.getNameString(); if (T.StrUtil.equals("basic.json", fileName)) { @@ -220,6 +223,14 @@ public class GitServiceImpl implements IGitService { basicJsonStr = T.StrUtil.emptyToDefault(basicJsonStr, T.StrUtil.EMPTY_JSON); Map basicJsonMap = T.JSONUtil.toBean(basicJsonStr, Map.class); + // filter by name + if (T.StrUtil.isNotEmpty(q)) { + String appName = T.MapUtil.getStr(basicJsonMap, "name", ""); + if (!appName.contains(q)) { + continue; + } + } + Map m = T.MapUtil.newHashMap(true); m.putAll(basicJsonMap); @@ -232,6 +243,21 @@ public class GitServiceImpl implements IGitService { m.put("commit", this.buildAswCommitInfo(commit)); resultList.add(m); + } else if (T.StrUtil.equals("icon.png", fileName)) { + ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); + byte[] bytes = loader.getBytes(); + if (T.ObjectUtil.isNotEmpty(bytes)) { + String dirPath = treeWalk.getPathString().replaceAll(fileName, ""); + appIconDataMapping.put(dirPath, Base64.getEncoder().encodeToString(bytes)); + } + } + } + + for (Map map : resultList) { + String applicationName = T.MapUtil.getStr(map, "name"); + if (T.StrUtil.isNotEmpty(applicationName)) { + String iconBase64Str = appIconDataMapping.get(T.StrUtil.concat(true, "applications/", applicationName, "/")); + map.put("icon", iconBase64Str); } } } @@ -536,7 +562,7 @@ public class GitServiceImpl implements IGitService { } @Override - public Map infoApplicationFileContent(String workspaceId, String branch, String applicationName, String commitId1111, String file) { + public Map infoApplicationFileContent(String workspaceId, String branch, String applicationName, String commitId, String file) { // applications/qq/basic.json String path = T.StrUtil.concat(true, "applications/", applicationName, "/", file); @@ -551,7 +577,7 @@ public class GitServiceImpl implements IGitService { try (TreeWalk treeWalk = new TreeWalk(repository); RevWalk revWalk = new RevWalk(repository); ) { - RevCommit revCommit = revWalk.parseCommit(ObjectId.fromString(commitId1111)); + RevCommit revCommit = revWalk.parseCommit(ObjectId.fromString(commitId)); ObjectId treeId = revCommit.getTree().getId(); treeWalk.addTree(treeId);