1298 lines
57 KiB
TypeScript
1298 lines
57 KiB
TypeScript
/**
|
|
* API abstraction layer.
|
|
* Switches between mock data and real backend based on VITE_USE_MOCK env var.
|
|
*/
|
|
import { api, setToken, clearToken } from './client';
|
|
import * as mock from './mock';
|
|
import type {
|
|
User, CreditRecord, Project, GenerationRecord, OptimizeParams, OptimizeResult,
|
|
Industry, IndustryConfig, AdminUser, AdminStats, ModelConfig, SystemConfig, AdminNotification,
|
|
PrivatePortraitConfig, PrivatePortraitProjectListOut, PrivatePortraitProject, PrivatePortraitValidateSession,
|
|
PrivatePortraitProjectCreateWithValidateOut, PrivatePortraitAssetListOut, PrivatePortraitAsset, PrivatePortraitSelectableAssetListOut,
|
|
} from '../types';
|
|
const USE_MOCK = import.meta.env.VITE_USE_MOCK === 'true';
|
|
// ── Auth ──────────────────────────────────────────────────
|
|
export async function login(username: string, password: string, captchaToken?: string, rememberMe?: boolean): Promise<User> {
|
|
if (USE_MOCK) return mock.mockLogin({ username, password });
|
|
const res = await api.post<{ accessToken: string; user: User }>('/auth/login', { username, password, captcha_token: captchaToken, remember_me: rememberMe || false }, false, true);
|
|
setToken(res.accessToken);
|
|
return res.user;
|
|
}
|
|
export async function phonelogin(phone: string, code: string): Promise<User> {
|
|
// if (USE_MOCK) return mock.mockLogin({ username, password });
|
|
const res = await api.post<{ accessToken: string; user: User }>('/auth/sms-login', { phone, code }, false, true);
|
|
setToken(res.accessToken);
|
|
return res.user;
|
|
}
|
|
export async function register(phone: string, code: string, password: string): Promise<User> {
|
|
const res = await api.post<{ accessToken: string; user: User }>('/auth/register', { phone, code, password }, false);
|
|
setToken(res.accessToken);
|
|
return res.user;
|
|
}
|
|
export async function logout(): Promise<void> {
|
|
if (USE_MOCK) return mock.mockLogout();
|
|
await api.post('/auth/logout');
|
|
clearToken();
|
|
}
|
|
export async function getUser(): Promise<User | null> {
|
|
if (USE_MOCK) return mock.mockGetUser();
|
|
try {
|
|
return await api.get<User>('/auth/me');
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
export async function changePassword(oldPwd: string, newPwd: string): Promise<void> {
|
|
if (USE_MOCK) return;
|
|
await api.post('/auth/change-password', { old_password: oldPwd, new_password: newPwd });
|
|
}
|
|
|
|
export async function changeUsername(newUsername: string): Promise<{ message: string; user?: User }> {
|
|
return api.post<{ message: string; user?: User }>('/auth/change-username', { new_username: newUsername });
|
|
}
|
|
|
|
// ── Projects ──────────────────────────────────────────────
|
|
export async function getProjects(): Promise<Project[]> {
|
|
if (USE_MOCK) return mock.mockGetProjects();
|
|
return api.get<Project[]>('/projects');
|
|
}
|
|
export async function createProject(name: string, industry: Industry): Promise<Project> {
|
|
if (USE_MOCK) return mock.mockCreateProject(name, industry);
|
|
return api.post<Project>('/projects', { name, industry });
|
|
}
|
|
export async function deleteProject(id: string): Promise<void> {
|
|
if (USE_MOCK) return mock.mockDeleteProject(id);
|
|
await api.delete(`/projects/${id}`);
|
|
}
|
|
// ── Generation ────────────────────────────────────────────
|
|
export interface GenerationRecordPageListOut {
|
|
page: number;
|
|
pageSize: number;
|
|
total: number;
|
|
items: GenerationRecord[];
|
|
}
|
|
export interface GetRecordsPageParams {
|
|
projectId?: string;
|
|
status?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
signal?: AbortSignal;
|
|
}
|
|
export async function getRecordsPage(params: GetRecordsPageParams = {}): Promise<GenerationRecordPageListOut> {
|
|
const page = params.page && params.page > 0 ? params.page : 1;
|
|
const pageSize = params.pageSize && params.pageSize > 0 ? params.pageSize : 10;
|
|
|
|
if (USE_MOCK) {
|
|
const mockRecords = await mock.mockGetGenerationRecords(params.projectId);
|
|
const filtered = params.status
|
|
? mockRecords.filter((record) => record.status === params.status)
|
|
: mockRecords;
|
|
const start = (page - 1) * pageSize;
|
|
|
|
return {
|
|
page,
|
|
pageSize,
|
|
total: filtered.length,
|
|
items: filtered.slice(start, start + pageSize),
|
|
};
|
|
}
|
|
const query = new URLSearchParams();
|
|
if (params.projectId) query.set('project_id', params.projectId);
|
|
if (params.status) query.set('status', params.status);
|
|
query.set('page', String(page));
|
|
query.set('page_size', String(pageSize));
|
|
|
|
return api.get<GenerationRecordPageListOut>(`/generation-records?${query.toString()}`, { signal: params.signal });
|
|
}
|
|
export async function optimizePrompt(
|
|
projectId: string, params: OptimizeParams
|
|
): Promise<OptimizeResult> {
|
|
if (USE_MOCK) return mock.mockOptimizePrompt(projectId, params as any);
|
|
return api.post('/generation-records/optimize', {
|
|
project_id: projectId,//项目id
|
|
gen_type:params.genType,//生成类型
|
|
prompt: params.prompt,
|
|
engine_id: params.engineId,
|
|
include_media_references: params.includeMediaReferences ?? false,
|
|
duration: params.duration,
|
|
aspect_ratio: params.aspectRatio || null,
|
|
resolution: params.resolution || null,
|
|
references: params.references || null,
|
|
idempotency_key: params.idempotencyKey || null,
|
|
image_size: params.image_size || null,
|
|
image_proportion: params.image_proportion || null,
|
|
image_px: params.image_px || null,
|
|
});
|
|
}
|
|
|
|
export interface UploadResourceResult {
|
|
url: string;
|
|
filename: string;
|
|
type?: string;
|
|
module?: string;
|
|
resource_id?: string;
|
|
file_size_bytes?: number;
|
|
duration_seconds?: number | null;
|
|
}
|
|
|
|
export async function uploadAudio(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
|
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/generation-records/upload-audio${query}`, {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error('音频上传失败');
|
|
return await res.json();
|
|
}
|
|
export async function uploadImage(file: File): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/generation-records/upload-image`, {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error('图片上传失败');
|
|
return await res.json();
|
|
}
|
|
export async function uploadVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
|
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/generation-records/upload-video${query}`, {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error('视频上传失败');
|
|
return await res.json();
|
|
}
|
|
|
|
function privatePortraitUploadEndpoint(path: string, durationSeconds?: number): string {
|
|
const base = `${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api${path}`;
|
|
const query = typeof durationSeconds === 'number' && durationSeconds > 0
|
|
? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}`
|
|
: '';
|
|
return `${base}${query}`;
|
|
}
|
|
|
|
async function uploadPrivatePortraitFile(path: string, file: File, durationSeconds?: number, errorMessage = '素材上传失败'): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const res = await fetch(privatePortraitUploadEndpoint(path, durationSeconds), {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error(errorMessage);
|
|
return await res.json();
|
|
}
|
|
|
|
export async function uploadPrivatePortraitImage(file: File): Promise<UploadResourceResult> {
|
|
return uploadPrivatePortraitFile('/private-portrait/uploads/image', file, undefined, '真人图片素材上传失败');
|
|
}
|
|
|
|
export async function uploadPrivatePortraitVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
|
return uploadPrivatePortraitFile('/private-portrait/uploads/video', file, durationSeconds, '真人视频素材上传失败');
|
|
}
|
|
|
|
export async function uploadPrivatePortraitVirtualImage(file: File): Promise<UploadResourceResult> {
|
|
return uploadPrivatePortraitFile('/private-portrait/virtual/uploads/image', file, undefined, '虚拟图片素材上传失败');
|
|
}
|
|
|
|
export async function uploadPrivatePortraitVirtualVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
|
return uploadPrivatePortraitFile('/private-portrait/virtual/uploads/video', file, durationSeconds, '虚拟视频素材上传失败');
|
|
}
|
|
|
|
export async function uploadHotOpeningImage(file: File): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/hot-opening-replications/upload-image`, {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error('图片上传失败');
|
|
return await res.json();
|
|
}
|
|
|
|
export async function uploadHotOpeningVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
|
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/hot-opening-replications/upload-video${query}`, {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error('视频上传失败');
|
|
return await res.json();
|
|
}
|
|
|
|
export async function uploadShotReplicateImage(file: File): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/shot-replications/upload-image`, {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error('图片上传失败');
|
|
return await res.json();
|
|
}
|
|
|
|
export async function uploadShotReplicateVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const token = localStorage.getItem('auth_token');
|
|
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
|
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/shot-replications/upload-video${query}`, {
|
|
method: 'POST',
|
|
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
body: form,
|
|
});
|
|
if (!res.ok) throw new Error('视频上传失败');
|
|
return await res.json();
|
|
}
|
|
export async function deleteUpload(url: string): Promise<void> {
|
|
await api.post(`/generation-records/delete-file?url=${encodeURIComponent(url)}`);
|
|
}
|
|
export async function updateRecordPrompt(recordId: string, optimizedPrompt: string): Promise<void> {
|
|
await api.put(`/generation-records/${recordId}/prompt`, { optimized_prompt: optimizedPrompt });
|
|
}
|
|
export async function generateVideo(recordId: string): Promise<GenerationRecord> {
|
|
if (USE_MOCK) return mock.mockGenerateVideo(recordId);
|
|
return api.post<GenerationRecord>(`/generation-records/${recordId}/generate`);
|
|
}
|
|
|
|
export async function retryGeneration(recordId: string): Promise<GenerationRecord> {
|
|
if (USE_MOCK) return mock.mockGenerateVideo(recordId);
|
|
return api.post<GenerationRecord>(`/generation-records/${recordId}/retry`);
|
|
}
|
|
// ── Credits ───────────────────────────────────────────────
|
|
export async function getCredits(page = 1, pageSize = 20): Promise<{ credits: number; records: CreditRecord[]; total: number }> {
|
|
if (USE_MOCK) {
|
|
const data = await mock.mockGetCredits();
|
|
return data;
|
|
}
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('page_size', String(pageSize));
|
|
return api.get(`/credits?${params.toString()}`);
|
|
}
|
|
// ── Captcha ───────────────────────────────────────────────
|
|
export async function getSliderCaptcha(): Promise<{ captcha_id: string; bg_image: string; slider_image: string }> {
|
|
if (USE_MOCK) return { captcha_id: 'mock', bg_image: '', slider_image: '' };
|
|
return api.get('/captcha/slider', false);
|
|
}
|
|
export async function verifyCaptcha(captchaId: string, x: number): Promise<string> {
|
|
if (USE_MOCK) return 'mock-token';
|
|
const res = await api.post<{ token: string }>('/captcha/verify', { captcha_id: captchaId, x_offset: x }, false);
|
|
return res.token;
|
|
}
|
|
// ── Site Info ─────────────────────────────────────────────
|
|
export async function getSiteInfo(): Promise<{ siteName: string; siteLogo: string; userAgreementPrivacyUrl: string; siteCopyright: string; operationManual: string; loginBgVideo: string; optimizeHoldCredits?: number; siteBanner?: string; siteBannerVersion?: number }> {
|
|
if (USE_MOCK) return { siteName: '智创', siteLogo: '', userAgreementPrivacyUrl: '', siteCopyright: '© 2026 智创 版权所有', operationManual: '', loginBgVideo: '' };
|
|
return api.get('/auth/site-info', false);
|
|
}
|
|
// ── Video Engines ─────────────────────────────────────────
|
|
export async function getVideoEngines(): Promise<{ items: { id: string; name: string; provider: string; supportedRatios: string[]; supportedResolutions: string[]; supportedDurations: number[] }[] }> {
|
|
if (USE_MOCK) return { items: [{ id: 'mock', name: 'Seedance', provider: 'seedance', supportedRatios: ['16:9', '9:16', '1:1', '4:3', '3:4', '21:9'], supportedResolutions: ['480p', '720p', '1080p'], supportedDurations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] }] };
|
|
return api.get('/video-engines');
|
|
}
|
|
// 参数选择(图片)Parameters
|
|
export async function getParameters(): Promise<any[]> {
|
|
return api.get('/image-engines');
|
|
}
|
|
// ── SMS ───────────────────────────────────────────────────
|
|
export async function sendSms(phone: string, scene: string): Promise<void> {
|
|
if (USE_MOCK) return;
|
|
await api.post('/sms/send', { phone, scene: scene }, false);
|
|
}
|
|
export async function verifySms(phone: string, code: string): Promise<{ token: string }> {
|
|
if (USE_MOCK) return { token: 'mock-sms-token' };
|
|
return api.post('/sms/verify', { phone, code }, false);
|
|
}
|
|
// ── Notifications ─────────────────────────────────────────
|
|
export async function getNotifications(page = 1, pageSize = 20, isRead?: boolean): Promise<{ items: AdminNotification[], total: number, credits?: { balance: number } }> {
|
|
if (USE_MOCK) {
|
|
const items = await mock.mockGetAdminNotifications();
|
|
return { items, total: items.length };
|
|
}
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('page_size', String(pageSize));
|
|
if (isRead !== undefined) {
|
|
params.set('is_read', String(isRead));
|
|
}
|
|
return api.get(`/notifications?${params.toString()}`);
|
|
}
|
|
export async function getUnreadCount(): Promise<number> {
|
|
if (USE_MOCK) return mock.mockGetAdminNotifications().then(n => n.filter(x => !x.isRead).length);
|
|
const res = await api.get<{ count: number }>('/notifications/unread-count');
|
|
return res.count;
|
|
}
|
|
export async function markNotificationRead(id: string): Promise<void> {
|
|
if (USE_MOCK) return;
|
|
await api.put(`/notifications/${id}/read`);
|
|
}
|
|
// ── Admin ─────────────────────────────────────────────────
|
|
export async function getAdminStats(): Promise<AdminStats> {
|
|
if (USE_MOCK) return mock.mockGetAdminStats();
|
|
return api.get('/admin/stats');
|
|
}
|
|
export async function getAdminUsers(page = 1, pageSize = 1000, search?: string): Promise<{ items: AdminUser[]; total: number }> {
|
|
if (USE_MOCK) {
|
|
const items = await mock.mockGetAdminUsers(search);
|
|
return { items, total: items.length };
|
|
}
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('page_size', String(pageSize));
|
|
if (search) params.set('search', search);
|
|
return api.get(`/admin/users?${params.toString()}`);
|
|
}
|
|
|
|
export async function getAdminNotifications(page = 1, pageSize = 20): Promise<{ items: any[]; total: number }> {
|
|
if (USE_MOCK) {
|
|
const items = await mock.mockGetAdminNotifications();
|
|
return { items, total: items.length };
|
|
}
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('page_size', String(pageSize));
|
|
return api.get(`/admin/notifications?${params.toString()}`);
|
|
}
|
|
|
|
export async function createAdminNotification(params: { title: string; content: string; type?: string; target_user_id?: string }): Promise<void> {
|
|
if (USE_MOCK) return;
|
|
await api.post('/admin/notifications', params);
|
|
}
|
|
|
|
export async function deleteAdminNotification(id: string): Promise<void> {
|
|
if (USE_MOCK) return;
|
|
await api.delete(`/admin/notifications/${id}`);
|
|
}
|
|
|
|
export async function getNotificationReadUsers(notificationId: string): Promise<{ items: any[] }> {
|
|
if (USE_MOCK) return { items: [] };
|
|
return api.get(`/admin/notifications/${notificationId}/read-users`);
|
|
}
|
|
export async function adjustCredits(userId: string, amount: number, description: string): Promise<void> {
|
|
if (USE_MOCK) return mock.mockAdjustCredits(userId, amount, description);
|
|
await api.post(`/admin/users/${userId}/credits`, { amount, description });
|
|
}
|
|
export async function toggleUserStatus(userId: string, isActive: boolean): Promise<void> {
|
|
if (USE_MOCK) return mock.mockToggleUserStatus(userId, isActive);
|
|
await api.put(`/admin/users/${userId}/status`, { is_active: isActive });
|
|
}
|
|
export async function getModelConfigs(): Promise<ModelConfig[]> {
|
|
if (USE_MOCK) return mock.mockGetModelConfigs();
|
|
return api.get('/admin/model-configs');
|
|
}
|
|
export async function saveModelConfig(config: Partial<ModelConfig> & { id?: string }): Promise<ModelConfig> {
|
|
if (USE_MOCK) return mock.mockSaveModelConfig(config as any);
|
|
if (config.id) return api.put(`/admin/model-configs/${config.id}`, config);
|
|
return api.post('/admin/model-configs', config);
|
|
}
|
|
export async function deleteModelConfig(id: string): Promise<void> {
|
|
if (USE_MOCK) return mock.mockDeleteModelConfig(id);
|
|
await api.delete(`/admin/model-configs/${id}`);
|
|
}
|
|
export async function getSystemConfigs(): Promise<SystemConfig[]> {
|
|
if (USE_MOCK) return mock.mockGetSystemConfigs();
|
|
return api.get('/admin/system-configs');
|
|
}
|
|
export async function updateSystemConfig(id: string, value: string): Promise<void> {
|
|
if (USE_MOCK) return mock.mockUpdateSystemConfig(id, value);
|
|
await api.put(`/admin/system-configs/${id}`, { value });
|
|
}
|
|
// ── Industries ─────────────────────────────────────────────
|
|
export async function getIndustries(): Promise<IndustryConfig[]> {
|
|
const data = await api.get<any[]>('/industries');
|
|
return data.map((item: any) => {
|
|
const skills = Array.isArray(item.skills) ? item.skills : [];
|
|
const optionGroups = skills
|
|
.filter((s: any) => s && s.type === 'option_group' && s.name && Array.isArray(s.options))
|
|
.map((s: any) => ({ name: s.name, options: s.options }));
|
|
return { ...item, optionGroups };
|
|
});
|
|
}
|
|
// ── Menu Config ────────────────────────────────────────────
|
|
export async function getMenuConfigs(): Promise<any[]> {
|
|
return api.get('/menu-configs');
|
|
}
|
|
// ── Recharge Packages ──────────────────────────────────────
|
|
export async function getRechargePackages(): Promise<any[]> {
|
|
return api.get('/recharge-packages');
|
|
}
|
|
|
|
export async function getPaymentMethods(): Promise<{ alipay: boolean; wechat: boolean }> {
|
|
return api.get('/payments/methods');
|
|
}
|
|
|
|
export async function createRechargeOrder(planId: string, method: string = 'wechat'): Promise<any> {
|
|
return api.post('/payments/recharge', { plan: planId, method });
|
|
}
|
|
|
|
export async function getPaymentOrders(page = 1, pageSize = 20): Promise<{ items: any[]; total: number }> {
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('page_size', String(pageSize));
|
|
return api.get(`/payments/orders?${params.toString()}`);
|
|
}
|
|
|
|
export async function getPaymentOrder(orderNo: string): Promise<any> {
|
|
return api.get(`/payments/orders/${orderNo}`);
|
|
}
|
|
|
|
export async function cancelPaymentOrder(orderNo: string): Promise<void> {
|
|
return api.post(`/payments/orders/${orderNo}/cancel`);
|
|
}
|
|
|
|
export async function getCreditRatios(): Promise<any[]> {
|
|
return api.get('/credits/ratios');
|
|
}
|
|
// 引擎配置
|
|
export async function getEngine(): Promise<any[]> {
|
|
return api.get('/generation-ai/engines');
|
|
}
|
|
// ── Generation AI Tasks ────────────────────────────────────
|
|
// 创建ai生成任务
|
|
export async function createGenerationTask(params: any): Promise<any> {
|
|
return api.post('/generation-ai/tasks', params);
|
|
}
|
|
// 获取ai生成任务列表
|
|
export async function getgen_list(Pagebreak: any): Promise<any[]> {
|
|
return api.get('/generation-ai/tasks?page='+Pagebreak.page+'&page_size='+Pagebreak.pageSize);
|
|
}
|
|
// 获取生成任务历史记录
|
|
export async function gethistory(Pagebreak: any): Promise<any[]> {
|
|
return api.get('/generation-ai/history'+Pagebreak);
|
|
}
|
|
// 获取生成任务历史记录子项
|
|
export async function gethistoryItems(Pagebreak: any): Promise<any[]> {
|
|
return api.get('/generation-ai/history/'+Pagebreak);
|
|
}
|
|
// 删除ai对话历史记录
|
|
export async function deleteHistory(id: string): Promise<void> {
|
|
await api.delete(`/generation-ai/tasks/${id}`);
|
|
}
|
|
export async function calculateCredits(): Promise<any[]> {
|
|
return api.get('/credits/credit-ratios');
|
|
}
|
|
// 获取验证码
|
|
export async function getSendcode(phone: string): Promise<any> {
|
|
return api.post('/sms/send', { phone });
|
|
}
|
|
export interface OAuthAppParam {
|
|
page: number;
|
|
pageSize: number;
|
|
open_type?: string;
|
|
status?: string;
|
|
app_id?: string;
|
|
}
|
|
export interface OAuthAppList {
|
|
page: number;
|
|
pageSize: number;
|
|
total: number;
|
|
data: any[];
|
|
}
|
|
// 获取用户列表
|
|
export async function getAuthorizationList(params: OAuthAppParam): Promise<OAuthAppList> {
|
|
const query = new URLSearchParams();
|
|
query.set('page', String(params.page));
|
|
query.set('page_size', String(params.pageSize));
|
|
if (params.open_type) query.set('open_type', params.open_type);
|
|
if (params.status) query.set('status', params.status);
|
|
if (params.app_id) query.set('app_id', params.app_id);
|
|
|
|
return api.get<OAuthAppList>(`/admin/user-oauth-apps/list?${query.toString()}`);
|
|
}
|
|
|
|
|
|
// 爆款开头复刻
|
|
export async function generateReplication(params: any): Promise<any> {
|
|
return api.post('/v2/hot-opening-replications/tasks', params);
|
|
}
|
|
// 获取爆款开头复刻任务列表
|
|
export async function getReplicationList(page: number, page_size: number, keyword?: string): Promise<any[]> {
|
|
let url = `/hot-opening-replications/tasks?page=${page}&page_size=${page_size}`;
|
|
if (keyword) {
|
|
url += `&keyword=${encodeURIComponent(keyword)}`;
|
|
}
|
|
return api.get(url);
|
|
}
|
|
// 获取爆款开头复刻任务详情。版本必须由列表/创建结果/URL 明确传入,禁止错误降级。
|
|
export async function getReplicationDetail(id: string, flowVersion: 'v1' | 'v2'): Promise<any> {
|
|
return flowVersion === 'v2'
|
|
? api.get(`/v2/hot-opening-replications/tasks/${id}`)
|
|
: api.get(`/hot-opening-replications/tasks/${id}`);
|
|
}
|
|
|
|
export interface RetryVideoPromptV2Params {
|
|
video_config: {
|
|
engine_id: string;
|
|
duration: number;
|
|
aspect_ratio: string;
|
|
resolution: string;
|
|
};
|
|
}
|
|
|
|
export async function retryHotOpeningVideoPromptV2(
|
|
projectId: string,
|
|
stepId: string,
|
|
params: RetryVideoPromptV2Params,
|
|
): Promise<any> {
|
|
return api.post(`/v2/hot-opening-replications/tasks/${projectId}/steps/${stepId}/retry-video-prompt`, params);
|
|
}
|
|
|
|
|
|
export async function updateHotOpeningVideoPromptSchemaV2(projectId: string, stepId: string, params: { prompt_schema: Record<string, any> }): Promise<any> {
|
|
return api.put(`/v2/hot-opening-replications/tasks/${projectId}/steps/${stepId}/video-prompt-schema`, params);
|
|
}
|
|
|
|
export async function generateHotOpeningVideoV2(projectId: string, stepId: string): Promise<any> {
|
|
return api.post(`/v2/hot-opening-replications/tasks/${projectId}/steps/${stepId}/generate-video`);
|
|
}
|
|
// 第一步,生成提示词
|
|
export async function getone(projectId: string, stepId: string): Promise<any> {
|
|
return api.post(`/hot-opening-replications/tasks/${projectId}/steps/${stepId}/generate-image-prompt`);
|
|
}
|
|
|
|
// 修改图片生成提示词
|
|
export async function updateImagePrompt(projectId: string, stepId: string, params: any): Promise<any> {
|
|
return api.put(`/hot-opening-replications/tasks/${projectId}/steps/${stepId}/image-prompt`, params);
|
|
}
|
|
|
|
// 第二步,生成图片
|
|
export async function gettwo(projectId: string, stepId: string ,params: any): Promise<any> {
|
|
return api.post(`/hot-opening-replications/tasks/${projectId}/steps/${stepId}/generate-image`, params);
|
|
}
|
|
|
|
// 第三步,生成视频提示词
|
|
export async function getthree(projectId: string, stepId: string ,params: any): Promise<any> {
|
|
return api.post(`/hot-opening-replications/tasks/${projectId}/steps/${stepId}/generate-video-prompt`, params);
|
|
}
|
|
// 第四步,生成视频
|
|
export async function getfour(projectId: string, stepId: string ,params: any): Promise<any> {
|
|
return api.post(`/hot-opening-replications/tasks/${projectId}/steps/${stepId}/generate-video`, params);
|
|
}
|
|
|
|
// 获取授权链接
|
|
export interface RequestOAuthParams {
|
|
open_type: number;
|
|
}
|
|
export async function requestOAuth(params: RequestOAuthParams): Promise<any> {
|
|
return api.post(`/user-oauth/request_oauth`, params);
|
|
}
|
|
|
|
// 巨量授权回调
|
|
export interface JuliangCallbackParams {
|
|
auth_code: string;
|
|
state: string;
|
|
app_id?: string;
|
|
material_auth_status?: string;
|
|
scope?: string;
|
|
uid?: string;
|
|
}
|
|
export async function juliang_callback(params: JuliangCallbackParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
query.set('auth_code', params.auth_code);
|
|
query.set('state', params.state);
|
|
if (params.app_id) query.set('app_id', params.app_id);
|
|
if (params.material_auth_status) query.set('material_auth_status', params.material_auth_status);
|
|
if (params.scope) query.set('scope', params.scope);
|
|
if (params.uid) query.set('uid', params.uid);
|
|
return api.get(`/user-oauth/juliang_callback?${query.toString()}`);
|
|
}
|
|
|
|
// 授权列表
|
|
export interface OAuthListParams {
|
|
account_userid?: string;
|
|
open_type?: number;
|
|
account_id?: string;
|
|
page?: number;
|
|
page_size?: number;
|
|
}
|
|
export async function getOAuthList(params: OAuthListParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params.account_userid) query.set('account_userid', params.account_userid);
|
|
if (params.open_type !== undefined) query.set('open_type', String(params.open_type));
|
|
if (params.account_id) query.set('account_id', params.account_id);
|
|
if (params.page !== undefined) query.set('page', String(params.page));
|
|
if (params.page_size !== undefined) query.set('page_size', String(params.page_size));
|
|
return api.get(`/user-oauth/oauth_list?${query.toString()}`);
|
|
}
|
|
|
|
// 前测模板列表
|
|
export interface PreTestListParams {
|
|
platform?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
}
|
|
export async function getPreTestList(params?: PreTestListParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params.platform) query.set('platform', params.platform);
|
|
if (params.page !== undefined) query.set('page', String(params.page));
|
|
if (params.pageSize !== undefined) query.set('page_size', String(params.pageSize));
|
|
return api.get(`/pre-test-template/list?${query.toString()}`);
|
|
}
|
|
|
|
// 获取前测字段列表
|
|
export async function getPreTestFields(): Promise<any> {
|
|
return api.get(`/pre-test-template/fields`);
|
|
}
|
|
|
|
// 创建前测模板
|
|
export async function createPreTest(params: any): Promise<any> {
|
|
return api.post(`/pre-test-template/create`, params);
|
|
}
|
|
|
|
// 前测模板详情
|
|
export async function getPreTestDetail(templateId: string): Promise<any> {
|
|
return api.get(`/pre-test-template/select/${templateId}`);
|
|
}
|
|
|
|
// 更新前测模板
|
|
export async function updatePreTest(templateId: string, params: any): Promise<any> {
|
|
return api.post(`/pre-test-template/update/${templateId}`, params);
|
|
}
|
|
|
|
// 删除前测模板
|
|
export async function deletePreTest(templateId: string): Promise<any> {
|
|
return api.get(`/pre-test-template/delete/${templateId}`);
|
|
}
|
|
|
|
// 获取默认前测模板
|
|
export async function getDefaultPreTest(): Promise<any> {
|
|
return api.get(`/pre-test-template/default`);
|
|
}
|
|
// 修改第四步视频 AI 提词 JSON schema
|
|
export async function updateHotOpeningVideoPromptSchema(projectId: string, stepId: string, params: { prompt_schema: Record<string, any> }): Promise<any> {
|
|
return api.put(`/hot-opening-replications/tasks/${projectId}/steps/${stepId}/video-prompt-schema`, params);
|
|
}
|
|
// 镜头复刻
|
|
export async function createShotReplication(params: any): Promise<any> {
|
|
return api.post('/shot-replications/task-sets', params);
|
|
}
|
|
// 获取镜头复刻任务列表
|
|
export async function getShotReplicationList(page: number, page_size: number, keyword?: string): Promise<any> {
|
|
const url = keyword
|
|
? `/shot-replications/task-sets?page=${page}&page_size=${page_size}&keyword=${encodeURIComponent(keyword)}`
|
|
: `/shot-replications/task-sets?page=${page}&page_size=${page_size}`;
|
|
return api.get(url);
|
|
}
|
|
// 获取镜头复刻任务详情
|
|
export async function getShotReplicationDetail(taskSetId: string): Promise<any> {
|
|
return api.get(`/shot-replications/task-sets/${taskSetId}`);
|
|
}
|
|
// ai拆镜
|
|
export async function createRemoveLens(taskSetId: string, params: any): Promise<any> {
|
|
return api.post(`/shot-replications/task-sets/${taskSetId}/split-by-ai`, params);
|
|
}
|
|
// 手动分割
|
|
export async function splitCustom(taskSetId: string, params: any): Promise<any> {
|
|
return api.post(`/shot-replications/task-sets/${taskSetId}/split-custom`, params);
|
|
}
|
|
// 拆镜列表
|
|
export async function Removelist(taskSetId: string, page: number = 1, pageSize: number = 20): Promise<any> {
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('page_size', String(pageSize));
|
|
return api.get(`/shot-replications/task-sets/${taskSetId}/segments?${params.toString()}`);
|
|
}
|
|
// 生成视频
|
|
export async function removeCreate(recordId: string, params: any): Promise<any> {
|
|
return api.post(`/v2/shot-replications/segments/${recordId}/replication-projects`, params);
|
|
}
|
|
// 获取拆镜复刻项目详情。版本必须明确传入,禁止任何异常回退 V1。
|
|
export async function removeDetail(id: string, flowVersion: 'v1' | 'v2'): Promise<any> {
|
|
return flowVersion === 'v2'
|
|
? api.get(`/v2/shot-replications/projects/${id}`)
|
|
: api.get(`/shot-replications/projects/${id}`);
|
|
}
|
|
|
|
export async function retryShotVideoPromptV2(
|
|
projectId: string,
|
|
stepId: string,
|
|
params: RetryVideoPromptV2Params,
|
|
): Promise<any> {
|
|
return api.post(`/v2/shot-replications/projects/${projectId}/steps/${stepId}/retry-video-prompt`, params);
|
|
}
|
|
|
|
|
|
export async function updateShotVideoPromptSchemaV2(projectId: string, stepId: string, params: any): Promise<any> {
|
|
return api.put(`/v2/shot-replications/projects/${projectId}/steps/${stepId}/video-prompt-schema`, params);
|
|
}
|
|
|
|
export async function generateShotVideoV2(projectId: string, stepId: string): Promise<any> {
|
|
return api.post(`/v2/shot-replications/projects/${projectId}/steps/${stepId}/generate-video`);
|
|
}
|
|
// 第一步,生成提示词
|
|
export async function removeone(projectId: string, stepId: string): Promise<any> {
|
|
return api.post(`/shot-replications/projects/${projectId}/steps/${stepId}/generate-image-prompt`);
|
|
}
|
|
// 修改图片提示词
|
|
export async function updateShotImagePrompt(projectId: string, stepId: string, params: any): Promise<any> {
|
|
return api.put(`/shot-replications/projects/${projectId}/steps/${stepId}/image-prompt`, params);
|
|
}
|
|
// 修改视频提示词
|
|
export async function updateShotVideoPromptSchema(projectId: string, stepId: string, params: any): Promise<any> {
|
|
return api.put(`/shot-replications/projects/${projectId}/steps/${stepId}/video-prompt-schema`, params);
|
|
}
|
|
// 第二步,生成图片
|
|
export async function removetwo(projectId: string, stepId: string ,params: any): Promise<any> {
|
|
return api.post(`/shot-replications/projects/${projectId}/steps/${stepId}/generate-image`, params);
|
|
}
|
|
// 第三步,生成视频提示词
|
|
export async function removethree(projectId: string, stepId: string ,params: any): Promise<any> {
|
|
return api.post(`/shot-replications/projects/${projectId}/steps/${stepId}/generate-video-prompt`, params);
|
|
}
|
|
// 第四步,生成视频
|
|
export async function removefour(projectId: string, stepId: string ,params: any): Promise<any> {
|
|
return api.post(`/shot-replications/projects/${projectId}/steps/${stepId}/generate-video`, params);
|
|
}
|
|
// 重新分析
|
|
export async function reanalyzeShotReplication(taskSetId: string): Promise<any> {
|
|
return api.post(`/shot-replications/task-sets/${taskSetId}/reanalyze`);
|
|
}
|
|
// 删除片段
|
|
export async function deleteSegment(segmentId: string): Promise<void> {
|
|
await api.delete(`/shot-replications/segments/${segmentId}`);
|
|
}
|
|
// 重新分析片段
|
|
export async function reanalyzeSegment(segmentId: string): Promise<any> {
|
|
return api.post(`/shot-replications/segments/${segmentId}/reanalyze`);
|
|
}
|
|
|
|
export async function retrySplit(segmentId: string): Promise<any> {
|
|
return api.post(`/shot-replications/segments/${segmentId}/retry-split`);
|
|
}
|
|
|
|
// 删除拆镜项目
|
|
export async function deleteShotReplicationProject(taskSetId: string): Promise<void> {
|
|
await api.delete(`/shot-replications/task-sets/${taskSetId}`);
|
|
}
|
|
// 删除爆款开头复刻任务
|
|
export async function deleteHotOpeningReplicationTask(taskId: string, flowVersion?: string): Promise<void> {
|
|
if (flowVersion === 'v2') {
|
|
await api.delete(`/v2/hot-opening-replications/tasks/${taskId}`);
|
|
return;
|
|
}
|
|
await api.delete(`/hot-opening-replications/tasks/${taskId}`);
|
|
}
|
|
// 获取地区信息
|
|
export interface GetAreaParams {
|
|
level?: string;
|
|
parent_code?: string;
|
|
}
|
|
export async function getArea(params?: GetAreaParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params?.level) query.set('level', params.level);
|
|
if (params?.parent_code) query.set('parent_code', params.parent_code);
|
|
return api.get(`/pre-test-template/getArea?${query.toString()}`);
|
|
}
|
|
// ── Upload Material ───────────────────────────────────────
|
|
export interface AsyncBatchUploadTask {
|
|
advertiser_ids: string[];
|
|
resource_ids: string[];
|
|
oauth_id: string;
|
|
is_pre_test: string;
|
|
pre_test_template: string;
|
|
source_model: string;
|
|
}
|
|
export interface AsyncBatchUploadParams {
|
|
tasks: AsyncBatchUploadTask[];
|
|
}
|
|
export async function asyncBatchUploadMaterial(params: AsyncBatchUploadParams): Promise<any> {
|
|
return api.post('/upload-material/async-batch-upload', params);
|
|
}
|
|
// 获取上传历史
|
|
// /api/upload-material/upload-history
|
|
export interface UploadHistoryParams {
|
|
status?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
}
|
|
export async function getUploadHistory(params: UploadHistoryParams): Promise<any> {
|
|
const searchParams = new URLSearchParams();
|
|
if (params.status) searchParams.set('status', params.status);
|
|
if (params.page) searchParams.set('page', String(params.page));
|
|
if (params.pageSize) searchParams.set('page_size', String(params.pageSize));
|
|
const query = searchParams.toString();
|
|
return api.get(`/upload-material/upload-history${query ? `?${query}` : ''}`);
|
|
}
|
|
export interface UploadFilenames {
|
|
source_id: string;
|
|
file_name: string;
|
|
}
|
|
export interface UpdateFilenameParams {
|
|
filenames: UploadFilenames[];
|
|
}
|
|
// 上传文件名
|
|
export async function updateFilename(params: UpdateFilenameParams): Promise<any> {
|
|
return api.post('/upload-material/batch-update-filename', params);
|
|
}
|
|
// 查询素材消耗列表
|
|
export interface MaterialConsumpListParams {
|
|
advertiser_id?: string;
|
|
consume_date?: [string, string];
|
|
page?: number;
|
|
page_size?: number;
|
|
}
|
|
export async function getMaterialConsumpList(params: MaterialConsumpListParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params.advertiser_id) query.set('advertiser_id', params.advertiser_id);
|
|
if (params.consume_date !== undefined) query.set('consume_date', params.consume_date[0] + ',' + params.consume_date[1]);
|
|
if (params.page !== undefined) query.set('page', String(params.page));
|
|
if (params.page_size !== undefined) query.set('page_size', String(params.page_size));
|
|
return api.get(`/material-consumption/list?${query.toString()}`);
|
|
}
|
|
// 拉取消耗
|
|
export async function syncMaterialConsumption(params: { date: string; advertiser_id?: string }): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params.advertiser_id) query.set('advertiser_id', params.advertiser_id);
|
|
if (params.date) query.set('date', params.date);
|
|
return api.get(`/material-consumption/sync?${query.toString()}`);
|
|
}
|
|
// 获取消耗字段列表
|
|
export async function getMaterialConsumptionFields(): Promise<any> {
|
|
return api.get('/material-consumption/fields');
|
|
}
|
|
// ── Contact ────────────────────────────────────────────────
|
|
export interface ContactRequestParams {
|
|
phone: string;
|
|
company_name: string;
|
|
industry: string;
|
|
name: string;
|
|
message?: string;
|
|
}
|
|
export async function createContactRequest(params: ContactRequestParams): Promise<any> {
|
|
return api.post('/contact/request', params);
|
|
}
|
|
// 查询上传素材列表
|
|
export interface ResourcesMaterialListParams {
|
|
advertiser_id?: string;
|
|
material_id?: string;
|
|
upload_id?: string;
|
|
file_name?: string;
|
|
resource_type?: string; // image或者video
|
|
page?: number;
|
|
page_size?: number;
|
|
}
|
|
export async function getResourcesMaterialList(params: ResourcesMaterialListParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params.advertiser_id) query.set('advertiser_id', params.advertiser_id);
|
|
if (params.material_id) query.set('material_id', params.material_id);
|
|
if (params.upload_id) query.set('upload_id', params.upload_id);
|
|
if (params.file_name) query.set('file_name', params.file_name);
|
|
if (params.resource_type) query.set('resource_type', params.resource_type);
|
|
if (params.page !== undefined) query.set('page', String(params.page));
|
|
if (params.page_size !== undefined) query.set('page_size', String(params.page_size));
|
|
return api.get(`/resources-material/list?${query.toString()}`);
|
|
}
|
|
|
|
// home 获取各模块媒体
|
|
export async function getmedit(limit:number): Promise<any> {
|
|
return api.get(`/recent-generations?limit=${limit}&modules=project&modules=chat_ai&modules=hot_opening_replicate&modules=shot_replicate`);
|
|
}
|
|
export interface OpenTypeItem {
|
|
id: string;
|
|
openType: number;
|
|
typeName: string;
|
|
description: string;
|
|
thumb?: string;
|
|
}
|
|
export async function getOpenTypeAll(): Promise<{ data: OpenTypeItem[] }> {
|
|
return api.get('/open-type/open_type_all');
|
|
}
|
|
// 获取授权账户列表,支持按广告主ID、授权ID、广告账户名称筛选
|
|
export interface OAuthAccountParams {
|
|
advertiser_id: string;
|
|
oauth_id: string;
|
|
advertiser_name: string;
|
|
page?: number;
|
|
page_size?: number;
|
|
}
|
|
export async function getOAuthAccountList(params: OAuthAccountParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params.advertiser_id) query.set('advertiser_id', params.advertiser_id);
|
|
if (params.oauth_id) query.set('oauth_id', params.oauth_id);
|
|
if (params.advertiser_name) query.set('advertiser_name', params.advertiser_name);
|
|
if (params.page !== undefined) query.set('page', String(params.page));
|
|
if (params.page_size !== undefined) query.set('page_size', String(params.page_size));
|
|
return api.get(`/oauth-account/list?${query.toString()}`);
|
|
}
|
|
// 软删除授权账户
|
|
export interface DeleteOAuthAccountParams {
|
|
id: string;
|
|
}
|
|
export async function deleteOAuthAccount(params: DeleteOAuthAccountParams): Promise<any> {
|
|
const query = new URLSearchParams();
|
|
if (params.id) query.set('id', params.id);
|
|
return api.get(`/oauth-account/delete?${query.toString()}`);
|
|
}
|
|
// 获取用户全部授权账户列表
|
|
export async function getAllOAuthAccountList(): Promise<any> {
|
|
return api.post(`/upload-material/oauth_account_list`);
|
|
}
|
|
// 获取用户全部授权账户列表 resources_material_ids pre_test_template_id
|
|
export async function submitPreTest(params: { resources_material_ids: any[]; pre_test_template_id: string }): Promise<any> {
|
|
return api.post(`/resources-material/pre-commit`, params);
|
|
}
|
|
// 首页素材案例头
|
|
export async function getHomeCaseHeader(): Promise<any> {
|
|
return api.get(`/home-materials/categories`);
|
|
}
|
|
// 首页素材按钮资源
|
|
export async function getHomeCaseButton(id: string,limit:number=10): Promise<any> {
|
|
return api.get(`/home-materials?category_id=${id}&limit_per_category=${limit}&include_empty_categories=false&response_mode=grouped&page=1&page_size=20`);
|
|
}
|
|
export async function deleteResourcesMaterial(params:any): Promise<any> {
|
|
return api.delete(`/generation-ai/history/batch`, params);
|
|
}
|
|
|
|
// ── UploadResource History ───────────────────────────────
|
|
export interface UploadResourceMediaReferenceOut {
|
|
name?: string | null;
|
|
type: 'image' | 'video' | 'audio';
|
|
url: string;
|
|
label?: string | null;
|
|
duration?: number | null;
|
|
source: 'upload_resource';
|
|
uploadResourceId: string;
|
|
}
|
|
|
|
export interface UploadResourceHistoryItemOut {
|
|
id: string;
|
|
sourceType: 'upload_resource';
|
|
historySource: 'upload_resource';
|
|
historySourceLabel: string;
|
|
module: string;
|
|
moduleLabel: string;
|
|
resourceType: 'image' | 'video' | 'audio';
|
|
resourceTypeLabel: string;
|
|
resourceUrl: string;
|
|
displayUrl: string;
|
|
previewUrl: string;
|
|
imageUrl?: string | null;
|
|
videoUrl?: string | null;
|
|
audioUrl?: string | null;
|
|
fileName?: string | null;
|
|
fileExt?: string | null;
|
|
mimeType?: string | null;
|
|
fileSizeBytes: number;
|
|
durationSeconds?: number | null;
|
|
width?: number | null;
|
|
height?: number | null;
|
|
bindStatus: string;
|
|
deletePolicy: string;
|
|
deletable: boolean;
|
|
mediaReference: UploadResourceMediaReferenceOut;
|
|
createdAt?: string | null;
|
|
updatedAt?: string | null;
|
|
}
|
|
|
|
export interface UploadResourceHistoryDayGroupOut {
|
|
generatedDate: string;
|
|
total: number;
|
|
page: number;
|
|
items: UploadResourceHistoryItemOut[];
|
|
}
|
|
|
|
export interface UploadResourceHistoryGroupedOut {
|
|
totalDays: number;
|
|
page: number;
|
|
pageSize: number;
|
|
groups: UploadResourceHistoryDayGroupOut[];
|
|
}
|
|
|
|
export interface UploadResourceHistoryDayItemsOut {
|
|
generatedDate: string;
|
|
total: number;
|
|
page: number;
|
|
pageSize: number;
|
|
items: UploadResourceHistoryItemOut[];
|
|
}
|
|
|
|
export interface UploadResourceHistoryQueryParams {
|
|
resourceType?: 'image' | 'video' | 'audio' | '';
|
|
page?: number;
|
|
pageSize?: number;
|
|
keyword?: string;
|
|
scene?: 'record' | 'picker' | string;
|
|
}
|
|
|
|
function buildUploadResourceHistoryQuery(params: UploadResourceHistoryQueryParams = {}): string {
|
|
const query = new URLSearchParams();
|
|
if (params.resourceType) query.set('resource_type', params.resourceType);
|
|
if (params.page) query.set('page', String(params.page));
|
|
if (params.pageSize) query.set('page_size', String(params.pageSize));
|
|
if (params.keyword) query.set('keyword', params.keyword);
|
|
if (params.scene) query.set('scene', params.scene);
|
|
const qs = query.toString();
|
|
return qs ? `?${qs}` : '';
|
|
}
|
|
|
|
export async function getUploadResourceHistory(params: UploadResourceHistoryQueryParams = {}): Promise<UploadResourceHistoryGroupedOut> {
|
|
return api.get<UploadResourceHistoryGroupedOut>(`/upload-resources/history${buildUploadResourceHistoryQuery(params)}`);
|
|
}
|
|
|
|
export async function getUploadResourceHistoryItems(generatedDate: string, params: UploadResourceHistoryQueryParams = {}): Promise<UploadResourceHistoryDayItemsOut> {
|
|
return api.get<UploadResourceHistoryDayItemsOut>(`/upload-resources/history/${generatedDate}${buildUploadResourceHistoryQuery(params)}`);
|
|
}
|
|
|
|
export async function deleteUploadResourceHistoryBatch(resourceIds: string[]): Promise<any> {
|
|
return api.delete('/upload-resources/history/batch', { resource_ids: resourceIds });
|
|
}
|
|
|
|
|
|
export async function getPrivatePortraitConfig(): Promise<PrivatePortraitConfig> {
|
|
return api.get<PrivatePortraitConfig>('/private-portrait/config');
|
|
}
|
|
|
|
// ── Private Portrait Library ──────────────────────────────
|
|
export async function getPrivatePortraitProjects(params: { page?: number; pageSize?: number; keyword?: string; status?: string } = {}): Promise<PrivatePortraitProjectListOut> {
|
|
const query = new URLSearchParams();
|
|
query.set('page', String(params.page || 1));
|
|
query.set('page_size', String(params.pageSize || 20));
|
|
if (params.keyword) query.set('keyword', params.keyword);
|
|
if (params.status) query.set('status', params.status);
|
|
return api.get<PrivatePortraitProjectListOut>(`/private-portrait/projects?${query.toString()}`);
|
|
}
|
|
|
|
export async function createPrivatePortraitProject(payload: { name: string; description?: string | null; callbackRedirectUrl?: string | null }): Promise<PrivatePortraitProjectCreateWithValidateOut> {
|
|
return api.post<PrivatePortraitProjectCreateWithValidateOut>('/private-portrait/projects', {
|
|
name: payload.name,
|
|
description: payload.description || null,
|
|
callback_redirect_url: payload.callbackRedirectUrl || null,
|
|
});
|
|
}
|
|
|
|
export async function updatePrivatePortraitProject(projectId: string, payload: { name?: string; description?: string | null; status?: string }): Promise<PrivatePortraitProject> {
|
|
return api.put<PrivatePortraitProject>(`/private-portrait/projects/${projectId}`, payload);
|
|
}
|
|
|
|
export async function deletePrivatePortraitProject(projectId: string): Promise<void> {
|
|
await api.delete(`/private-portrait/projects/${projectId}`);
|
|
}
|
|
|
|
export async function createPrivatePortraitValidateSession(projectId: string, callbackRedirectUrl?: string): Promise<PrivatePortraitValidateSession> {
|
|
return api.post<PrivatePortraitValidateSession>(`/private-portrait/projects/${projectId}/validate-sessions`, { callback_redirect_url: callbackRedirectUrl || null });
|
|
}
|
|
|
|
export async function getPrivatePortraitValidateSession(sessionId: string): Promise<PrivatePortraitValidateSession> {
|
|
return api.get<PrivatePortraitValidateSession>(`/private-portrait/validate-sessions/${sessionId}`);
|
|
}
|
|
|
|
export async function createPrivatePortraitAsset(projectId: string, payload: { url: string; assetType?: string; name?: string | null; videoDuration?: number | null; videoCoverUrl?: string | null; fileSize?: number | null; mimeType?: string | null; uploadResourceId?: string | null }): Promise<PrivatePortraitAsset> {
|
|
return api.post<PrivatePortraitAsset>(`/private-portrait/projects/${projectId}/assets`, {
|
|
url: payload.url,
|
|
asset_type: payload.assetType || 'Image',
|
|
name: payload.name || null,
|
|
video_duration: payload.videoDuration ?? null,
|
|
video_cover_url: payload.videoCoverUrl || null,
|
|
file_size: payload.fileSize ?? null,
|
|
mime_type: payload.mimeType || null,
|
|
upload_resource_id: payload.uploadResourceId || null,
|
|
});
|
|
}
|
|
|
|
export async function getPrivatePortraitAssets(projectId: string, params: { page?: number; pageSize?: number; status?: string; keyword?: string; assetType?: string } = {}): Promise<PrivatePortraitAssetListOut> {
|
|
const query = new URLSearchParams();
|
|
query.set('page', String(params.page || 1));
|
|
query.set('page_size', String(params.pageSize || 20));
|
|
if (params.status) query.set('status', params.status);
|
|
if (params.keyword) query.set('keyword', params.keyword);
|
|
if (params.assetType) query.set('asset_type', params.assetType);
|
|
return api.get<PrivatePortraitAssetListOut>(`/private-portrait/projects/${projectId}/assets?${query.toString()}`);
|
|
}
|
|
|
|
export async function syncPrivatePortraitAsset(assetId: string): Promise<PrivatePortraitAsset> {
|
|
return api.post<PrivatePortraitAsset>(`/private-portrait/assets/${assetId}/sync`);
|
|
}
|
|
|
|
export async function deletePrivatePortraitAsset(assetId: string): Promise<void> {
|
|
await api.delete(`/private-portrait/assets/${assetId}`);
|
|
}
|
|
|
|
export async function getPrivatePortraitSelectableAssets(params: { projectId?: string; keyword?: string; page?: number; pageSize?: number; assetType?: string } = {}): Promise<PrivatePortraitSelectableAssetListOut> {
|
|
const query = new URLSearchParams();
|
|
query.set('page', String(params.page || 1));
|
|
query.set('page_size', String(params.pageSize || 20));
|
|
if (params.projectId) query.set('project_id', params.projectId);
|
|
if (params.keyword) query.set('keyword', params.keyword);
|
|
if (params.assetType) query.set('asset_type', params.assetType);
|
|
return api.get<PrivatePortraitSelectableAssetListOut>(`/private-portrait/selectable-assets?${query.toString()}`);
|
|
}
|
|
|
|
|
|
// ── Private Portrait Virtual Library ─────────────────────
|
|
export async function getPrivatePortraitVirtualConfig(): Promise<PrivatePortraitConfig> {
|
|
return api.get<PrivatePortraitConfig>('/private-portrait/virtual/config');
|
|
}
|
|
|
|
export async function getPrivatePortraitVirtualProjects(params: { page?: number; pageSize?: number; keyword?: string; status?: string } = {}): Promise<PrivatePortraitProjectListOut> {
|
|
const query = new URLSearchParams();
|
|
query.set('page', String(params.page || 1));
|
|
query.set('page_size', String(params.pageSize || 20));
|
|
if (params.keyword) query.set('keyword', params.keyword);
|
|
if (params.status) query.set('status', params.status);
|
|
return api.get<PrivatePortraitProjectListOut>(`/private-portrait/virtual-projects?${query.toString()}`);
|
|
}
|
|
|
|
export async function createPrivatePortraitVirtualProject(payload: { name: string; description?: string | null }): Promise<PrivatePortraitProject> {
|
|
return api.post<PrivatePortraitProject>('/private-portrait/virtual-projects', {
|
|
name: payload.name,
|
|
description: payload.description || null,
|
|
});
|
|
}
|
|
|
|
export async function updatePrivatePortraitVirtualProject(projectId: string, payload: { name?: string; description?: string | null; status?: string }): Promise<PrivatePortraitProject> {
|
|
return api.put<PrivatePortraitProject>(`/private-portrait/virtual-projects/${projectId}`, payload);
|
|
}
|
|
|
|
export async function deletePrivatePortraitVirtualProject(projectId: string): Promise<void> {
|
|
await api.delete(`/private-portrait/virtual-projects/${projectId}`);
|
|
}
|
|
|
|
export async function createPrivatePortraitVirtualAsset(projectId: string, payload: { url: string; assetType?: string; name?: string | null; videoDuration?: number | null; videoCoverUrl?: string | null; fileSize?: number | null; mimeType?: string | null; uploadResourceId?: string | null }): Promise<PrivatePortraitAsset> {
|
|
return api.post<PrivatePortraitAsset>(`/private-portrait/virtual-projects/${projectId}/assets`, {
|
|
url: payload.url,
|
|
asset_type: payload.assetType || 'Image',
|
|
name: payload.name || null,
|
|
video_duration: payload.videoDuration ?? null,
|
|
video_cover_url: payload.videoCoverUrl || null,
|
|
file_size: payload.fileSize ?? null,
|
|
mime_type: payload.mimeType || null,
|
|
upload_resource_id: payload.uploadResourceId || null,
|
|
});
|
|
}
|
|
|
|
export async function getPrivatePortraitVirtualAssets(projectId: string, params: { page?: number; pageSize?: number; status?: string; keyword?: string; assetType?: string } = {}): Promise<PrivatePortraitAssetListOut> {
|
|
const query = new URLSearchParams();
|
|
query.set('page', String(params.page || 1));
|
|
query.set('page_size', String(params.pageSize || 20));
|
|
if (params.status) query.set('status', params.status);
|
|
if (params.keyword) query.set('keyword', params.keyword);
|
|
if (params.assetType) query.set('asset_type', params.assetType);
|
|
return api.get<PrivatePortraitAssetListOut>(`/private-portrait/virtual-projects/${projectId}/assets?${query.toString()}`);
|
|
}
|
|
|
|
export async function getPrivatePortraitVirtualAsset(assetId: string): Promise<PrivatePortraitAsset> {
|
|
return api.get<PrivatePortraitAsset>(`/private-portrait/virtual-assets/${assetId}`);
|
|
}
|
|
|
|
export async function syncPrivatePortraitVirtualAsset(assetId: string): Promise<PrivatePortraitAsset> {
|
|
return api.post<PrivatePortraitAsset>(`/private-portrait/virtual-assets/${assetId}/sync`);
|
|
}
|
|
|
|
export async function deletePrivatePortraitVirtualAsset(assetId: string): Promise<void> {
|
|
await api.delete(`/private-portrait/virtual-assets/${assetId}`);
|
|
}
|
|
|
|
export async function getPrivatePortraitVirtualSelectableAssets(params: { projectId?: string; keyword?: string; page?: number; pageSize?: number; assetType?: string } = {}): Promise<PrivatePortraitSelectableAssetListOut> {
|
|
const query = new URLSearchParams();
|
|
query.set('page', String(params.page || 1));
|
|
query.set('page_size', String(params.pageSize || 20));
|
|
if (params.projectId) query.set('project_id', params.projectId);
|
|
if (params.keyword) query.set('keyword', params.keyword);
|
|
if (params.assetType) query.set('asset_type', params.assetType);
|
|
return api.get<PrivatePortraitSelectableAssetListOut>(`/private-portrait/virtual-selectable-assets?${query.toString()}`);
|
|
}
|
|
|
|
// ── Team Management APIs ──────────────────────────────
|
|
export async function getManagedTeam(): Promise<any> {
|
|
return api.get('/team/managed');
|
|
}
|
|
|
|
export async function getTeamMembers(page = 1, pageSize = 20): Promise<any> {
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('page_size', String(pageSize));
|
|
return api.get(`/team/members?${params.toString()}`);
|
|
}
|
|
|
|
export async function transferCredits(memberId: string, amount: number, direction: string = "increase", description?: string): Promise<void> {
|
|
await api.post(`/team/members/${memberId}/credits`, { target_user_id: memberId, amount, direction, description: description || null });
|
|
}
|
|
|
|
export async function getTeamInvitations(): Promise<any[]> {
|
|
return api.get('/team/invitations');
|
|
}
|
|
|
|
export async function createTeamInvitation(maxUses?: number, expiresAt?: string): Promise<any> {
|
|
return api.post('/team/invitations', { max_uses: maxUses || null, expires_at: expiresAt || null });
|
|
}
|
|
|
|
export async function revokeInvitation(invitationId: string): Promise<void> {
|
|
await api.delete(`/team/invitations/${invitationId}`);
|
|
}
|
|
|
|
export async function getPendingJoinRequests(status?: string): Promise<any[]> {
|
|
const url = status ? `/team/join-requests?status=${status}` : '/team/join-requests';
|
|
return api.get(url);
|
|
}
|
|
|
|
export async function handleJoinRequest(requestId: string, action: 'approve' | 'reject', note?: string): Promise<void> {
|
|
await api.post(`/team/join-requests/${requestId}`, { action, note: note || null });
|
|
}
|
|
|
|
export async function getJoinTeamInfo(code: string): Promise<any> {
|
|
return api.get(`/team/join-info?code=${encodeURIComponent(code)}`, { auth: true, skipAuthRedirect: true });
|
|
}
|
|
|
|
export async function getJoinTeamInfoPublic(code: string): Promise<any> {
|
|
return api.get(`/team/join-info/public?code=${encodeURIComponent(code)}`, false);
|
|
}
|
|
|
|
export async function submitJoinRequest(code: string): Promise<void> {
|
|
await api.post('/team/join', { invitation_code: code });
|
|
}
|
|
|
|
export async function getTeamCreditRecords(params: {
|
|
page?: number;
|
|
pageSize?: number;
|
|
userId?: string;
|
|
phone?: string;
|
|
recordType?: string;
|
|
startDate?: string;
|
|
endDate?: string;
|
|
}): Promise<any> {
|
|
const p = new URLSearchParams();
|
|
if (params.page) p.set('page', String(params.page));
|
|
if (params.pageSize) p.set('page_size', String(params.pageSize));
|
|
if (params.userId) p.set('user_id', params.userId);
|
|
if (params.phone) p.set('phone', params.phone);
|
|
if (params.recordType) p.set('record_type', params.recordType);
|
|
if (params.startDate) p.set('start_date', params.startDate);
|
|
if (params.endDate) p.set('end_date', params.endDate);
|
|
return api.get(`/team/credit-records?${p.toString()}`);
|
|
}
|
|
|
|
export function getTeamCreditExportUrl(params: {
|
|
phone?: string;
|
|
recordType?: string;
|
|
startDate?: string;
|
|
endDate?: string;
|
|
}): string {
|
|
const p = new URLSearchParams();
|
|
if (params.phone) p.set('phone', params.phone);
|
|
if (params.recordType) p.set('record_type', params.recordType);
|
|
if (params.startDate) p.set('start_date', params.startDate);
|
|
if (params.endDate) p.set('end_date', params.endDate);
|
|
const base = (import.meta as any).env?.VITE_API_BASE || 'http://localhost:8000';
|
|
return `${base}/api/team/credit-records/export?${p.toString()}`;
|
|
}
|