write-sensitive-word-category.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const fs = require('fs')
  2. const paths = [
  3. 'd:/ylrz_saas_new/saas-companyui/src/utils/lobster/sensitiveWordCategory.js',
  4. 'd:/ylrz_saas_new/saas-mgnui/src/utils/lobster/sensitiveWordCategory.js',
  5. 'd:/ylrz_saas_new/adminui/src/utils/lobster/sensitiveWordCategory.js'
  6. ]
  7. const content = `/** Sensitive word categories: value is stored code, label is display text. */
  8. export const SENSITIVE_WORD_CATEGORY_OPTIONS = [
  9. { value: 'wechat_ban', label: '\\u5fae\\u4fe1\\u8fdd\\u89c4' },
  10. { value: 'fin_ban', label: '\\u91d1\\u878d\\u8fdd\\u89c4' },
  11. { value: 'medical_ban', label: '\\u533b\\u7597\\u8fdd\\u89c4' },
  12. { value: 'edu_ban', label: '\\u6559\\u80b2\\u8fdd\\u89c4' },
  13. { value: 'competitor', label: '\\u7ade\\u54c1\\u5f15\\u6d41' },
  14. { value: 'scam_high_risk', label: '\\u8bc8\\u9a97\\u9ad8\\u98ce\\u9669' },
  15. { value: 'custom', label: '\\u81ea\\u5b9a\\u4e49' },
  16. { value: 'auto', label: '\\u81ea\\u52a8\\u5206\\u7c7b' },
  17. { value: 'politic', label: '\\u653f\\u6cbb' },
  18. { value: 'violence', label: '\\u66b4\\u529b' },
  19. { value: 'porn', label: '\\u8272\\u60c5' },
  20. { value: 'finance', label: '\\u91d1\\u878d' },
  21. { value: '\\u91d1\\u878d', label: '\\u91d1\\u878d' },
  22. { value: '\\u533b\\u7597', label: '\\u533b\\u7597' },
  23. { value: '\\u5e7f\\u544a', label: '\\u5e7f\\u544a' },
  24. { value: '\\u6cd5\\u5f8b', label: '\\u6cd5\\u5f8b' },
  25. { value: '\\u653f\\u6cbb', label: '\\u653f\\u6cbb' },
  26. { value: '\\u8bc8\\u9a97', label: '\\u8bc8\\u9a97' },
  27. { value: '\\u8272\\u60c5', label: '\\u8272\\u60c5' },
  28. { value: '\\u66b4\\u529b', label: '\\u66b4\\u529b' },
  29. { value: '\\u901a\\u7528', label: '\\u901a\\u7528' }
  30. ]
  31. const LABEL_MAP = SENSITIVE_WORD_CATEGORY_OPTIONS.reduce((acc, item) => {
  32. acc[item.value] = item.label
  33. return acc
  34. }, Object.create(null))
  35. const HAN_RE = /[\\u4e00-\\u9fff]/
  36. export function sensitiveWordCategoryLabel(code) {
  37. if (code == null || code === '') return '\\u2014'
  38. const key = String(code).trim()
  39. if (LABEL_MAP[key]) return LABEL_MAP[key]
  40. if (HAN_RE.test(key)) return key
  41. return key
  42. }
  43. export function buildSensitiveWordCategoryOptions(extraCodes) {
  44. const known = new Map(SENSITIVE_WORD_CATEGORY_OPTIONS.map(o => [o.value, o.label]))
  45. ;(extraCodes || []).forEach(c => {
  46. if (c && !known.has(c)) {
  47. known.set(c, sensitiveWordCategoryLabel(c))
  48. }
  49. })
  50. return Array.from(known.entries()).map(([value, label]) => ({ value, label }))
  51. }
  52. `
  53. paths.forEach(p => {
  54. fs.writeFileSync(p, content, 'utf8')
  55. const t = fs.readFileSync(p, 'utf8')
  56. console.log(p, t.includes('微信违规'), /^[\\x00-\\x7f]*$/.test(t))
  57. })