56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
// app/lib/services/file.ts
|
|
import axios from "axios";
|
|
|
|
interface CreateFileParams {
|
|
name: string;
|
|
type: "file" | "folder";
|
|
parentId?: string;
|
|
}
|
|
|
|
interface UpdateFileParams {
|
|
id: string;
|
|
name: string;
|
|
}
|
|
|
|
export const FileService = {
|
|
async getFileTree() {
|
|
try {
|
|
const response = await axios.get("/api/files");
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error("Error fetching file tree:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
async createFile(params: CreateFileParams) {
|
|
try {
|
|
const response = await axios.post("/api/files", params);
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error("Error creating file:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
async updateFile(params: UpdateFileParams) {
|
|
try {
|
|
const response = await axios.put(`/api/files/${params.id}`, params);
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error("Error updating file:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
async deleteFile(id: string) {
|
|
try {
|
|
const response = await axios.delete(`/api/files/${id}`);
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error("Error deleting file:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
};
|