"use strict";
const common_vendor = require("../../../common/vendor.js");
const sheep_config_index = require("../../config/index.js");
require("../../request/index.js");
const FileApi = {
  // 上传文件
  uploadFile: (file) => {
    common_vendor.index.getStorageSync("token");
    common_vendor.index.showLoading({
      title: "上传中"
    });
    return new Promise((resolve, reject) => {
      common_vendor.index.uploadFile({
        url: sheep_config_index.baseUrl + sheep_config_index.apiPath + "/infra/file/upload",
        filePath: file,
        name: "file",
        header: {
          // Accept: 'text/json',
          Accept: "*/*",
          "tenant-id": "1"
          // Authorization:  'Bearer test247',
        },
        success: (uploadFileRes) => {
          let result = JSON.parse(uploadFileRes.data);
          if (result.error === 1) {
            common_vendor.index.showToast({
              icon: "none",
              title: result.msg
            });
          } else {
            return resolve(result);
          }
        },
        fail: (error) => {
          console.log("上传失败：", error);
          return resolve(false);
        },
        complete: () => {
          common_vendor.index.hideLoading();
        }
      });
    });
  },
  // 通过图片url获得文件流
  getFileIO: async (fileUrl) => {
    return new Promise((resolve, reject) => {
      common_vendor.wx$1.request({
        url: `${"https://zxgz.newfeifan.cn"}/app-api/infra/file/downloadByUrl`,
        method: "GET",
        data: {
          fileUrl
        },
        responseType: "arraybuffer",
        success: (res) => {
          if (res.statusCode === 200) {
            const base64 = common_vendor.wx$1.arrayBufferToBase64(res.data);
            resolve(base64);
          } else {
            reject(new Error("网络响应不是OK状态"));
          }
        },
        fail: (err) => {
          reject(err);
        }
      });
    });
  }
};
const __vite_glob_0_3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: FileApi
}, Symbol.toStringTag, { value: "Module" }));
exports.FileApi = FileApi;
exports.__vite_glob_0_3 = __vite_glob_0_3;
