generated from template/astro-template
feat: add ai-html
This commit is contained in:
30
src/apps/ai-html/module/upload-file.ts
Normal file
30
src/apps/ai-html/module/upload-file.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { uploadChunkV2 } from '@/apps/draw/modules/upload';
|
||||
import { toFile } from '@/apps/draw/modules/to-file';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
type UploadFileOpts = {
|
||||
appKey: string;
|
||||
version: string;
|
||||
filename: string;
|
||||
text: string;
|
||||
};
|
||||
const getFilenameExtension = (filename: string) => {
|
||||
return filename.split('.').pop() || '';
|
||||
};
|
||||
const allowFilesName = ['js', 'css', 'json', 'html'];
|
||||
export const uploadFile = async (uploadFileOpts: UploadFileOpts) => {
|
||||
const { appKey, version, filename, text } = uploadFileOpts;
|
||||
const extension = getFilenameExtension(filename);
|
||||
if (!allowFilesName.includes(extension)) {
|
||||
toast.error('文件类型不支持');
|
||||
return;
|
||||
}
|
||||
const file = toFile(text, filename);
|
||||
const res = await uploadChunkV2(file, {
|
||||
appKey,
|
||||
version,
|
||||
filename,
|
||||
noCheckAppFiles: false,
|
||||
});
|
||||
return res as any;
|
||||
};
|
||||
Reference in New Issue
Block a user