var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/dataSourceComponents/fields/Upload/serve.ts
var serve_exports = {};
__export(serve_exports, {
  getMediaTypeList: () => getMediaTypeList,
  useMediaConfig: () => useMediaConfig,
  useMediaTypes: () => useMediaTypes
});
module.exports = __toCommonJS(serve_exports);
var import_ahooks = require("ahooks");
var import_utils = require("./utils");
var import_utils2 = require("../../../table/utils");
var getMediaTypeList = async () => {
  const { data } = await import_utils2.request.getRequest().get(
    `/media_type:list`,
    {},
    {
      isNocobase: true,
      fullResult: true,
      headers: {
        "x-data-source": "pisell2"
      }
    }
  );
  return data;
};
var getMediaConfig = async () => {
  const data = await import_utils2.request.getRequest().get(`/core/module/media/config`, {});
  return data;
};
var useMediaConfig = () => {
  const { data } = (0, import_ahooks.useRequest)(getMediaConfig, {
    cacheKey: "media-config",
    staleTime: 1e3 * 60 * 5,
    // 5分钟后数据过期
    cacheTime: 1e3 * 60 * 60
    // 1小时后清除缓存
  });
  return { data };
};
var useMediaTypes = () => {
  const { data } = (0, import_ahooks.useRequest)(getMediaTypeList, {
    cacheKey: "media-type",
    staleTime: 1e3 * 60 * 5,
    // 5分钟后数据过期
    cacheTime: 1e3 * 60 * 60
    // 1小时后清除缓存
  });
  const getExtensionsByIds = (ids) => {
    const extensions = [];
    (data || []).forEach((item) => {
      if (ids == null ? void 0 : ids.includes(item.id)) {
        extensions.push(
          ...(item.extensions || []).map((item2) => (0, import_utils.getPointSuffix)(item2))
        );
      }
    });
    return extensions;
  };
  const getMaxSizeByIds = (ids) => {
    const maxSizeMap = {};
    (data || []).forEach((item) => {
      if (ids == null ? void 0 : ids.includes(item.id)) {
        item.extensions.forEach((extension) => {
          const key = (0, import_utils.getPointSuffix)(extension);
          maxSizeMap[key] = item.maxsize;
        });
      }
    });
    return maxSizeMap;
  };
  return { data, getExtensionsByIds, getMaxSizeByIds };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getMediaTypeList,
  useMediaConfig,
  useMediaTypes
});
