import { httpApp } from "@/plugins/axiosIndex";
import { object2QueryString } from "@/utils/utils";
import { pickBy } from "lodash-es";

export function uploadFile({ file, md5 }) {
  const form = new FormData();
  form.append("file", file);
  return httpApp.post(
    "/api/admin/sys/file/upload?" + object2QueryString({ type: "frontend" }),
    form,
    { headers: { "Content-Type": "multipart/form-data", md5: md5 } }
  );
}

export function downloadFile({ id = "", type = "" }) {
  const data = pickBy({ id, type }, (v) => v !== "");
  return httpApp.post(
    "/api/admin/sys/file/download?" +
      object2QueryString({ ...data, type: type })
  );
}
