import axios from 'axios'; 
 | 
  
 | 
export class SensitiveManage { 
 | 
  static sensitiveFilePath = `https://parkmanagement.oss-cn-hangzhou.aliyuncs.com/12333/sensitive.txt?${new Date().getTime()}`; 
 | 
  
 | 
  static sensitiveList = ''; 
 | 
  
 | 
  static async getSensitiveList() { 
 | 
    try { 
 | 
      if (!this.sensitiveList) { 
 | 
        const res = await axios.get(this.sensitiveFilePath); 
 | 
        this.sensitiveList = res.data; 
 | 
      } 
 | 
      return this.sensitiveList; 
 | 
    } catch (error) {} 
 | 
  } 
 | 
  
 | 
  static filterSensitiveWord(data: any, needFilter = true) { 
 | 
    if (needFilter && this.sensitiveList && data) { 
 | 
      if (typeof data === 'string') { 
 | 
        const regex = new RegExp(this.sensitiveList, 'gi'); 
 | 
        return data.replace(regex, (match) => match.replace(/./g, '*')); 
 | 
      } else if (Array.isArray(data)) { 
 | 
        return data.map((item) => this.filterSensitiveWord(item)); 
 | 
      } else if (typeof data === 'object') { 
 | 
        const dataKeys = Object.keys(data); 
 | 
        const newData: any = Object.create(Object.getPrototypeOf(data)); 
 | 
        dataKeys.forEach((value) => { 
 | 
          newData[value] = this.filterSensitiveWord(data[value]); 
 | 
        }); 
 | 
        return newData; 
 | 
      } 
 | 
    } 
 | 
    return data; 
 | 
  } 
 | 
} 
 | 
  
 | 
SensitiveManage.getSensitiveList(); 
 |