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