104 lines
2.5 KiB
TypeScript
104 lines
2.5 KiB
TypeScript
import { apiClient } from "./client";
|
|
|
|
export interface ArchiveItem {
|
|
id: string;
|
|
videoId: string;
|
|
title: string;
|
|
description: string;
|
|
thumbnail: string;
|
|
url: string;
|
|
category: string;
|
|
downloadPath: string;
|
|
networkSharePath?: string;
|
|
downloadDate: string;
|
|
duration: string;
|
|
views: string;
|
|
channel: string;
|
|
size?: string;
|
|
}
|
|
|
|
export interface ArchiveResponse {
|
|
items: ArchiveItem[];
|
|
total: number;
|
|
page: number;
|
|
hasMore: boolean;
|
|
}
|
|
|
|
export interface ArchiveFilters {
|
|
page?: number;
|
|
limit?: number;
|
|
category?: string;
|
|
search?: string;
|
|
startDate?: string;
|
|
endDate?: string;
|
|
}
|
|
|
|
export async function getArchive(
|
|
filters: ArchiveFilters = {},
|
|
): Promise<ArchiveResponse> {
|
|
const response = await apiClient.get<any>("/archive", {
|
|
params: filters,
|
|
});
|
|
// Handle both server response formats (archive vs items)
|
|
const archiveData = response.data.archive || response.data.items || [];
|
|
return {
|
|
items: archiveData,
|
|
total: response.data.total || archiveData.length,
|
|
page: filters.page || 1,
|
|
hasMore: archiveData.length >= (filters.limit || 24),
|
|
};
|
|
}
|
|
|
|
export async function getArchiveItem(videoId: string): Promise<ArchiveItem> {
|
|
const response = await apiClient.get<ArchiveItem>(`/archive/${videoId}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function deleteFromArchive(videoId: string): Promise<void> {
|
|
await apiClient.delete(`/archive/${videoId}`);
|
|
}
|
|
|
|
export async function clearArchive(): Promise<void> {
|
|
await apiClient.delete("/archive");
|
|
}
|
|
|
|
export async function getArchiveStats(): Promise<{
|
|
total: number;
|
|
totalSize: string;
|
|
categories: Record<string, number>;
|
|
}> {
|
|
const response = await apiClient.get<{
|
|
total: number;
|
|
totalSize: string;
|
|
categories: Record<string, number>;
|
|
}>("/archive/stats");
|
|
return response.data;
|
|
}
|
|
|
|
export async function getCategoryList(): Promise<string[]> {
|
|
const response = await apiClient.get<string[]>("/archive/categories");
|
|
return response.data;
|
|
}
|
|
|
|
export async function exportArchive(
|
|
format: "json" | "csv" = "json",
|
|
): Promise<Blob> {
|
|
const response = await apiClient.get("/archive/export", {
|
|
params: { format },
|
|
responseType: "blob",
|
|
});
|
|
return response.data;
|
|
}
|
|
|
|
export async function importArchive(
|
|
file: File,
|
|
): Promise<{ success: boolean; imported: number }> {
|
|
const formData = new FormData();
|
|
formData.append("file", file);
|
|
const response = await apiClient.post<{ success: boolean; imported: number }>(
|
|
"/archive/import",
|
|
formData,
|
|
);
|
|
return response.data;
|
|
}
|