From 9462c284d6ae1005c7edfb36e15542c16a698966 Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 10 Aug 2025 02:02:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=B4=A1=E7=8C=AE?= =?UTF-8?q?=E8=80=85=E5=8B=8B=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openisle/service/ContributorService.java | 26 ++++++++++++++----- .../com/openisle/service/MedalService.java | 2 +- frontend_nuxt/components/AchievementList.vue | 3 +++ frontend_nuxt/components/CommentItem.vue | 13 +++++++++- frontend_nuxt/pages/users/[id].vue | 8 ++++-- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/openisle/service/ContributorService.java b/backend/src/main/java/com/openisle/service/ContributorService.java index 778648d36..4bf3b04d3 100644 --- a/backend/src/main/java/com/openisle/service/ContributorService.java +++ b/backend/src/main/java/com/openisle/service/ContributorService.java @@ -4,6 +4,7 @@ import com.openisle.model.ContributorConfig; import com.openisle.repository.ContributorConfigRepository; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -12,10 +13,11 @@ import org.springframework.web.client.RestTemplate; import java.util.List; import java.util.Map; +@Slf4j @Service @RequiredArgsConstructor public class ContributorService { - private static final String OWNER = "OpenIsle"; + private static final String OWNER = "nagisa77"; private static final String REPO = "OpenIsle"; private final ContributorConfigRepository repository; @@ -34,12 +36,23 @@ public class ContributorService { private long fetchContributionLines(String githubId) { try { String url = String.format("https://api.github.com/repos/%s/%s/stats/contributors", OWNER, REPO); - ResponseEntity response = restTemplate.getForEntity(url, List.class); - List> body = response.getBody(); - if (body == null) { + ResponseEntity response = restTemplate.getForEntity(url, Object.class); + + // 检查是否为202,GitHub有时会返回202表示正在生成统计数据 + if (response.getStatusCodeValue() == 202) { + log.warn("GitHub API 返回202,统计数据正在生成中,githubId: {}", githubId); return 0; } - for (Map item : body) { + + Object body = response.getBody(); + if (!(body instanceof List)) { + // 不是List类型,直接返回0 + return 0; + } + List listBody = (List) body; + for (Object itemObj : listBody) { + if (!(itemObj instanceof Map)) continue; + Map item = (Map) itemObj; Map author = (Map) item.get("author"); if (author != null && githubId.equals(author.get("login"))) { List> weeks = (List>) item.get("weeks"); @@ -59,7 +72,8 @@ public class ContributorService { return total; } } - } catch (Exception ignored) { + } catch (Exception e) { + log.warn(e.getMessage()); } return 0; } diff --git a/backend/src/main/java/com/openisle/service/MedalService.java b/backend/src/main/java/com/openisle/service/MedalService.java index e2cbb2569..ba64923fc 100644 --- a/backend/src/main/java/com/openisle/service/MedalService.java +++ b/backend/src/main/java/com/openisle/service/MedalService.java @@ -73,7 +73,7 @@ public class MedalService { medals.add(postMedal); ContributorMedalDto contributorMedal = new ContributorMedalDto(); - contributorMedal.setIcon("https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/icons/achi_contributor.png"); + contributorMedal.setIcon("https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/icons/achi_coder.png"); contributorMedal.setTitle("贡献者"); contributorMedal.setDescription("对仓库贡献超过1行代码"); contributorMedal.setType(MedalType.CONTRIBUTOR); diff --git a/frontend_nuxt/components/AchievementList.vue b/frontend_nuxt/components/AchievementList.vue index 1559d567e..5c925c61d 100644 --- a/frontend_nuxt/components/AchievementList.vue +++ b/frontend_nuxt/components/AchievementList.vue @@ -21,6 +21,9 @@ + diff --git a/frontend_nuxt/components/CommentItem.vue b/frontend_nuxt/components/CommentItem.vue index e6f130105..d2ee2d415 100644 --- a/frontend_nuxt/components/CommentItem.vue +++ b/frontend_nuxt/components/CommentItem.vue @@ -11,6 +11,7 @@
{{ comment.userName }} + authState.username === username) + const isMine = computed(function() { + const mine = authState.username === username || String(authState.userId) === username + console.log(mine) + return mine + }) const formatDate = (d) => { if (!d) return ''