Files
OpenFlare/atsf_server/web/features/files/api/files.ts
T
ryan 4f8970ff5c feat: add user management features including user creation, editing, and role management
- Implemented user API functions for fetching, creating, updating, and managing users.
- Created a UsersPage component for displaying and managing users with search and pagination.
- Added types for user data and mutation payloads.
- Introduced a LegacyRouteRedirect component for handling legacy routes.
- Defined settings-related types for better type safety in settings management.
2026-03-11 15:40:41 +08:00

57 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { apiRequest, getApiUrl } from '@/lib/api/client';
import type { FileItem } from '@/features/files/types';
export function getFiles(page: number) {
return apiRequest<FileItem[]>(`/file/?p=${page}`);
}
export function searchFiles(keyword: string) {
return apiRequest<FileItem[]>(`/file/search?keyword=${encodeURIComponent(keyword)}`);
}
export function deleteFile(id: number) {
return apiRequest<void>(`/file/${id}`, {
method: 'DELETE',
});
}
export function buildFileDownloadUrl(link: string) {
return `/upload/${link}`;
}
export function buildFileAbsoluteUrl(link: string) {
if (typeof window === 'undefined') {
return buildFileDownloadUrl(link);
}
return new URL(buildFileDownloadUrl(link), window.location.origin).toString();
}
export async function uploadFiles(files: File[], description?: string) {
const formData = new FormData();
files.forEach((file) => {
formData.append('file', file);
});
if (description) {
formData.append('description', description);
}
const response = await fetch(getApiUrl('/file/'), {
method: 'POST',
credentials: 'include',
body: formData,
});
const payload = (await response.json()) as {
success: boolean;
message: string;
};
if (!response.ok || !payload.success) {
throw new Error(payload.message || `上传失败(${response.status})`);
}
}