helper.ts 450 B

12345678910111213
  1. import { ResourceModule } from ".";
  2. export const helper = ResourceModule.helper({
  3. createFileName(fileName: string, dir: string) {
  4. const suffix = fileName.substring(fileName.lastIndexOf("."));
  5. if (/[\u4e00-\u9fa5]/.test(fileName) || fileName.length > 10) {
  6. fileName = `${this.controls.uploader.randomName(4)}${suffix}`;
  7. }
  8. return `${dir}/${Date.now()}_${this.controls.uploader.randomName(
  9. 6
  10. )}_${fileName}`;
  11. },
  12. });