feat(platform): prevent unscoped raw field lookups
This commit is contained in:
@@ -58,6 +58,19 @@ function isIncludeFieldsEnabled(value?: boolean | string) {
|
||||
return value === true || value === 'true';
|
||||
}
|
||||
|
||||
function hasRawFieldQueryScope(filters: HistoryFilters) {
|
||||
return Boolean(
|
||||
filters.keyword?.trim() ||
|
||||
filters.dateFrom?.trim() ||
|
||||
filters.dateTo?.trim() ||
|
||||
splitFields(filters.fields).length > 0
|
||||
);
|
||||
}
|
||||
|
||||
function shouldBlockRawFieldQuery(filters: HistoryFilters) {
|
||||
return isIncludeFieldsEnabled(filters.includeFields) && !hasRawFieldQueryScope(filters);
|
||||
}
|
||||
|
||||
function isFiniteNumber(value: unknown): value is number {
|
||||
return typeof value === 'number' && Number.isFinite(value);
|
||||
}
|
||||
@@ -72,9 +85,10 @@ function formatNumber(value?: number, suffix = '') {
|
||||
}
|
||||
|
||||
function mergeInitialFilters(initialVin: string, initialProtocol?: string, initialFilters: Record<string, string> = {}): HistoryFilters {
|
||||
const hasExplicitFilters = Object.keys(initialFilters).length > 0;
|
||||
return {
|
||||
...defaultFilters,
|
||||
keyword: initialVin || defaultFilters.keyword,
|
||||
keyword: initialVin || (hasExplicitFilters ? '' : defaultFilters.keyword),
|
||||
protocol: initialProtocol,
|
||||
...initialFilters,
|
||||
includeFields: isIncludeFieldsEnabled(initialFilters.includeFields)
|
||||
@@ -178,6 +192,12 @@ export function History({
|
||||
};
|
||||
|
||||
const loadRawFrames = (nextFilters = filters, page = rawPagination.currentPage, pageSize = rawPagination.pageSize) => {
|
||||
if (shouldBlockRawFieldQuery(nextFilters)) {
|
||||
setRawFrames({ items: [], total: 0, limit: pageSize, offset: (page - 1) * pageSize });
|
||||
setRawPagination({ currentPage: page, pageSize });
|
||||
Toast.warning('RAW 解析字段查询需要车辆、时间范围或字段裁剪');
|
||||
return;
|
||||
}
|
||||
setLoadingRaw(true);
|
||||
api.rawFramesQuery(buildRawQuery(nextFilters, pageSize, (page - 1) * pageSize))
|
||||
.then((nextPage) => {
|
||||
|
||||
Reference in New Issue
Block a user