import oss from "ali-oss"
import {
  GetSts
} from '@/api/admin/common.js'

let ossData = null;
let sysTime = 0;
let setAliSts = async function () {
	let res = await GetSts({});
	if (res.code === 1) {
		ossData = res.data;
		sysTime = setTime();
	}
}

let setTime = function () {
	return (new Date()).getTime();
}

export const clientArr = async function () {
  let client = ''
	if (ossData === null || (sysTime + 900000 <= setTime())) {
		await setAliSts();
	}
  return client = new oss({
    region: "oss-cn-chengdu",
    bucket: "jhnewshop",

    refreshSTSTokenInterval: 900000,
    accessKeySecret: ossData.AccessKeySecret,
    stsToken: ossData.SecurityToken,
    accessKeyId: ossData.AccessKeyId,
  })
}
