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);
var tx_cos_exports = {};
__export(tx_cos_exports, {
  default: () => tx_cos_default
});
module.exports = __toCommonJS(tx_cos_exports);
var import_node_util = require("node:util");
var import_constants = require("../constants");
var import_utils = require("../utils");
var tx_cos_default = {
  filenameKey: "url",
  make(storage) {
    const createTxCosStorage = require("multer-cos");
    return new createTxCosStorage({
      cos: storage.options,
      filename: (0, import_utils.cloudFilenameGetter)(storage)
    });
  },
  defaults() {
    return {
      title: "\u817E\u8BAF\u4E91\u5BF9\u8C61\u5B58\u50A8",
      type: import_constants.STORAGE_TYPE_TX_COS,
      name: "tx-cos-1",
      baseUrl: process.env.TX_COS_STORAGE_BASE_URL,
      options: {
        Region: process.env.TX_COS_REGION,
        SecretId: process.env.TX_COS_SECRET_ID,
        SecretKey: process.env.TX_COS_SECRET_KEY,
        Bucket: process.env.TX_COS_BUCKET
      }
    };
  },
  async delete(storage, records) {
    const { cos } = this.make(storage);
    const { Deleted } = await (0, import_node_util.promisify)(cos.deleteMultipleObject)({
      Region: storage.options.Region,
      Bucket: storage.options.Bucket,
      Objects: records.map((record) => ({ Key: `${record.path}/${record.filename}` }))
    });
    return [
      Deleted.length,
      records.filter((record) => !Deleted.find((item) => item.Key === `${record.path}/${record.filename}`))
    ];
  }
};
