recycleBin.ts 1.77 KB
import { service as http } from "@/utils/request";
import { transformFileList } from "./files";

// 获取回收站列表
export const listTrash = () => {
  return http.get("/files/trash");
};

// 清空回收站
export const emptyTrash = () => {
  return http.delete("/files/trash");
};

// 批量还原
export const restoreBatch = (ids: (string | number)[]) => {
  return http.post("/files/restore-batch", { ids });
};

// 回收站批量删除(永久删除)
export const trashDeleteBatch = (ids: (string | number)[]) => {
  return http.delete("/files/trash-delete-batch", { data: { ids } });
};

export const recycleBinApi = {
  async getList(_params: any = {}) {
    return await listTrash().then((res: any) => {
      const rawItems = res.data || [];
      const transformedItems = transformFileList(rawItems);
      return {
        code: 200,
        ...res,
        data: {
          items: transformedItems,
          total: transformedItems.length,
        },
      };
    });
  },

  async restoreItems(payload: {
    ids: (string | number)[];
    conflictStrategy?: string;
  }) {
    return restoreBatch(payload.ids).then((res: any) => ({
      code: 200,
      ...res,
      data: {
        successCount: payload.ids.length,
        failCount: 0,
        failedItems: [],
      },
    }));
  },

  async deleteItems(ids: (string | number)[]) {
    return trashDeleteBatch(ids).then((res: any) => ({
      code: 200,
      ...res,
    }));
  },

  async clearAll() {
    return await emptyTrash().then((res: any) => ({
      code: 200,
      ...res,
    }));
  },

  async getFolderContent(_folderId: string | number) {
    // 实现获取文件夹内容的逻辑
    return Promise.resolve({ code: 200, data: [] });
  },

  async getStatistics() {
    // 实现获取统计信息的逻辑
  },
};