feat(geodata): add standard source presets (#6504)

* feat(geodata): add standard source presets

Expose the existing geofile allowlist to the Geodata editor so administrators can configure the supported scheduled downloads without copying URLs manually

Tested with npm run test, npm run lint, npm run typecheck, npm run format:check, and go test ./internal/web/service ./internal/web/controller -run '^(TestStandardGeodataSources|TestGeodata)' -count=1

Assisted-by: OpenCode:openai/gpt-5.6-terra (mostly)

* fix(geodata): preserve custom source entries

Add missing standard sources instead of replacing existing custom entries.

Assisted-by: OpenCode:openai/gpt-5.6-terra (mostly)
This commit is contained in:
ilyusha authored and GitHub committed 2026-09-13 20:02:43 +02:00 Unverified
1 parent ff1a6c3caf
commit d600de2c2e
19 files changed
+148 -2

No files matched your search

@@ -0,0 +1,79 @@
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, describe, expect, it, vi } from 'vitest';
import GeodataSection from '@/pages/index/GeodataSection';
import { HttpUtil, Msg } from '@/utils';
const STANDARD_SOURCES = [
{
url: 'https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat',
file: 'geoip.dat',
},
{
url: 'https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat',
file: 'geosite.dat',
},
{
url: 'https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat',
file: 'geoip_IR.dat',
},
{
url: 'https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat',
file: 'geosite_IR.dat',
},
{
url: 'https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat',
file: 'geoip_RU.dat',
},
{
url: 'https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat',
file: 'geosite_RU.dat',
},
];
const CUSTOM_SOURCE = {
url: 'https://example.com/geosite_custom.dat',
file: 'geosite_custom.dat',
};
afterEach(() => {
vi.restoreAllMocks();
});
describe('GeodataSection', () => {
it('adds the standard sources without removing custom sources', async () => {
vi.spyOn(HttpUtil, 'post').mockResolvedValue(
new Msg(
true,
'',
JSON.stringify({
xraySetting: { outbounds: [], geodata: { assets: [CUSTOM_SOURCE] } },
geodataSources: STANDARD_SOURCES,
}),
),
);
const user = userEvent.setup();
render(<GeodataSection active onBusy={vi.fn()} onClose={vi.fn()} />);
await screen.findByRole('button', {
name: 'Use standard sources',
});
await waitFor(() =>
expect(
(screen.getByRole('button', { name: 'Use standard sources' }) as HTMLButtonElement)
.disabled,
).toBe(false),
);
await user.click(screen.getByRole('button', { name: 'Use standard sources' }));
await waitFor(() => {
expect(screen.getByDisplayValue(CUSTOM_SOURCE.url)).toBeTruthy();
for (const source of STANDARD_SOURCES) {
expect(screen.getByDisplayValue(source.url)).toBeTruthy();
expect(screen.getByDisplayValue(source.file)).toBeTruthy();
}
});
});
});