mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-06-29 03:01:30 +08:00
feat(offline-downloads): implement offline download
This commit is contained in:
@@ -73,4 +73,5 @@ async function request<T = any>(url: string, options: RequestOptions = {}): Prom
|
||||
export { vfsApi, type VfsEntry, type DirListing } from './vfs';
|
||||
export { adaptersApi, type AdapterItem, type AdapterTypeField, type AdapterTypeMeta } from './adapters';
|
||||
export { shareApi, type ShareInfo, type ShareInfoWithPassword } from './share';
|
||||
export { offlineDownloadsApi, type OfflineDownloadTask, type OfflineDownloadCreate, type TaskProgress } from './offlineDownloads';
|
||||
export default request;
|
||||
|
||||
35
web/src/api/offlineDownloads.ts
Normal file
35
web/src/api/offlineDownloads.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import request from './client';
|
||||
|
||||
export interface TaskProgress {
|
||||
stage?: string | null;
|
||||
percent?: number | null;
|
||||
bytes_total?: number | null;
|
||||
bytes_done?: number | null;
|
||||
detail?: string | null;
|
||||
}
|
||||
|
||||
export interface OfflineDownloadTask {
|
||||
id: string;
|
||||
name: string;
|
||||
status: 'pending' | 'running' | 'success' | 'failed';
|
||||
result?: any;
|
||||
error?: string | null;
|
||||
task_info: Record<string, any>;
|
||||
progress?: TaskProgress | null;
|
||||
meta?: Record<string, any> | null;
|
||||
}
|
||||
|
||||
export interface OfflineDownloadCreate {
|
||||
url: string;
|
||||
dest_dir: string;
|
||||
filename: string;
|
||||
}
|
||||
|
||||
export const offlineDownloadsApi = {
|
||||
create: (payload: OfflineDownloadCreate) => request<{ task_id: string }>('/offline-downloads/', {
|
||||
method: 'POST',
|
||||
json: payload,
|
||||
}),
|
||||
list: () => request<OfflineDownloadTask[]>('/offline-downloads/'),
|
||||
detail: (taskId: string) => request<OfflineDownloadTask>(`/offline-downloads/${taskId}`),
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import request from './client';
|
||||
import type { TaskProgress } from './offlineDownloads';
|
||||
|
||||
export interface AutomationTask {
|
||||
id: number;
|
||||
@@ -21,6 +22,8 @@ export interface QueuedTask {
|
||||
result?: any;
|
||||
error?: string;
|
||||
task_info: Record<string, any>;
|
||||
progress?: TaskProgress | null;
|
||||
meta?: Record<string, any> | null;
|
||||
}
|
||||
|
||||
export const tasksApi = {
|
||||
@@ -29,4 +32,4 @@ export const tasksApi = {
|
||||
update: (id: number, payload: AutomationTaskUpdate) => request<AutomationTask>(`/tasks/${id}`, { method: 'PUT', json: payload }),
|
||||
remove: (id: number) => request<void>(`/tasks/${id}`, { method: 'DELETE' }),
|
||||
getQueue: () => request<QueuedTask[]>('/tasks/queue'),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user