"use strict";
const common_vendor = require("../../vendor.js");
const common_js_cache_storage = require("../cache/storage.js");
const common_js_net_mainUrl = require("./mainUrl.js");
const PROJECT_URL_MAP = {
  operator: common_js_net_mainUrl.operatorUrl,
  copyright: common_js_net_mainUrl.copyrightUrl,
  plug: common_js_net_mainUrl.operatorPlug,
  aiShop: common_js_net_mainUrl.aiShopUrl
  // 添加新项目只需在此扩展
};
function request(url, method = "GET", data = {}, project = "copyright", needToken = true) {
  const baseUrl = PROJECT_URL_MAP[project] || common_js_net_mainUrl.copyrightUrl;
  const requestUrl = baseUrl + url;
  const headers = {
    "Content-Type": "application/json"
  };
  if (needToken) {
    const token = common_js_cache_storage.get("token");
    if (token) {
      headers.Auth = `Bearer ${token}`;
    }
  }
  const requestConfig = {
    url: requestUrl.toString(),
    method: method.toUpperCase(),
    data,
    header: headers,
    timeout: 1e4,
    dataType: "json"
  };
  return new Promise(function(resolve, reject) {
    common_vendor.index.request({
      ...requestConfig,
      success(res) {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          common_vendor.index.__f__("log", "at common/js/net/http.js:61", "错误success");
          reject(res.data);
        }
      },
      fail(err) {
        common_vendor.index.__f__("log", "at common/js/net/http.js:66", "错误");
        if (err.data) {
          reject(err.data);
        } else {
          reject(err);
        }
      }
    });
  });
}
exports.request = request;
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/common/js/net/http.js.map
