zhengyiming
2025-02-21 db9a1cb8638d0159e5bce586c0e6a0610bc2b625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import * as accountServices from '@life-payment/services/api/Account';
 
type CacheData = {
  data: API.OssSTSReponse;
  time: number;
};
 
export class OssSTS {
  private static refreshSTSTokenInterval = 20 * 60 * 1000;
  private static cacheKey = 'ossSTSCacheKey';
  private static cache: { [key: string]: CacheData } = {};
 
  static async getOssSTS() {
    if (this.cache[this.cacheKey]) {
      if (new Date().getTime() - this.cache[this.cacheKey].time < this.refreshSTSTokenInterval) {
        return this.cache[this.cacheKey].data;
      }
    }
 
    let res = await accountServices.getOssSTS({
      showLoading: false,
    });
    this.cache[this.cacheKey] = {
      data: res,
      time: new Date().getTime(),
    };
    return res;
  }
}