From 08f873e8cdfe15abcfd8800650d1e94496b0924e Mon Sep 17 00:00:00 2001 From: shizhendong Date: Thu, 17 Oct 2024 14:48:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20application=20=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81=E5=90=8D=E7=A7=B0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. application 列表接口支持名称搜索 2. application 列表接口返回 icon 字段 3. master 改为 main, 初始分支是 main 分支 --- .../app/service/impl/GitServiceImpl.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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);