import { getLocale } from 'umi'; import { CKEDITOR_MAP } from '@/locales/helper'; import { handleUloadFile } from '@/utils/file'; import { getImageById } from '@/utils'; export type OnUploadChange = (data: { fileId: string; imgName: string }) => void; export class CustomUploadAdapter { loader: any; onUploadChange?: OnUploadChange; constructor(loader: any, onUploadChange?: OnUploadChange) { this.loader = loader; this.onUploadChange = onUploadChange; } upload() { return this.loader.file.then( (file: any) => new Promise((resolve) => { (async () => { const uploadedFile = await handleUloadFile(file); const { id } = uploadedFile[0]; this.onUploadChange?.({ fileId: id, imgName: file.name, }); resolve({ default: getImageById(id) }); })(); }), ); } } export const getLanguage = () => { const umiLocalKey = getLocale(); return CKEDITOR_MAP[umiLocalKey] || 'en-gb'; };