mirror of
https://github.com/yyhuni/xingrin.git
synced 2026-01-31 11:46:16 +08:00
feat(blacklist): add mock data and service integration for blacklist management
- Create new blacklist mock data module with global and target-specific patterns - Add mock functions for getting and updating global blacklist rules - Add mock functions for getting and updating target-specific blacklist rules - Integrate mock blacklist endpoints into global-blacklist.service.ts - Integrate mock blacklist endpoints into target.service.ts - Export blacklist mock functions from main mock index - Enable testing of blacklist management UI without backend API
This commit is contained in:
69
frontend/mock/data/blacklist.ts
Normal file
69
frontend/mock/data/blacklist.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/**
|
||||||
|
* Blacklist Mock Data
|
||||||
|
*
|
||||||
|
* 黑名单规则 mock 数据
|
||||||
|
* - 全局黑名单:适用于所有 Target
|
||||||
|
* - Target 黑名单:仅适用于特定 Target
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface BlacklistResponse {
|
||||||
|
patterns: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateBlacklistRequest {
|
||||||
|
patterns: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 全局黑名单 mock 数据
|
||||||
|
let mockGlobalBlacklistPatterns: string[] = [
|
||||||
|
'*.gov',
|
||||||
|
'*.edu',
|
||||||
|
'*.mil',
|
||||||
|
'10.0.0.0/8',
|
||||||
|
'172.16.0.0/12',
|
||||||
|
'192.168.0.0/16',
|
||||||
|
]
|
||||||
|
|
||||||
|
// Target 黑名单 mock 数据(按 targetId 存储)
|
||||||
|
const mockTargetBlacklistPatterns: Record<number, string[]> = {
|
||||||
|
1: ['*.internal.example.com', '192.168.1.0/24'],
|
||||||
|
2: ['cdn.example.com', '*.cdn.*'],
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取全局黑名单
|
||||||
|
*/
|
||||||
|
export function getMockGlobalBlacklist(): BlacklistResponse {
|
||||||
|
return {
|
||||||
|
patterns: [...mockGlobalBlacklistPatterns],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新全局黑名单(全量替换)
|
||||||
|
*/
|
||||||
|
export function updateMockGlobalBlacklist(data: UpdateBlacklistRequest): BlacklistResponse {
|
||||||
|
mockGlobalBlacklistPatterns = [...data.patterns]
|
||||||
|
return {
|
||||||
|
patterns: mockGlobalBlacklistPatterns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 Target 黑名单
|
||||||
|
*/
|
||||||
|
export function getMockTargetBlacklist(targetId: number): BlacklistResponse {
|
||||||
|
return {
|
||||||
|
patterns: mockTargetBlacklistPatterns[targetId] ? [...mockTargetBlacklistPatterns[targetId]] : [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新 Target 黑名单(全量替换)
|
||||||
|
*/
|
||||||
|
export function updateMockTargetBlacklist(targetId: number, data: UpdateBlacklistRequest): BlacklistResponse {
|
||||||
|
mockTargetBlacklistPatterns[targetId] = [...data.patterns]
|
||||||
|
return {
|
||||||
|
patterns: mockTargetBlacklistPatterns[targetId],
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -182,3 +182,11 @@ export {
|
|||||||
getMockNotificationSettings,
|
getMockNotificationSettings,
|
||||||
updateMockNotificationSettings,
|
updateMockNotificationSettings,
|
||||||
} from './data/notification-settings'
|
} from './data/notification-settings'
|
||||||
|
|
||||||
|
// Blacklist
|
||||||
|
export {
|
||||||
|
getMockGlobalBlacklist,
|
||||||
|
updateMockGlobalBlacklist,
|
||||||
|
getMockTargetBlacklist,
|
||||||
|
updateMockTargetBlacklist,
|
||||||
|
} from './data/blacklist'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { api } from '@/lib/api-client'
|
import { api } from '@/lib/api-client'
|
||||||
|
import { USE_MOCK, mockDelay, getMockGlobalBlacklist, updateMockGlobalBlacklist } from '@/mock'
|
||||||
|
|
||||||
export interface GlobalBlacklistResponse {
|
export interface GlobalBlacklistResponse {
|
||||||
patterns: string[]
|
patterns: string[]
|
||||||
@@ -12,6 +13,10 @@ export interface UpdateGlobalBlacklistRequest {
|
|||||||
* Get global blacklist rules
|
* Get global blacklist rules
|
||||||
*/
|
*/
|
||||||
export async function getGlobalBlacklist(): Promise<GlobalBlacklistResponse> {
|
export async function getGlobalBlacklist(): Promise<GlobalBlacklistResponse> {
|
||||||
|
if (USE_MOCK) {
|
||||||
|
await mockDelay()
|
||||||
|
return getMockGlobalBlacklist()
|
||||||
|
}
|
||||||
const res = await api.get<GlobalBlacklistResponse>('/blacklist/rules/')
|
const res = await api.get<GlobalBlacklistResponse>('/blacklist/rules/')
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
@@ -20,6 +25,10 @@ export async function getGlobalBlacklist(): Promise<GlobalBlacklistResponse> {
|
|||||||
* Update global blacklist rules (full replace)
|
* Update global blacklist rules (full replace)
|
||||||
*/
|
*/
|
||||||
export async function updateGlobalBlacklist(data: UpdateGlobalBlacklistRequest): Promise<GlobalBlacklistResponse> {
|
export async function updateGlobalBlacklist(data: UpdateGlobalBlacklistRequest): Promise<GlobalBlacklistResponse> {
|
||||||
|
if (USE_MOCK) {
|
||||||
|
await mockDelay()
|
||||||
|
return updateMockGlobalBlacklist(data)
|
||||||
|
}
|
||||||
const res = await api.put<GlobalBlacklistResponse>('/blacklist/rules/', data)
|
const res = await api.put<GlobalBlacklistResponse>('/blacklist/rules/', data)
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import type {
|
|||||||
BatchCreateTargetsRequest,
|
BatchCreateTargetsRequest,
|
||||||
BatchCreateTargetsResponse,
|
BatchCreateTargetsResponse,
|
||||||
} from '@/types/target.types'
|
} from '@/types/target.types'
|
||||||
import { USE_MOCK, mockDelay, getMockTargets, getMockTargetById } from '@/mock'
|
import { USE_MOCK, mockDelay, getMockTargets, getMockTargetById, getMockTargetBlacklist, updateMockTargetBlacklist } from '@/mock'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all targets list (paginated)
|
* Get all targets list (paginated)
|
||||||
@@ -163,6 +163,10 @@ export async function getTargetEndpoints(
|
|||||||
* Get target's blacklist rules
|
* Get target's blacklist rules
|
||||||
*/
|
*/
|
||||||
export async function getTargetBlacklist(id: number): Promise<{ patterns: string[] }> {
|
export async function getTargetBlacklist(id: number): Promise<{ patterns: string[] }> {
|
||||||
|
if (USE_MOCK) {
|
||||||
|
await mockDelay()
|
||||||
|
return getMockTargetBlacklist(id)
|
||||||
|
}
|
||||||
const response = await api.get<{ patterns: string[] }>(`/targets/${id}/blacklist/`)
|
const response = await api.get<{ patterns: string[] }>(`/targets/${id}/blacklist/`)
|
||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
@@ -174,6 +178,11 @@ export async function updateTargetBlacklist(
|
|||||||
id: number,
|
id: number,
|
||||||
patterns: string[]
|
patterns: string[]
|
||||||
): Promise<{ count: number }> {
|
): Promise<{ count: number }> {
|
||||||
|
if (USE_MOCK) {
|
||||||
|
await mockDelay()
|
||||||
|
const result = updateMockTargetBlacklist(id, { patterns })
|
||||||
|
return { count: result.patterns.length }
|
||||||
|
}
|
||||||
const response = await api.put<{ count: number }>(`/targets/${id}/blacklist/`, { patterns })
|
const response = await api.put<{ count: number }>(`/targets/${id}/blacklist/`, { patterns })
|
||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user