check-oa-upload-file-type.mjs 1.2 KB

123456789101112131415161718192021222324
  1. /**
  2. * 轻量断言:OA 上传控件图片/非图片判定(tsx 直接跑 TypeScript 源码)
  3. * 用法:pnpm exec tsx scripts/check-oa-upload-file-type.mjs
  4. */
  5. import assert from 'node:assert/strict'
  6. import {
  7. isOaUploadImageFile,
  8. isOaUploadVideoFile,
  9. getOaUploadDisplayName
  10. } from '../src/utils/oa-upload-file-type.ts'
  11. assert.equal(isOaUploadImageFile({ name: 'a.png', url: 'https://x/a.png' }), true)
  12. assert.equal(isOaUploadImageFile({ name: 'a.PDF', url: 'https://x/a.PDF' }), false)
  13. assert.equal(isOaUploadImageFile({ name: 'x.docx', url: 'https://cdn/x.docx' }), false)
  14. assert.equal(isOaUploadImageFile({ name: 'blob', url: 'blob:http://localhost/1', raw: { type: 'image/jpeg' } }), true)
  15. assert.equal(isOaUploadImageFile({ name: 'report.xlsx', url: 'https://cdn/report.xlsx' }), false)
  16. assert.equal(isOaUploadVideoFile({ name: 'a.mp4', url: 'https://x/a.mp4' }), true)
  17. assert.equal(isOaUploadVideoFile({ name: 'a.pdf', url: 'https://x/a.pdf' }), false)
  18. assert.equal(getOaUploadDisplayName({ name: '合同.pdf', url: 'https://x/path/合同.pdf' }), '合同.pdf')
  19. assert.equal(getOaUploadDisplayName({ url: 'https://x/path/only-url.docx' }), 'only-url.docx')
  20. console.log('ok: oa upload file type helpers')