//所有的接口请求
import axios from "axios";
export const cdn = "";
// import.meta.env.VITE_ROUTER_BASE
// ? ""
// : "https://assets.le5lecdn.com";

export const upCdn = import.meta.env.VITE_ROUTER_BASE
  ? ""
  : "https://drive.le5lecdn.com";

export async function delImage(image: string) {
  if (image.startsWith(upCdn)) {
    await axios.delete("/file" + image.replace(upCdn, ""));
  } else {
    await axios.delete(`${image}`);
  }
  return true;
}

export async function getFolders(query: any) {
  const folder: any = await axios.post("/api/data/folders/get", {
    query,
  });
  if (folder.error) {
    return;
  } else {
    return folder;
  }
}

export async function updateFolders(data: any) {
  const folder: any = await axios.post("/api/data/folders/update", data);
  if (folder.error) {
    return;
  } else {
    return folder;
  }
}

export async function addCollection(collection: string, data: any) {
  return await axios.post(`/api/data/${collection}/add`, data); // 新增
}

export async function updateCollection(collection: string, data: any) {
  return await axios.post(`/api/data/${collection}/update`, data); // 新增
}

// export async function addCollection(collection: string, data: any) {
//   return await axios.post(`/data/${collection}/add`, data); // 新增
// }
export async function getLe5le2d(id: string) {
  return await axios.post("/api/data/le5le2d/get", {
    id,
  });
}

export async function getComponents(id: string) {
  return await axios.post(`/api/data/le5le2d-components/get`, {
    id,
  });
}

export async function getComponentsList(data: any, config: any) {
  return await axios.post("/api/data/le5le2d-components/list", data, config);
}
