feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
5
frontend/packages/studio/common/file-kit/.stylelintrc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
frontend/packages/studio/common/file-kit/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# file-kit
|
||||
|
||||
> Project template for react component with storybook.
|
||||
|
||||
## Features
|
||||
|
||||
- [x] eslint & ts
|
||||
- [x] esm bundle
|
||||
- [x] umd bundle
|
||||
- [x] storybook
|
||||
|
||||
## Commands
|
||||
|
||||
- init: `rush update`
|
||||
- dev: `npm run dev`
|
||||
- build: `npm run build`
|
||||
158
frontend/packages/studio/common/file-kit/__tests__/util.test.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { getFileInfo } from '../src/util';
|
||||
import { FileTypeEnum } from '../src/const';
|
||||
|
||||
// 创建模拟的 File 对象
|
||||
function createMockFile(name: string, type: string): File {
|
||||
return {
|
||||
name,
|
||||
type,
|
||||
size: 1024,
|
||||
lastModified: Date.now(),
|
||||
slice: () => new Blob(),
|
||||
arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
|
||||
stream: () => new ReadableStream(),
|
||||
text: () => Promise.resolve(''),
|
||||
} as File;
|
||||
}
|
||||
|
||||
describe('getFileInfo', () => {
|
||||
it('应该根据文件类型识别图片文件', () => {
|
||||
const file = createMockFile('test.jpg', 'image/jpeg');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.IMAGE);
|
||||
});
|
||||
|
||||
it('应该根据文件类型识别音频文件', () => {
|
||||
const file = createMockFile('test.mp3', 'audio/mpeg');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.AUDIO);
|
||||
});
|
||||
|
||||
it('应该根据文件类型识别视频文件', () => {
|
||||
const file = createMockFile('test.mp4', 'video/mp4');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.VIDEO);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别 PDF 文件', () => {
|
||||
const file = createMockFile('document.pdf', 'application/pdf');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.PDF);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别 DOCX 文件', () => {
|
||||
const file = createMockFile(
|
||||
'document.docx',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
);
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.DOCX);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别 EXCEL 文件', () => {
|
||||
const file = createMockFile(
|
||||
'spreadsheet.xlsx',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
);
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.EXCEL);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别 CSV 文件', () => {
|
||||
const file = createMockFile('data.csv', 'text/csv');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.CSV);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别压缩文件', () => {
|
||||
const file = createMockFile('archive.zip', 'application/zip');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.ARCHIVE);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别代码文件', () => {
|
||||
const file = createMockFile('script.js', 'text/javascript');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.CODE);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别文本文件', () => {
|
||||
const file = createMockFile('notes.txt', 'text/plain');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.TXT);
|
||||
});
|
||||
|
||||
it('应该根据文件扩展名识别 PPT 文件', () => {
|
||||
const file = createMockFile(
|
||||
'presentation.pptx',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
);
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.PPT);
|
||||
});
|
||||
|
||||
it('应该对未知文件类型返回默认类型', () => {
|
||||
const file = createMockFile('unknown.xyz', 'application/octet-stream');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.DEFAULT_UNKNOWN);
|
||||
});
|
||||
|
||||
it('当文件类型和扩展名不匹配时,应该优先使用文件类型判断', () => {
|
||||
// 文件名是 .txt 但 MIME 类型是图片
|
||||
const file = createMockFile('image.txt', 'image/jpeg');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.IMAGE);
|
||||
});
|
||||
|
||||
it('当文件没有 MIME 类型时,应该使用扩展名判断', () => {
|
||||
const file = createMockFile('document.docx', '');
|
||||
const fileInfo = getFileInfo(file);
|
||||
|
||||
expect(fileInfo).not.toBeNull();
|
||||
expect(fileInfo?.fileType).toBe(FileTypeEnum.DOCX);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["./dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"codecov": {
|
||||
"coverage": 0,
|
||||
"incrementCoverage": 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
50
frontend/packages/studio/common/file-kit/package.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "@coze-studio/file-kit",
|
||||
"version": "0.0.1",
|
||||
"description": "file kit ",
|
||||
"license": "Apache-2.0",
|
||||
"author": "liuyuhang.0@bytedance.com",
|
||||
"maintainers": [],
|
||||
"exports": {
|
||||
"./config": "./src/exports/config.ts",
|
||||
"./logic": "./src/exports/logic.ts"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"logic": [
|
||||
"./src/exports/logic.ts"
|
||||
],
|
||||
"config": [
|
||||
"./src/exports/config.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-arch/i18n": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"stylelint": "^15.11.0",
|
||||
"vite-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
86
frontend/packages/studio/common/file-kit/src/accept.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
|
||||
import {
|
||||
ZipIcon,
|
||||
VideoIcon,
|
||||
TextIcon as TxtIcon,
|
||||
ImageIcon,
|
||||
AudioIcon,
|
||||
CodeIcon,
|
||||
PptIcon,
|
||||
DocxIcon as DocIcon,
|
||||
XlsxIcon as TableIcon,
|
||||
UnknownIcon,
|
||||
} from './icon';
|
||||
import { FileTypeEnum } from './const';
|
||||
|
||||
const uploadTableConfig = {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_table'),
|
||||
icon: TableIcon,
|
||||
};
|
||||
|
||||
const uploadDocConfig = {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_doc'),
|
||||
icon: DocIcon,
|
||||
};
|
||||
|
||||
export const ACCEPT_UPLOAD_TYPES: Record<
|
||||
FileTypeEnum,
|
||||
{
|
||||
label: string;
|
||||
icon: string;
|
||||
}
|
||||
> = {
|
||||
[FileTypeEnum.IMAGE]: {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_img'),
|
||||
icon: ImageIcon,
|
||||
},
|
||||
[FileTypeEnum.EXCEL]: uploadTableConfig,
|
||||
[FileTypeEnum.CSV]: uploadTableConfig,
|
||||
[FileTypeEnum.PDF]: uploadDocConfig,
|
||||
[FileTypeEnum.DOCX]: uploadDocConfig,
|
||||
[FileTypeEnum.DEFAULT_UNKNOWN]: {
|
||||
label: I18n.t('plugin_file_unknown'),
|
||||
icon: UnknownIcon,
|
||||
},
|
||||
[FileTypeEnum.AUDIO]: {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_audio'),
|
||||
icon: AudioIcon,
|
||||
},
|
||||
[FileTypeEnum.CODE]: {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_code'),
|
||||
icon: CodeIcon,
|
||||
},
|
||||
[FileTypeEnum.ARCHIVE]: {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_zip'),
|
||||
icon: ZipIcon,
|
||||
},
|
||||
[FileTypeEnum.PPT]: {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_ppt'),
|
||||
icon: PptIcon,
|
||||
},
|
||||
[FileTypeEnum.VIDEO]: {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_video'),
|
||||
icon: VideoIcon,
|
||||
},
|
||||
[FileTypeEnum.TXT]: {
|
||||
label: I18n.t('shortcut_modal_upload_component_file_format_txt'),
|
||||
icon: TxtIcon,
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2526" d="M1 4.99996C1 3.15901 2.49238 1.66663 4.33333 1.66663H20.3096C20.7517 1.66663 21.1756 1.84222 21.4882 2.15478L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99996Z" fill="#32A645"/>
|
||||
<path id="Rectangle 2527" opacity="0.9" d="M21 2.27018C21 2.04745 21.2693 1.93591 21.4268 2.0934L30.5732 11.2398C30.7307 11.3973 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1742 21 8.33329V2.27018Z" fill="#258832"/>
|
||||
<path id="music_note" d="M13.0833 31.25C12.1667 31.25 11.3819 30.9236 10.7292 30.2708C10.0764 29.6181 9.75 28.8333 9.75 27.9167C9.75 27 10.0764 26.2153 10.7292 25.5625C11.3819 24.9097 12.1667 24.5833 13.0833 24.5833C13.4028 24.5833 13.6979 24.6215 13.9688 24.6979C14.2396 24.7743 14.5 24.8889 14.75 25.0417V17.5C14.75 16.8096 15.3096 16.25 16 16.25H21V18.75H17.0417C16.6965 18.75 16.4167 19.0298 16.4167 19.375V27.9167C16.4167 28.8333 16.0903 29.6181 15.4375 30.2708C14.7847 30.9236 14 31.25 13.0833 31.25Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2528" d="M1 5.00008C1 3.15913 2.49238 1.66675 4.33333 1.66675H20.3096C20.7517 1.66675 21.1756 1.84234 21.4882 2.1549L30.5118 11.1786C30.8244 11.4912 31 11.9151 31 12.3571V35.0001C31 36.841 29.5076 38.3334 27.6667 38.3334H4.33333C2.49238 38.3334 1 36.841 1 35.0001V5.00008Z" fill="#336DF4"/>
|
||||
<path id="Rectangle 2529" opacity="0.7" d="M21 2.2703C21 2.04757 21.2693 1.93603 21.4268 2.09352L30.5732 11.24C30.7307 11.3975 30.6192 11.6667 30.3964 11.6667H24.3333C22.4924 11.6667 21 10.1744 21 8.33341V2.2703Z" fill="#0442D2"/>
|
||||
<path id="icon_file_code_nor" d="M13.1583 19.1273L8.94653 23.5605L13.1583 27.9936C13.3094 28.1527 13.3067 28.4078 13.1523 28.5635L13.1506 28.5652L12.5848 29.1289C12.4301 29.2831 12.1836 29.2796 12.033 29.1211L7.01788 23.8423C6.86904 23.6857 6.86904 23.4352 7.01788 23.2786L12.033 17.9998C12.1836 17.8414 12.4301 17.8379 12.5848 17.992L13.1506 18.5558C13.306 18.7105 13.3101 18.9657 13.1598 19.1257L13.1583 19.1273ZM23.1935 23.5605L19.2826 19.1273C19.1423 18.9683 19.1448 18.7131 19.2882 18.5574L19.2897 18.5558L19.8152 17.992C19.9588 17.8379 20.1877 17.8414 20.3275 17.9998L24.9844 23.2786C25.1226 23.4352 25.1226 23.6857 24.9844 23.8423L20.3275 29.1211C20.1877 29.2796 19.9588 29.2831 19.8152 29.1289L19.2897 28.5652C19.1455 28.4104 19.1416 28.1552 19.2812 27.9952L19.2826 27.9936L23.1935 23.5605ZM17.0448 15.1539L17.8645 15.2418C18.0882 15.2658 18.2487 15.4536 18.2228 15.6611L16.2662 31.1805C16.2401 31.3879 16.0378 31.5364 15.8143 31.5125L14.9946 31.4246C14.7708 31.4006 14.6104 31.2128 14.6363 31.0052L16.5928 15.4858C16.619 15.2785 16.8212 15.1299 17.0448 15.1539Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,8 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2528" d="M4 4.99997C4 3.15902 5.19391 1.66664 6.66667 1.66664H19.4477C19.8013 1.66664 20.1405 1.84224 20.3905 2.1548L27.6095 11.1785C27.8595 11.491 28 11.915 28 12.357V35C28 36.8409 26.8061 38.3333 25.3333 38.3333H6.66667C5.19391 38.3333 4 36.8409 4 35V4.99997Z" fill="#336DF4"/>
|
||||
<path id="Rectangle 2530" d="M1 4.99997C1 3.15902 2.49238 1.66664 4.33333 1.66664H20.3096C20.7517 1.66664 21.1756 1.84224 21.4882 2.1548L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99997Z" fill="#336DF4"/>
|
||||
<path id="Rectangle 2531" opacity="0.7" d="M21 2.27019C21 2.04747 21.2693 1.93593 21.4268 2.09342L30.5732 11.2399C30.7307 11.3974 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1743 21 8.33331V2.27019Z" fill="#0442D2"/>
|
||||
<path id="icon_file_word_nor" d="M16.0074 20.4158L13.5499 29.51C13.52 29.6204 13.4199 29.697 13.3056 29.697H11.8581C11.7449 29.697 11.6455 29.6219 11.6147 29.513L8.2821 17.7463C8.24402 17.6119 8.32215 17.472 8.45662 17.4339C8.47905 17.4275 8.50226 17.4243 8.52557 17.4243H9.97719C10.0926 17.4243 10.1933 17.5023 10.2222 17.614L12.5937 26.7863L15.0564 17.6118C15.086 17.5012 15.1863 17.4243 15.3008 17.4243H16.7153C16.8299 17.4243 16.9302 17.5014 16.9598 17.6121L19.4067 26.784L21.7776 17.614C21.8064 17.5023 21.9072 17.4243 22.0226 17.4243H23.4742C23.6139 17.4243 23.7272 17.5376 23.7272 17.6774C23.7272 17.7007 23.724 17.7239 23.7177 17.7463L20.3851 29.513C20.3542 29.6219 20.2548 29.697 20.1416 29.697H18.6942C18.5797 29.697 18.4795 29.6202 18.4498 29.5096L16.0074 20.4158Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2528" d="M1 4.99996C1 3.15901 2.49238 1.66663 4.33333 1.66663H20.3096C20.7517 1.66663 21.1756 1.84222 21.4882 2.15478L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99996Z" fill="#FFC60A"/>
|
||||
<path id="Rectangle 2529" opacity="0.8" d="M21 2.27018C21 2.04745 21.2693 1.93591 21.4268 2.0934L30.5732 11.2398C30.7307 11.3973 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1742 21 8.33329V2.27018Z" fill="#D99904"/>
|
||||
<g id="形状结合">
|
||||
<path d="M9.95312 16.6666C9.03265 16.6666 8.28646 17.4128 8.28646 18.3333V18.6363C8.28646 19.5568 9.03265 20.303 9.95312 20.303H10.2562C11.1766 20.303 11.9228 19.5568 11.9228 18.6363V18.3333C11.9228 17.4128 11.1766 16.6666 10.2562 16.6666H9.95312Z" fill="white"/>
|
||||
<path d="M23.8254 21.2663C24.4434 20.5989 25.5592 21.0362 25.5592 21.9457V30.8333C25.5592 31.2935 25.1861 31.6666 24.7259 31.6666L8.33494 31.6666C7.76879 31.6666 7.46033 31.0055 7.82405 30.5716L12.7 24.7554C13.3661 23.9609 14.5883 23.9609 15.2544 24.7554L17.792 27.7824L23.8254 21.2663Z" fill="white"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2526" d="M1 4.99997C1 3.15902 2.49238 1.66664 4.33333 1.66664H20.3096C20.7517 1.66664 21.1756 1.84224 21.4882 2.1548L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99997Z" fill="#F54A45"/>
|
||||
<path id="Rectangle 2527" d="M21 2.27019C21 2.04747 21.2693 1.93593 21.4268 2.09342L30.5732 11.2399C30.7307 11.3974 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1743 21 8.33331V2.27019Z" fill="#C02A26"/>
|
||||
<path id="icon_file_pdf_nor" d="M25.2516 25.9184C24.8379 25.4341 23.9896 25.1986 22.6583 25.1986C21.8845 25.1986 20.8185 25.2181 19.7472 25.3771C16.821 23.2676 16.1352 21.0015 16.1352 21.0015C16.1352 21.0015 16.635 19.7471 16.6667 17.6982C16.6868 16.403 16.4814 15.437 15.9578 15.0218C15.7347 14.8449 15.4108 14.697 15.0848 14.697C14.8303 14.697 14.592 14.7707 14.3967 14.9115C12.8756 16.009 14.5363 21.1828 14.5808 21.3207C13.8629 23.0626 12.9586 24.9081 12.0279 26.5297C11.7255 27.0565 11.7255 27.0667 11.5223 27.3059C11.5223 27.3059 8.85954 28.6265 7.61092 30.0907C6.90544 30.9181 6.88254 31.4861 6.92 31.9118C6.98036 32.4223 7.63116 32.8788 8.28633 32.8788C8.3135 32.8788 8.34084 32.878 8.36762 32.8763C9.03349 32.8358 9.77415 32.6526 10.5983 31.873C11.195 31.3086 11.866 29.7758 12.7286 28.276C15.2034 27.5818 17.3814 27.0874 19.2066 26.8055C20.5451 27.5157 22.5366 28.3201 23.8922 28.3201C24.3469 28.3201 24.7128 28.2287 24.9795 28.0484C25.2986 27.8328 25.4341 27.5641 25.5183 27.0667C25.6025 26.5693 25.4853 26.1921 25.2516 25.9184ZM22.342 26.697C23.578 26.697 24.2472 26.9151 24.591 27.098C24.697 27.1544 24.7742 27.2089 24.8289 27.2543C24.732 27.3294 24.5414 27.4243 24.1971 27.4243C23.626 27.4243 22.8765 27.1823 21.9623 26.7036C22.0924 26.6992 22.219 26.697 22.342 26.697ZM15.2432 15.7931L15.2453 15.7879C15.4383 15.93 15.5284 16.9281 15.5103 17.5068C15.486 18.2834 15.4802 18.5835 15.3827 19.0606C15.1185 18.0659 15.0997 16.2779 15.2432 15.7931ZM15.3042 23.0606C15.907 24.0536 16.6715 25.0591 17.5328 25.827C15.8516 26.1874 14.4556 26.5181 13.4512 26.8696C14.5278 25.005 15.2335 23.2454 15.3042 23.0606ZM8.51592 31.4738C8.66804 31.2488 9.08367 30.8128 10.1377 29.9697C9.57203 31.2728 8.93672 31.4738 8.34612 31.7878C8.39069 31.6845 8.44678 31.5761 8.51592 31.4738Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2530" d="M1 5.00008C1 3.15913 2.49238 1.66675 4.33333 1.66675H20.3096C20.7517 1.66675 21.1756 1.84234 21.4882 2.1549L30.5118 11.1786C30.8244 11.4912 31 11.9151 31 12.3571V35.0001C31 36.841 29.5076 38.3334 27.6667 38.3334H4.33333C2.49238 38.3334 1 36.841 1 35.0001V5.00008Z" fill="#FF811A"/>
|
||||
<path id="Rectangle 2531" opacity="0.8" d="M21 2.2703C21 2.04757 21.2693 1.93603 21.4268 2.09352L30.5732 11.24C30.7307 11.3975 30.6192 11.6667 30.3964 11.6667H24.3333C22.4924 11.6667 21 10.1744 21 8.33341V2.2703Z" fill="#ED6D0C"/>
|
||||
<path id="Subtract" d="M13.3038 30.8251V24.8477H16.1402C16.8218 24.8477 17.5001 24.7878 18.1749 24.668C18.8621 24.546 19.479 24.3316 20.0243 24.0244C20.5793 23.7117 21.032 23.2837 21.3799 22.7429C21.7332 22.1938 21.9077 21.5053 21.9077 20.6814C21.9077 20.1383 21.8345 19.6179 21.688 19.1206C21.5371 18.6083 21.2705 18.1546 20.8902 17.7622C20.5082 17.3681 19.9947 17.0617 19.3529 16.8413C18.717 16.6229 17.92 16.5151 16.9605 16.5151H11.6886C11.5586 16.5151 11.4531 16.6206 11.4531 16.7506V30.8251C11.4531 30.9552 11.5586 31.0606 11.6886 31.0606H13.0683C13.1983 31.0606 13.3038 30.9552 13.3038 30.8251ZM17.8627 23.1217C17.3692 23.1978 16.8082 23.236 16.1801 23.236H13.3037V18.1268H16.5803C17.8243 18.1268 18.7172 18.3424 19.2601 18.7594C19.7912 19.1673 20.057 19.7679 20.057 20.5837C20.057 21.1479 19.9675 21.5968 19.7935 21.9308C19.6202 22.2634 19.3773 22.5236 19.062 22.7154C18.738 22.9123 18.3387 23.0483 17.8627 23.1217Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2526" d="M1 4.99997C1 3.15902 2.49238 1.66664 4.33333 1.66664H20.3096C20.7517 1.66664 21.1756 1.84224 21.4882 2.1548L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99997Z" fill="#336DF4"/>
|
||||
<path id="Rectangle 2527" opacity="0.7" d="M21 2.27019C21 2.04747 21.2693 1.93593 21.4268 2.09342L30.5732 11.2399C30.7307 11.3974 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1743 21 8.33331V2.27019Z" fill="#0442D2"/>
|
||||
<path id="Union" d="M16.9089 17.8787V30.3787C16.9089 30.5043 16.8072 30.606 16.6816 30.606H15.318C15.1925 30.606 15.0907 30.5043 15.0907 30.3787V17.8787H9.40891C9.28339 17.8787 9.18164 17.777 9.18164 17.6515V16.2878C9.18164 16.1623 9.28339 16.0606 9.40891 16.0606H22.5907C22.7163 16.0606 22.818 16.1623 22.818 16.2878V17.6515C22.818 17.777 22.7163 17.8787 22.5907 17.8787H16.9089Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2526" d="M1 5.00008C1 3.15913 2.49238 1.66675 4.33333 1.66675H20.3096C20.7517 1.66675 21.1756 1.84234 21.4882 2.1549L30.5118 11.1786C30.8244 11.4912 31 11.9151 31 12.3571V35.0001C31 36.841 29.5076 38.3334 27.6667 38.3334H4.33333C2.49238 38.3334 1 36.841 1 35.0001V5.00008Z" fill="#336DF4"/>
|
||||
<path id="Rectangle 2527" opacity="0.7" d="M21 2.2703C21 2.04757 21.2693 1.93603 21.4268 2.09352L30.5732 11.24C30.7307 11.3975 30.6192 11.6667 30.3964 11.6667H24.3333C22.4924 11.6667 21 10.1744 21 8.33341V2.2703Z" fill="#0442D2"/>
|
||||
<path id="Union" d="M16.907 17.8787V30.3787C16.907 30.5042 16.8052 30.606 16.6797 30.606H15.3161C15.1905 30.606 15.0888 30.5042 15.0888 30.3787V17.8787H9.40696C9.28144 17.8787 9.17969 17.777 9.17969 17.6515V16.2878C9.17969 16.1623 9.28144 16.0605 9.40696 16.0605H22.5888C22.7143 16.0605 22.8161 16.1623 22.8161 16.2878V17.6515C22.8161 17.777 22.7143 17.8787 22.5888 17.8787H16.907Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2530" opacity="0.9" d="M1 4.99997C1 3.15902 2.49238 1.66664 4.33333 1.66664H20.3096C20.7517 1.66664 21.1756 1.84224 21.4882 2.1548L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99997Z" fill="#8F959E"/>
|
||||
<path id="Rectangle 2531" opacity="0.6" d="M21 2.27019C21 2.04747 21.2693 1.93593 21.4268 2.09342L30.5732 11.2399C30.7307 11.3974 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1743 21 8.33331V2.27019Z" fill="#646A73"/>
|
||||
<path id="?" d="M19.8136 16.4407C18.904 15.579 17.7103 15.1514 16.2258 15.1514C14.5581 15.1514 13.2511 15.686 12.3042 16.775C11.5021 17.7108 11.07 18.6077 11.0082 20.0217C11.0067 20.055 11.0055 20.1162 11.0044 20.187C11.001 20.4179 11.1884 20.6059 11.4195 20.6059H12.4045C12.6337 20.6059 12.8192 20.4209 12.823 20.1918C12.8242 20.1228 12.8255 20.0633 12.8271 20.0315C12.8755 19.0547 13.1303 18.5436 13.585 17.9752C14.1592 17.2098 15.0014 16.8332 16.1576 16.8332C17.1893 16.8332 17.9629 17.0963 18.4969 17.6303C19.0058 18.1605 19.2712 18.8823 19.2712 19.7877C19.2712 20.4058 19.0472 20.9945 18.5918 21.58C18.4467 21.7613 18.2378 21.977 17.565 22.6498C16.5022 23.579 15.8458 24.3349 15.4991 25.078C15.214 25.648 15.0687 26.2959 15.0687 26.9923V27.462C15.0687 27.6921 15.2552 27.8786 15.4853 27.8786H16.4929C16.723 27.8786 16.9096 27.6921 16.9096 27.462V26.9923C16.9096 26.4021 17.0549 25.8728 17.3559 25.3568C17.5813 24.9736 17.8708 24.673 18.3754 24.2315C19.3872 23.3161 19.9485 22.7708 20.1999 22.4509C20.8038 21.6538 21.1121 20.7409 21.1121 19.7423C21.1121 18.3641 20.6794 17.2584 19.8136 16.4407ZM15.5081 29.6968C15.2779 29.6968 15.0914 29.8834 15.0914 30.1135V31.0983C15.0914 31.3285 15.2779 31.515 15.5081 31.515H16.4929C16.723 31.515 16.9096 31.3285 16.9096 31.0983V30.1135C16.9096 29.8834 16.723 29.6968 16.4929 29.6968H15.5081Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2528" d="M1 5.00008C1 3.15913 2.49238 1.66675 4.33333 1.66675H20.3096C20.7517 1.66675 21.1756 1.84234 21.4882 2.1549L30.5118 11.1786C30.8244 11.4912 31 11.9151 31 12.3571V35.0001C31 36.841 29.5076 38.3334 27.6667 38.3334H4.33333C2.49238 38.3334 1 36.841 1 35.0001V5.00008Z" fill="#336DF4"/>
|
||||
<path id="Rectangle 2529" opacity="0.7" d="M21 2.2703C21 2.04757 21.2693 1.93603 21.4268 2.09352L30.5732 11.24C30.7307 11.3975 30.6192 11.6667 30.3964 11.6667H24.3333C22.4924 11.6667 21 10.1744 21 8.33341V2.2703Z" fill="#0442D2"/>
|
||||
<path id="形状" d="M7.66406 17.9165C7.66406 17.2261 8.22371 16.6665 8.91406 16.6665H17.6641C18.3544 16.6665 18.9141 17.2261 18.9141 17.9165V19.4009L20.8012 18.3393C21.6345 17.8706 22.6641 18.4728 22.6641 19.4288V25.1542C22.6641 26.1102 21.6345 26.7124 20.8012 26.2437L18.9141 25.1821V26.6665C18.9141 27.3569 18.3544 27.9165 17.6641 27.9165H8.91406C8.22371 27.9165 7.66406 27.3569 7.66406 26.6665V17.9165ZM11.4141 21.6665C12.1044 21.6665 12.6641 21.1069 12.6641 20.4165C12.6641 19.7261 12.1044 19.1665 11.4141 19.1665C10.7237 19.1665 10.1641 19.7261 10.1641 20.4165C10.1641 21.1069 10.7237 21.6665 11.4141 21.6665Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2526" d="M1 4.99996C1 3.15901 2.49238 1.66663 4.33333 1.66663H20.3096C20.7517 1.66663 21.1756 1.84222 21.4882 2.15478L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99996Z" fill="#32A645"/>
|
||||
<path id="Rectangle 2527" opacity="0.9" d="M21 2.27018C21 2.04745 21.2693 1.93591 21.4268 2.0934L30.5732 11.2398C30.7307 11.3973 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1742 21 8.33329V2.27018Z" fill="#258832"/>
|
||||
<path id="icon_file_excel_nor" d="M10.2443 16.5151H12.064C12.1447 16.5151 12.2202 16.5548 12.266 16.6212L15.7637 21.6898L19.2798 16.6207C19.3256 16.5546 19.401 16.5151 19.4815 16.5151H21.3009C21.4365 16.5151 21.5464 16.625 21.5464 16.7606C21.5464 16.8117 21.5304 16.8615 21.5008 16.9031L16.9458 23.2925L21.8632 30.2185C21.9416 30.329 21.9156 30.4823 21.8051 30.5607C21.7636 30.5902 21.7139 30.606 21.663 30.606H19.8434C19.7628 30.606 19.6874 30.5665 19.6416 30.5002L15.7636 24.8954L11.9042 30.4998C11.8584 30.5663 11.7828 30.606 11.7021 30.606H9.88217C9.74661 30.606 9.63672 30.4962 9.63672 30.3606C9.63672 30.31 9.65237 30.2606 9.68153 30.2192L14.5623 23.2925L10.0438 16.9023C9.96558 16.7916 9.99186 16.6384 10.1025 16.5602C10.144 16.5309 10.1935 16.5151 10.2443 16.5151Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="icon">
|
||||
<path id="Rectangle 2528" d="M1 4.99997C1 3.15902 2.49238 1.66664 4.33333 1.66664H20.3096C20.7517 1.66664 21.1756 1.84224 21.4882 2.1548L30.5118 11.1785C30.8244 11.491 31 11.915 31 12.357V35C31 36.8409 29.5076 38.3333 27.6667 38.3333H4.33333C2.49238 38.3333 1 36.8409 1 35V4.99997Z" fill="#336DF4"/>
|
||||
<path id="Rectangle 2529" opacity="0.7" d="M21 2.27019C21 2.04747 21.2693 1.93593 21.4268 2.09342L30.5732 11.2399C30.7307 11.3974 30.6192 11.6666 30.3964 11.6666H24.3333C22.4924 11.6666 21 10.1743 21 8.33331V2.27019Z" fill="#0442D2"/>
|
||||
<path id="合并形状" d="M21.714 15.8334C22.2399 15.8334 22.6663 16.2531 22.6663 16.7709V29.8959C22.6663 30.4136 22.2399 30.8334 21.714 30.8334H10.2854C9.7594 30.8334 9.33301 30.4136 9.33301 29.8959V16.7709C9.33301 16.2531 9.7594 15.8334 10.2854 15.8334H21.714ZM17.9044 26.1459H14.0949V29.4271H17.9044V26.1459ZM16.9521 27.0834V28.1682H15.0473V27.0834H16.9521ZM17.9484 19.5834H15.9997V21.4584H14.0949V23.3334H15.9997V25.2084H17.9484V23.3334H16.0436V21.4584H17.9484V19.5834ZM15.9997 17.7084H14.0949V19.5834H15.9997V17.7084Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
40
frontend/packages/studio/common/file-kit/src/const.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type EnumToUnion } from './types/util';
|
||||
|
||||
export const enum FileTypeEnum {
|
||||
PDF = 'pdf',
|
||||
DOCX = 'docx',
|
||||
EXCEL = 'excel',
|
||||
CSV = 'csv',
|
||||
IMAGE = 'image',
|
||||
AUDIO = 'audio',
|
||||
VIDEO = 'video',
|
||||
ARCHIVE = 'archive',
|
||||
CODE = 'code',
|
||||
TXT = 'txt',
|
||||
PPT = 'ppt',
|
||||
DEFAULT_UNKNOWN = 'default_unknown',
|
||||
}
|
||||
|
||||
export type FileType = EnumToUnion<typeof FileTypeEnum>;
|
||||
|
||||
export interface TFileTypeConfig {
|
||||
fileType: FileTypeEnum;
|
||||
accept: string[];
|
||||
judge?: (file: Pick<File, 'type'>) => boolean;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { ACCEPT_UPLOAD_TYPES } from '../accept';
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { FileTypeEnum } from '../const';
|
||||
export { FILE_TYPE_CONFIG } from '../file-type';
|
||||
export { getFileInfo } from '../util';
|
||||
|
||||
// types
|
||||
export type { FileType, TFileTypeConfig } from '../const';
|
||||
90
frontend/packages/studio/common/file-kit/src/file-type.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { FileTypeEnum, type TFileTypeConfig } from './const';
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
* {@link
|
||||
* {@link https://www.iana.org/assignments/media-types/media-types.xhtml#image}
|
||||
*/
|
||||
export const FILE_TYPE_CONFIG: readonly TFileTypeConfig[] = [
|
||||
{
|
||||
fileType: FileTypeEnum.IMAGE,
|
||||
accept: ['image/*'],
|
||||
judge: file => file.type.startsWith('image/'),
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.AUDIO,
|
||||
accept: [
|
||||
'.mp3',
|
||||
'.wav',
|
||||
'.aac',
|
||||
'.flac',
|
||||
'.ogg',
|
||||
'.wma',
|
||||
'.alac',
|
||||
// .midi 和 .mid 都是MIDI(Musical Instrument Digital Interface)文件的扩展名 - GPT
|
||||
'.mid',
|
||||
'.midi',
|
||||
'.ac3',
|
||||
'.dsd',
|
||||
],
|
||||
judge: file => file.type.startsWith('audio/'),
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.PDF,
|
||||
accept: ['.pdf'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.DOCX,
|
||||
accept: ['.docx', '.doc'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.EXCEL,
|
||||
accept: ['.xls', '.xlsx'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.CSV,
|
||||
accept: ['.csv'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.VIDEO,
|
||||
accept: ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv'],
|
||||
judge: file => file.type.startsWith('video/'),
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.ARCHIVE,
|
||||
accept: ['.zip', '.rar', '.7z', '.tar', '.gz', '.bz2'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.CODE,
|
||||
accept: ['.py', '.java', '.c', '.cpp', '.js', '.html', '.css'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.TXT,
|
||||
accept: ['.txt'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.PPT,
|
||||
accept: ['.ppt', '.pptx'],
|
||||
},
|
||||
{
|
||||
fileType: FileTypeEnum.DEFAULT_UNKNOWN,
|
||||
judge: () => true,
|
||||
accept: ['*'],
|
||||
},
|
||||
];
|
||||
26
frontend/packages/studio/common/file-kit/src/icon/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { default as ZipIcon } from '../assets/file/zip-success.svg';
|
||||
export { default as XlsxIcon } from '../assets/file/xlsx-success.svg';
|
||||
export { default as VideoIcon } from '../assets/file/video-success.svg';
|
||||
export { default as TextIcon } from '../assets/file/txt-success.svg';
|
||||
export { default as PptIcon } from '../assets/file/ppt-success.svg';
|
||||
export { default as ImageIcon } from '../assets/file/image-success.svg';
|
||||
export { default as DocxIcon } from '../assets/file/docx-success.svg';
|
||||
export { default as CodeIcon } from '../assets/file/code-success.svg';
|
||||
export { default as AudioIcon } from '../assets/file/audio-success.svg';
|
||||
export { default as UnknownIcon } from '../assets/file/unknown-success.svg';
|
||||
17
frontend/packages/studio/common/file-kit/src/types/util.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export type EnumToUnion<T extends Record<string, string>> = T[keyof T];
|
||||
17
frontend/packages/studio/common/file-kit/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
28
frontend/packages/studio/common/file-kit/src/util.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { FILE_TYPE_CONFIG } from './file-type';
|
||||
|
||||
// 获取文件信息
|
||||
export const getFileInfo = (file: File) => {
|
||||
const fileInfo = FILE_TYPE_CONFIG.find(({ judge, accept }) =>
|
||||
judge ? judge(file) : accept.some(ext => file.name.endsWith(ext)),
|
||||
);
|
||||
if (!fileInfo) {
|
||||
return null;
|
||||
}
|
||||
return fileInfo;
|
||||
};
|
||||
33
frontend/packages/studio/common/file-kit/tsconfig.build.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"compilerOptions": {
|
||||
"types": [],
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true,
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"tsBuildInfoFile": "./dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../arch/i18n/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../config/eslint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../config/stylelint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../config/ts-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../../config/vitest-config/tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
frontend/packages/studio/common/file-kit/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
],
|
||||
"exclude": ["**/*"]
|
||||
}
|
||||
18
frontend/packages/studio/common/file-kit/tsconfig.misc.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"include": ["__tests__", "stories", "vitest.config.ts", "tailwind.config.ts"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"types": ["vitest/globals"],
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true
|
||||
}
|
||||
}
|
||||
22
frontend/packages/studio/common/file-kit/vitest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||