import { cosConfig } from "../../../../lib/useAppState.js";
import toast from "react-hot-toast";
const deleteMedia = (url) => {
  console.log("deleteMedia-->", url);
  const key = url.replace(/^https:\/\/[^/]+/, "");
  console.log("deleteMedia-->", key);
  cos.deleteObject({
    Bucket: cosConfig.Bucket,
    Region: cosConfig.Region,
    Key: key
  }, (err, data) => {
    if (err && err.error)
      ;
    else if (err)
      ;
    else {
      toast.success("\u5DF2\u6210\u529F\u5220\u9664");
    }
  });
};
const getAuthorization = function(options, callback) {
  const authorization = COS.getAuthorization({
    SecretId: cosConfig.SecretId,
    SecretKey: cosConfig.SecretKey,
    Method: options.Method,
    Pathname: options.Pathname,
    Query: options.Query,
    Headers: options.Headers,
    Expires: 60
  });
  callback({
    Authorization: authorization
  });
};
let COS;
if (typeof window !== "undefined" || typeof document !== "undefined") {
  COS = require("cos-js-sdk-v5");
}
const cos = typeof window !== "undefined" ? new COS({
  getAuthorization
}) : {};
export {
  cos,
  deleteMedia
};
//# sourceMappingURL=sdk.js.map
