mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 23:06:36 +08:00
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.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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})`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user