Compare commits

...

6 Commits

Author SHA1 Message Date
ryan a49d07e2c2 chore(release): v3.5.5
### 🛠 修复
- 修复 Cloudflare 指向分组引用的节点已被删除时,分组列表/详情接口整体返回「Cloudflare 资源不存在」的问题;现会跳过缺失节点并继续返回其余分组。
- 修复静态导出部署下访问 Cloudflare 指向分组详情(`/cloudflare/groups/{id}`,id 不为 1)会跳回首页并触发 React hydration 报错的问题。

### ⚡️ 优化与改进
- 优化 openflare-agent Docker 镜像体积:精简运行时依赖并消除离线 IP 库冗余层,镜像总体积从 500MB+ 缩减至约 150MB。
2026-09-19 12:42:47 +08:00
ryan 1fe2763034 perf(docker): switch agent openresty base image to alpine-slim 2026-09-19 12:34:51 +08:00
ryan bf1e77a865 fix(docker): optimize Dockerfile by reducing layers and improving permissions 2026-09-19 12:27:50 +08:00
ryan 65bc7d9b81 chore(release): v3.5.5
### 🛠 修复

- 修复 Cloudflare 指向分组引用的节点已被删除时,分组列表/详情接口整体返回「Cloudflare 资源不存在」的问题;现会跳过缺失节点并继续返回其余分组。
- 修复静态导出部署下访问 Cloudflare 指向分组详情(`/cloudflare/groups/{id}`,id 不为 1)会跳回首页并触发 React hydration 报错的问题。
2026-09-19 11:13:42 +08:00
ryan 1d4533f183 fix(cloudflare): handle missing nodes in group detail responses 2026-09-18 14:04:44 +08:00
ryan a2404a50ef fix(cloudflare): restore group detail pages for ids other than 1
Static export only generates /cloudflare/groups/1.html. Unknown ids fell
through to the dashboard index, bouncing the browser home and triggering
React hydration error #418. Serve the generated group shell and resolve
the real id from the pathname, matching the websites detail fallback.
2026-09-17 22:00:12 +08:00
9 changed files with 207 additions and 42 deletions
+8 -8
View File
@@ -26,11 +26,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \
RUN apk add --no-cache bash curl \
&& bash scripts/fetch-agent-geoip-mmdb.sh
FROM openresty/openresty:alpine
FROM openresty/openresty:alpine-slim
RUN apk add --no-cache ca-certificates tzdata perl libmaxminddb su-exec libcap \
RUN apk add --no-cache ca-certificates tzdata libmaxminddb su-exec libcap \
&& ln -sf /usr/lib/libmaxminddb.so.0 /usr/lib/libmaxminddb.so \
&& apk add --no-cache --virtual .build-deps perl curl \
&& opm get anjia0532/lua-resty-maxminddb \
&& apk del .build-deps \
&& rm -rf /root/.opm \
&& addgroup -S openflare \
&& adduser -S -G openflare -H -h /data -s /sbin/nologin openflare \
&& mkdir -p /etc/openflare /data/etc/openflare \
@@ -42,13 +45,10 @@ ENV OPENFLARE_OPENRESTY_PATH=openresty \
COPY --from=builder /build/bin/openflare-agent /usr/local/bin/openflare-agent
# Default agent paths: data_dir/etc/openflare/GeoLite2-*.mmdb
COPY --from=builder /build/dist/geoip/GeoLite2-Country.mmdb /data/etc/openflare/GeoLite2-Country.mmdb
COPY --from=builder /build/dist/geoip/GeoLite2-City.mmdb /data/etc/openflare/GeoLite2-City.mmdb
RUN chown openflare:openflare /data/etc/openflare/GeoLite2-Country.mmdb /data/etc/openflare/GeoLite2-City.mmdb \
&& chmod 644 /data/etc/openflare/GeoLite2-Country.mmdb /data/etc/openflare/GeoLite2-City.mmdb
COPY --chown=openflare:openflare --chmod=644 --from=builder /build/dist/geoip/GeoLite2-Country.mmdb /data/etc/openflare/GeoLite2-Country.mmdb
COPY --chown=openflare:openflare --chmod=644 --from=builder /build/dist/geoip/GeoLite2-City.mmdb /data/etc/openflare/GeoLite2-City.mmdb
COPY scripts/agent-entrypoint.sh /usr/local/bin/openflare-agent-entrypoint.sh
RUN chmod +x /usr/local/bin/openflare-agent-entrypoint.sh
COPY --chmod=755 scripts/agent-entrypoint.sh /usr/local/bin/openflare-agent-entrypoint.sh
EXPOSE 80 443 18081
ENTRYPOINT ["/usr/local/bin/openflare-agent-entrypoint.sh"]
+16 -4
View File
@@ -10,7 +10,18 @@ sidebar: false
## [Unreleased]
### 新增
## [v3.5.5] - 2026-09-19
### 🛠 修复
- 修复 Cloudflare 指向分组引用的节点已被删除时,分组列表/详情接口整体返回「Cloudflare 资源不存在」的问题;现会跳过缺失节点并继续返回其余分组。
- 修复静态导出部署下访问 Cloudflare 指向分组详情(`/cloudflare/groups/{id}`,id 不为 1)会跳回首页并触发 React hydration 报错的问题。
### ⚡️ 优化与改进
- 优化 openflare-agent Docker 镜像体积:精简运行时依赖并消除离线 IP 库冗余层,镜像总体积从 500MB+ 缩减至约 150MB。
## [v3.5.4] - 2026-08-29
### ✨ 新功能
- 控制台接入中英双语(next-intl,无 URL 语言前缀):默认中文,可在顶栏或「外观设置」切换;选择写入 cookie 后刷新生效。
### 🛠 修复
@@ -18,16 +29,17 @@ sidebar: false
- 修复自定义 Webhook 推送在企业微信/钉钉返回 HTTP 200 但 `errcode` 非零时仍记为成功的问题;任务日志会记录上游响应体。
- 修复 OpenTelemetry Resource 绑定 semconv schema 版本导致 SDK 升级后可能无法启动的问题。
- 修复静态导出(build:embed)部署下切换语言无效的问题:此前页面在构建时固定为默认中文,运行时不再读取 `NEXT_LOCALE`;现在客户端会按 cookie/浏览器语言重新解析并切换界面语言与 `html lang`。
- 修复 frpc 子进程在被杀后孤儿进程继续持有管道导致退出阻塞的问题。
### 💄 其他/体验
- 前端使用 `next/font` 自托管 Inter,并忽略浏览器扩展改写 `body` 属性引起的 hydration 警告。
- 前端使用 `next/font` 自托管 Inter 字体,并忽略浏览器扩展改写 `body` 属性引起的 hydration 警告。
## 重大变更
> [!IMPORTANT]
>
>
>3.5.1 版本解耦了日志存储,ClickHouse 变为可选项,如果想切换数据库, 点击 「任务管理」 -> 「切换日志数据库」任务,按提示迁移数据并切换主库。
>
>
## [v3.5.3] - 2026-08-13
@@ -12,8 +12,8 @@ import {
} from 'lucide-react';
import Link from 'next/link';
import { useTranslations } from 'next-intl';
import { useParams } from 'next/navigation';
import { useState } from 'react';
import { usePathname } from 'next/navigation';
import { useEffect, useMemo, useState } from 'react';
import { toast } from 'sonner';
import { Badge } from '@/components/ui/badge';
@@ -46,10 +46,20 @@ import { getErrorMessage } from '../../../websites/components/website-utils';
import { GroupDialog } from '../../components/group-dialog';
import { MemberAddDialog } from '../../components/member-add-dialog';
function getGroupIdFromPathname(pathname: string | null): number {
const match = pathname?.match(/^\/cloudflare\/groups\/([^/]+)$/);
return Number(match?.[1]);
}
export function CloudflareGroupDetailPageClient() {
const t = useTranslations('cloudflare');
const params = useParams<{ id: string }>();
const groupID = Number(params.id);
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
const pathname = usePathname();
const groupID = useMemo(() => getGroupIdFromPathname(pathname), [pathname]);
const queryClient = useQueryClient();
const [editOpen, setEditOpen] = useState(false);
const [addOpen, setAddOpen] = useState(false);
@@ -147,7 +157,7 @@ export function CloudflareGroupDetailPageClient() {
onError: (error) => toast.error(getErrorMessage(error)),
});
if (detailQuery.isLoading)
if (!mounted || detailQuery.isLoading)
return (
<div className='w-full py-6 px-1'>
<LoadingStateWithBorder icon={Cloud} description={t('loadingDetail')} />
@@ -6,7 +6,7 @@ import { LoadingStateWithBorder } from '@/components/layout/loading';
import { CloudflareGroupDetailPageClient } from './page-client';
/** Placeholder for static export; real ids resolve client-side via useParams. */
/** Placeholder for static export; real ids resolve client-side from the pathname. */
export async function generateStaticParams() {
return [{ id: '1' }];
}
@@ -13,8 +13,22 @@ import { CloudflareService, NodeService } from '@/lib/services/openflare';
import { NextIntlClientProvider } from 'next-intl';
import zhCN from '@/messages/zh-CN.json';
let mockGroupId = '7';
let mockParamId = '7';
vi.mock('next/link', () => ({
default: ({
children,
href,
}: {
children: React.ReactNode;
href: string;
}) => <a href={href}>{children}</a>,
}));
vi.mock('next/navigation', () => ({
useParams: () => ({ id: '7' }),
useParams: () => ({ id: mockParamId }),
usePathname: () => `/cloudflare/groups/${mockGroupId}`,
}));
vi.mock('@/lib/services/openflare', async (importOriginal) => {
@@ -55,6 +69,8 @@ function renderPage() {
describe('Cloudflare group detail refresh', () => {
beforeEach(() => {
mockGroupId = '7';
mockParamId = '7';
vi.mocked(CloudflareService.getGroup).mockReset();
vi.mocked(CloudflareService.listAvailableDomains).mockReset();
vi.mocked(NodeService.listNodes).mockReset();
@@ -94,6 +110,19 @@ describe('Cloudflare group detail refresh', () => {
});
});
it('uses the browser pathname ID when serving a static-export fallback shell', async () => {
mockParamId = '1';
renderPage();
await waitFor(() => {
expect(CloudflareService.getGroup).toHaveBeenCalledWith(7);
});
expect(CloudflareService.getGroup).not.toHaveBeenCalledWith(1);
expect(
await screen.findByRole('heading', { name: '生产节点' }),
).toBeVisible();
});
it('automatically refreshes detail data every five seconds', async () => {
vi.useFakeTimers({ shouldAdvanceTime: true });
renderPage();
+21 -5
View File
@@ -255,11 +255,11 @@ func validEdgeNode(ctx context.Context, id uint, requireIPv4 bool) (*model.OpenF
}
func buildGroupItem(ctx context.Context, group *model.CFPointingGroup) (*GroupItem, error) {
primary, err := repository.GetOpenFlareNodeByID(ctx, group.PrimaryNodeID)
primary, err := lookupGroupNode(ctx, group.ID, group.PrimaryNodeID)
if err != nil {
return nil, err
}
active, err := repository.GetOpenFlareNodeByID(ctx, group.ActiveNodeID)
active, err := lookupGroupNode(ctx, group.ID, group.ActiveNodeID)
if err != nil {
return nil, err
}
@@ -267,18 +267,34 @@ func buildGroupItem(ctx context.Context, group *model.CFPointingGroup) (*GroupIt
if err != nil {
return nil, err
}
item := &GroupItem{ID: group.ID, Name: group.Name, PrimaryNode: nodeOption(primary), ActiveNode: nodeOption(active), DefaultProxied: group.DefaultProxied, Enabled: group.Enabled, MemberCount: count, CreatedAt: group.CreatedAt, UpdatedAt: group.UpdatedAt}
item := &GroupItem{ID: group.ID, Name: group.Name, PrimaryNode: nodeOptionForID(group.PrimaryNodeID, primary), ActiveNode: nodeOptionForID(group.ActiveNodeID, active), DefaultProxied: group.DefaultProxied, Enabled: group.Enabled, MemberCount: count, CreatedAt: group.CreatedAt, UpdatedAt: group.UpdatedAt}
if group.BackupNodeID != nil {
backup, backupErr := repository.GetOpenFlareNodeByID(ctx, *group.BackupNodeID)
backup, backupErr := lookupGroupNode(ctx, group.ID, *group.BackupNodeID)
if backupErr != nil {
return nil, backupErr
}
option := nodeOption(backup)
option := nodeOptionForID(*group.BackupNodeID, backup)
item.BackupNode = &option
}
return item, nil
}
func lookupGroupNode(ctx context.Context, groupID, nodeID uint) (*model.OpenFlareNode, error) {
node, err := repository.GetOpenFlareNodeByID(ctx, nodeID)
if errors.Is(err, gorm.ErrRecordNotFound) {
logger.WarnF(ctx, "[Cloudflare] pointing group references missing node: group_id=%d node_id=%d", groupID, nodeID)
return nil, nil
}
return node, err
}
func nodeOptionForID(id uint, node *model.OpenFlareNode) NodeOption {
if node == nil {
return NodeOption{ID: id}
}
return nodeOption(node)
}
func nodeOption(node *model.OpenFlareNode) NodeOption {
return NodeOption{ID: node.ID, Name: node.Name, IP: node.IP}
}
@@ -4,12 +4,14 @@
package cloudflare
import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
db "github.com/Rain-kl/Wavelet/internal/infra/persistence"
"github.com/Rain-kl/Wavelet/internal/model"
"github.com/Rain-kl/Wavelet/internal/repository"
"github.com/Rain-kl/Wavelet/internal/shared/response"
"github.com/gin-gonic/gin"
@@ -75,3 +77,56 @@ func TestGetGroupWithOrphanedMemberHealsAndSucceeds(t *testing.T) {
t.Errorf("GetCFPointingMemberByID() should return not found after healing")
}
}
func TestListGroupsHandlerWithMissingNodeStillSucceeds(t *testing.T) {
ctx, _ := setupCloudflareLogicDB(t)
if err := db.DB(ctx).Create(&model.CFPointingGroup{
Name: "KR",
PrimaryNodeID: 12,
ActiveNodeID: 12,
Enabled: true,
}).Error; err != nil {
t.Fatalf("Create(missing-node group) error = %v", err)
}
gin.SetMode(gin.TestMode)
router := gin.New()
router.Use(response.ErrorHandlerMiddleware())
router.GET("/groups", ListGroupsHandler)
recorder := httptest.NewRecorder()
router.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/groups", nil))
if recorder.Code != http.StatusOK {
t.Fatalf("ListGroupsHandler status = %d, body = %s, want %d", recorder.Code, recorder.Body.String(), http.StatusOK)
}
body := recorder.Body.String()
if !strings.Contains(body, `"name":"KR"`) {
t.Fatalf("ListGroupsHandler body = %s, want group KR", body)
}
if !strings.Contains(body, `"name":"primary"`) {
t.Fatalf("ListGroupsHandler body = %s, want intact group primary", body)
}
}
func TestGetGroupHandlerWithMissingNodeStillSucceeds(t *testing.T) {
ctx, _ := setupCloudflareLogicDB(t)
group := model.CFPointingGroup{Name: "KR", PrimaryNodeID: 12, ActiveNodeID: 12, Enabled: true}
if err := db.DB(ctx).Create(&group).Error; err != nil {
t.Fatalf("Create(missing-node group) error = %v", err)
}
gin.SetMode(gin.TestMode)
router := gin.New()
router.Use(response.ErrorHandlerMiddleware())
router.GET("/groups/:id", GetGroupHandler)
recorder := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/groups/%d", group.ID), nil)
router.ServeHTTP(recorder, request)
if recorder.Code != http.StatusOK {
t.Fatalf("GetGroupHandler status = %d, body = %s, want %d", recorder.Code, recorder.Body.String(), http.StatusOK)
}
if !strings.Contains(recorder.Body.String(), `"name":"KR"`) {
t.Fatalf("GetGroupHandler body = %s, want group KR", recorder.Body.String())
}
}
+37 -15
View File
@@ -8,27 +8,49 @@ import (
"strings"
)
//nolint:unused // Used by frontend.go in embed_frontend builds; default lint runs without that tag.
var nextExportDynamicPrefixes = []string{"websites", "cloudflare/groups"}
//nolint:unused // Used by frontend.go in embed_frontend builds; default lint runs without that tag.
func resolveNextExportDynamicFallback(subFS fs.FS, cleanPath string) (string, bool) {
parts := strings.Split(cleanPath, "/")
if len(parts) < 2 || parts[0] != "websites" || parts[1] == "" {
templatePath, ok := nextExportDynamicTemplate(cleanPath)
if !ok {
return "", false
}
var templatePath string
switch {
case len(parts) == 2 && !strings.Contains(parts[1], "."):
templatePath = "websites/1.html"
case len(parts) == 2 && strings.HasSuffix(parts[1], ".txt"):
templatePath = "websites/1.txt"
case len(parts) == 3 && parts[2] != "" && strings.HasPrefix(parts[2], "__next.") && strings.HasSuffix(parts[2], ".txt"):
templatePath = "websites/1/" + parts[2]
default:
return "", false
}
if _, err := fs.Stat(subFS, templatePath); err != nil {
return "", false
}
return templatePath, true
}
//nolint:unused // Used by frontend.go in embed_frontend builds; default lint runs without that tag.
func nextExportDynamicTemplate(cleanPath string) (string, bool) {
for _, prefix := range nextExportDynamicPrefixes {
if path, ok := nextExportIDTemplate(cleanPath, prefix); ok {
return path, true
}
}
return "", false
}
//nolint:unused // Used by frontend.go in embed_frontend builds; default lint runs without that tag.
func nextExportIDTemplate(cleanPath, prefix string) (string, bool) {
if cleanPath == prefix || !strings.HasPrefix(cleanPath, prefix+"/") {
return "", false
}
rest := strings.TrimPrefix(cleanPath, prefix+"/")
if rest == "" {
return "", false
}
parts := strings.Split(rest, "/")
switch {
case len(parts) == 1 && !strings.Contains(parts[0], "."):
return prefix + "/1.html", true
case len(parts) == 1 && strings.HasSuffix(parts[0], ".txt"):
return prefix + "/1.txt", true
case len(parts) == 2 && parts[1] != "" && strings.HasPrefix(parts[1], "__next.") && strings.HasSuffix(parts[1], ".txt"):
return prefix + "/1/" + parts[1], true
default:
return "", false
}
}
+24 -3
View File
@@ -14,6 +14,10 @@ func TestResolveNextExportDynamicFallbackUsesZoneTemplate(t *testing.T) {
"websites/1.html": &fstest.MapFile{Data: []byte("zone detail")},
"websites/1.txt": &fstest.MapFile{Data: []byte("zone flight")},
"websites/1/__next.!KG1haW4p.websites.$d$zoneId.__PAGE__.txt": &fstest.MapFile{Data: []byte("zone segment")},
"cloudflare/groups.html": &fstest.MapFile{Data: []byte("groups list redirect")},
"cloudflare/groups/1.html": &fstest.MapFile{Data: []byte("group detail")},
"cloudflare/groups/1.txt": &fstest.MapFile{Data: []byte("group flight")},
"cloudflare/groups/1/__next.!KG1haW4p.cloudflare.groups.$d$id.__PAGE__.txt": &fstest.MapFile{Data: []byte("group segment")},
}
tests := []struct {
@@ -28,15 +32,22 @@ func TestResolveNextExportDynamicFallbackUsesZoneTemplate(t *testing.T) {
input: "websites/3/__next.!KG1haW4p.websites.$d$zoneId.__PAGE__.txt",
want: "websites/1/__next.!KG1haW4p.websites.$d$zoneId.__PAGE__.txt",
},
{name: "cloudflare group html", input: "cloudflare/groups/2", want: "cloudflare/groups/1.html"},
{name: "cloudflare group route payload", input: "cloudflare/groups/2.txt", want: "cloudflare/groups/1.txt"},
{
name: "cloudflare group segment payload",
input: "cloudflare/groups/3/__next.!KG1haW4p.cloudflare.groups.$d$id.__PAGE__.txt",
want: "cloudflare/groups/1/__next.!KG1haW4p.cloudflare.groups.$d$id.__PAGE__.txt",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, ok := resolveNextExportDynamicFallback(subFS, tt.input)
if !ok {
t.Fatal("expected dynamic websites route fallback")
t.Fatalf("resolveNextExportDynamicFallback(%q) ok = false, want true", tt.input)
}
if got != tt.want {
t.Fatalf("expected %q fallback, got %q", tt.want, got)
t.Fatalf("resolveNextExportDynamicFallback(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
@@ -53,6 +64,13 @@ func TestResolveNextExportDynamicFallbackRejectsNestedOrAssetPath(t *testing.T)
"websites/3.js",
"websites/3/",
"websites/3/missing.txt",
"cloudflare",
"cloudflare/groups",
"cloudflare/groups.html",
"cloudflare/groups/2/settings",
"cloudflare/groups/2.js",
"cloudflare/groups/2/",
"cloudflare/groups/2/missing.txt",
}
for _, tt := range tests {
t.Run(tt, func(t *testing.T) {
@@ -69,6 +87,9 @@ func TestResolveNextExportDynamicFallbackRequiresGeneratedTemplate(t *testing.T)
}
if got, ok := resolveNextExportDynamicFallback(subFS, "websites/3"); ok {
t.Fatalf("expected no fallback without generated template, got %q", got)
t.Fatalf("resolveNextExportDynamicFallback(%q) = %q, want no fallback", "websites/3", got)
}
if got, ok := resolveNextExportDynamicFallback(subFS, "cloudflare/groups/2"); ok {
t.Fatalf("resolveNextExportDynamicFallback(%q) = %q, want no fallback", "cloudflare/groups/2", got)
}
}