Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/sync-qq-groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Sync QQ Groups

on:
repository_dispatch:
types: [sync-qq-groups]
workflow_dispatch:

permissions:
contents: write

jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
token: ${{ secrets.PAT_TOKEN }}
show-progress: false

- name: Fetch index.json and update README
run: |
DATA=$(curl -sf https://end.maafw.com/index.json) || exit 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): curl 没有设置超时时间,在出现网络问题时任务可能会一直挂起。

如果接口长时间无响应或非常缓慢,这一步可能会被无限阻塞。请显式添加超时参数(例如 --connect-timeout 和/或 --max-time,如 curl -sf --connect-timeout 5 --max-time 15 ...),以确保该步骤在有限时间内失败或退出。

Suggested change
DATA=$(curl -sf https://end.maafw.com/index.json) || exit 0
DATA=$(curl -sf --connect-timeout 5 --max-time 15 https://end.maafw.com/index.json) || exit 0
Original comment in English

suggestion (bug_risk): curl has no timeout, so the job might hang on network issues.

A hanging or very slow endpoint could block this job indefinitely. Please add an explicit timeout (e.g. --connect-timeout and/or --max-time, such as curl -sf --connect-timeout 5 --max-time 15 ...) so the step fails or exits within a bounded time.

Suggested change
DATA=$(curl -sf https://end.maafw.com/index.json) || exit 0
DATA=$(curl -sf --connect-timeout 5 --max-time 15 https://end.maafw.com/index.json) || exit 0


USER_GROUP=$(echo "$DATA" | jq -r '.qq_groups.user.number // empty')
USER_LINK=$(echo "$DATA" | jq -r '.qq_groups.user.link // empty')
DEV_GROUP=$(echo "$DATA" | jq -r '.qq_groups.dev.number // empty')
DEV_LINK=$(echo "$DATA" | jq -r '.qq_groups.dev.link // empty')

if [ -z "$USER_GROUP" ] || [ -z "$USER_LINK" ] || [ -z "$DEV_GROUP" ] || [ -z "$DEV_LINK" ]; then
echo "Missing fields in index.json, skipping"
exit 0
fi

sed -i "s|\[用户 QQ 群\](https://qm.qq.com/q/[^)]*): [0-9]*|[用户 QQ 群]($USER_LINK): $USER_GROUP|" README.md
sed -i "s|\[开发 QQ 群\](https://qm.qq.com/q/[^)]*): [0-9]*|[开发 QQ 群]($DEV_LINK): $DEV_GROUP|" README.md

- name: Check for changes
id: diff
run: |
git diff --quiet && echo "changed=false" >> "$GITHUB_OUTPUT" || echo "changed=true" >> "$GITHUB_OUTPUT"

- name: Commit and push
if: steps.diff.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "chore: sync QQ group info in README"
git push
12 changes: 7 additions & 5 deletions app/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import { motion } from "framer-motion";
import { useTranslation } from "react-i18next";
import Image from "next/image";
import { FRIEND_LINKS, GITHUB_URLS, QQ_GROUPS } from "../constants";
import { FRIEND_LINKS, GITHUB_URLS } from "../constants";
import { useQQGroups } from "../hooks/useQQGroups";

export default function Footer() {
const { t } = useTranslation();
const qqGroups = useQQGroups();

// 性能优化:使用固定速度,移除滚动速度检测
const marqueeDuration = 200;
Expand Down Expand Up @@ -51,22 +53,22 @@ export default function Footer() {
<ul className="space-y-2 text-sm text-black/80 dark:text-white/70">
<li>
<a
href={QQ_GROUPS.USER_GROUP_LINK}
href={qqGroups.user.link}
target="_blank"
rel="noopener noreferrer"
className="transition-colors hover:text-[#c49102] dark:hover:text-[#FFE600]"
>
{t("footer.userGroup")}: {QQ_GROUPS.USER_GROUP}
{t("footer.userGroup")}: {qqGroups.user.number}
</a>
</li>
<li>
<a
href={QQ_GROUPS.DEV_GROUP_LINK}
href={qqGroups.dev.link}
target="_blank"
rel="noopener noreferrer"
className="transition-colors hover:text-[#c49102] dark:hover:text-[#FFE600]"
>
{t("footer.devGroup")}: {QQ_GROUPS.DEV_GROUP}
{t("footer.devGroup")}: {qqGroups.dev.number}
</a>
</li>
</ul>
Expand Down
6 changes: 4 additions & 2 deletions app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { Book, Languages, Users } from "lucide-react";
import { Button } from "./ui/Button";
import { useTranslation } from "react-i18next";
import { ThemeToggle } from "./ThemeToggle";
import { GITHUB_URLS, QQ_GROUPS } from "../constants";
import { GITHUB_URLS } from "../constants";
import { useQQGroups } from "../hooks/useQQGroups";

export default function Header() {
const { t, i18n } = useTranslation();
const qqGroups = useQQGroups();

const toggleLanguage = () => {
const newLang = i18n.language === "zh" ? "en" : "zh";
Expand Down Expand Up @@ -52,7 +54,7 @@ export default function Header() {
<Book size={16} /> {t("header.docs")}
</Link>
<Link
href={QQ_GROUPS.USER_GROUP_LINK}
href={qqGroups.user.link}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 font-mono text-sm text-black/80 transition-colors hover:text-[#c49102] dark:text-white/80 dark:hover:text-[#FFE600]"
Expand Down
78 changes: 78 additions & 0 deletions app/hooks/useQQGroups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { useCallback, useEffect, useState } from "react";
import { QQ_GROUPS } from "../constants";

interface QQGroup {
number: string;
link: string;
}

interface QQGroups {
user: QQGroup;
dev: QQGroup;
}

const CACHE_KEY = "maaend-qq-groups";
const CACHE_TTL = 1000 * 60 * 60; // 1 hour

const fallback: QQGroups = {
user: { number: QQ_GROUPS.USER_GROUP, link: QQ_GROUPS.USER_GROUP_LINK },
dev: { number: QQ_GROUPS.DEV_GROUP, link: QQ_GROUPS.DEV_GROUP_LINK },
};

function readCache(): QQGroups | null {
try {
const raw = localStorage.getItem(CACHE_KEY);
if (!raw) return null;
const { data, ts } = JSON.parse(raw);
if (Date.now() - ts > CACHE_TTL) return null;
return data;
} catch {
return null;
}
}

function writeCache(data: QQGroups) {
try {
localStorage.setItem(CACHE_KEY, JSON.stringify({ data, ts: Date.now() }));
} catch {
// storage full or unavailable
}
}

export function useQQGroups() {
const [groups, setGroups] = useState<QQGroups>(fallback);

const fetchGroups = useCallback(async () => {
const cached = readCache();
if (cached) {
setGroups(cached);
return;
}
try {
const res = await fetch("https://end.maafw.com/index.json");
if (!res.ok) return;
const data = await res.json();
const qq = data.qq_groups;
if (
qq?.user?.number &&
qq?.user?.link &&
qq?.dev?.number &&
qq?.dev?.link
) {
const result: QQGroups = { user: qq.user, dev: qq.dev };
setGroups(result);
writeCache(result);
}
} catch {
// fallback to constants
}
}, []);

useEffect(() => {
(async () => {
await fetchGroups();
})();
}, [fetchGroups]);

return groups;
}
Loading