132 lines
3.0 KiB
TypeScript
132 lines
3.0 KiB
TypeScript
import { request } from '../request';
|
|
import type { PageParams } from './brand';
|
|
|
|
export function fetchGetModels(
|
|
params?: PageParams & {
|
|
brand_name?: string;
|
|
name?: string;
|
|
sort_by?: string;
|
|
sort_order?: string;
|
|
}
|
|
) {
|
|
return request<Api.Common.PageResult<Api.Model.ModelItem>>({
|
|
url: '/models/',
|
|
method: 'get',
|
|
params
|
|
});
|
|
}
|
|
|
|
export function fetchGetModel(id: number) {
|
|
return request<Api.Model.ModelItem>({
|
|
url: `/models/${id}`,
|
|
method: 'get'
|
|
});
|
|
}
|
|
|
|
export function fetchCreateModel(data: FormData | Record<string, unknown>, isFormData = false) {
|
|
return request<Api.Model.ModelItem>({
|
|
url: '/models/',
|
|
method: 'post',
|
|
data,
|
|
headers: isFormData ? { 'Content-Type': 'multipart/form-data' } : {}
|
|
});
|
|
}
|
|
|
|
export function fetchUpdateModel(id: number, data: FormData | Record<string, unknown>, isFormData = false) {
|
|
return request<Api.Model.ModelItem>({
|
|
url: `/models/${id}`,
|
|
method: 'put',
|
|
data,
|
|
headers: isFormData ? { 'Content-Type': 'multipart/form-data' } : {}
|
|
});
|
|
}
|
|
|
|
export function fetchDeleteModel(id: number) {
|
|
return request({
|
|
url: `/models/${id}`,
|
|
method: 'delete'
|
|
});
|
|
}
|
|
|
|
export function fetchGetModelEqCache(id: number) {
|
|
return request({
|
|
url: `/models/${id}/eq-cache`,
|
|
method: 'get',
|
|
timeout: 30000
|
|
});
|
|
}
|
|
|
|
export function fetchGetModelEqCacheField(id: number, fieldKey: string) {
|
|
return request({
|
|
url: `/models/${id}/eq-cache/field`,
|
|
method: 'get',
|
|
params: { key: fieldKey },
|
|
timeout: 30000
|
|
});
|
|
}
|
|
|
|
export function fetchGetModelMeilisearch(id: number) {
|
|
return request({
|
|
url: `/models/${id}/meilisearch`,
|
|
method: 'get',
|
|
timeout: 30000
|
|
});
|
|
}
|
|
|
|
export function fetchGetModelMeasurement(id: number) {
|
|
return request({
|
|
url: `/models/${id}/measurement`,
|
|
method: 'get',
|
|
timeout: 30000
|
|
});
|
|
}
|
|
|
|
export function fetchValidatePushToMeilisearch(modelIds: number[]) {
|
|
return request({
|
|
url: '/models/push-to-search/validate',
|
|
method: 'post',
|
|
data: { model_ids: modelIds },
|
|
timeout: 120000,
|
|
// @ts-expect-error custom flag consumed by request onError
|
|
skipErrorToast: true
|
|
});
|
|
}
|
|
|
|
export function fetchPushToMeilisearch(modelIds: number[]) {
|
|
return request({
|
|
url: '/models/push-to-search',
|
|
method: 'post',
|
|
data: { model_ids: modelIds },
|
|
timeout: 60000,
|
|
// @ts-expect-error custom flag consumed by request onError
|
|
skipErrorToast: true
|
|
});
|
|
}
|
|
|
|
export function fetchBatchUpdateModels(data: {
|
|
ids: number[];
|
|
brand_name?: string;
|
|
form?: string;
|
|
source?: string;
|
|
rig?: string;
|
|
}) {
|
|
return request<{
|
|
updated_count: number;
|
|
updated_ids: number[];
|
|
errors: Array<{ id: number; brand_name: string; name: string; error: string }>;
|
|
}>({
|
|
url: '/models/batch-update',
|
|
method: 'patch',
|
|
data
|
|
});
|
|
}
|
|
|
|
export function fetchFromSquigLink(shareUrl: string, selectedFile?: string) {
|
|
return request({
|
|
url: '/models/squiglink-fetch',
|
|
method: 'post',
|
|
data: { share_url: shareUrl, selected_file: selectedFile },
|
|
timeout: 30000
|
|
});
|
|
}
|