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 ali_oss_exports = {};
__export(ali_oss_exports, {
  default: () => ali_oss_default
});
module.exports = __toCommonJS(ali_oss_exports);
var import_constants = require("../constants");
var import_utils = require("../utils");
var ali_oss_default = {
  make(storage) {
    const createAliOssStorage = require("multer-aliyun-oss");
    return new createAliOssStorage({
      config: storage.options,
      filename: (0, import_utils.cloudFilenameGetter)(storage)
    });
  },
  defaults() {
    return {
      title: "\u963F\u91CC\u4E91\u5BF9\u8C61\u5B58\u50A8",
      type: import_constants.STORAGE_TYPE_ALI_OSS,
      name: "ali-oss-1",
      baseUrl: process.env.ALI_OSS_STORAGE_BASE_URL,
      options: {
        region: process.env.ALI_OSS_REGION,
        accessKeyId: process.env.ALI_OSS_ACCESS_KEY_ID,
        accessKeySecret: process.env.ALI_OSS_ACCESS_KEY_SECRET,
        bucket: process.env.ALI_OSS_BUCKET
      }
    };
  },
  async delete(storage, records) {
    const { client } = this.make(storage);
    const { deleted } = await client.deleteMulti(records.map((record) => `${record.path}/${record.filename}`));
    return [
      deleted.length,
      records.filter((record) => !deleted.find((item) => item.Key === `${record.path}/${record.filename}`))
    ];
  }
};
