fix:span file proplem

This commit is contained in:
liamzi
2024-12-24 17:29:04 +08:00
parent 36c57349bc
commit 5eb069c63f
52 changed files with 49 additions and 928 deletions

View File

@@ -161,7 +161,9 @@ const StorageManager = () => {
showUploadList: false,
customRequest: async ({ file, onSuccess, onError }) => {
try {
const fileName = file.name;
const originalName = file.name;
const fileName = handleFileName(originalName);
// 检查文件是否存在
const fileExists = allFiles.some((f) => f.name === fileName);
@@ -171,11 +173,14 @@ const StorageManager = () => {
const { data, error } = await supabase.storage
.from("file")
.upload(fileName, file);
.upload(fileName, file, {
cacheControl: '3600',
upsert: false
});
if (error) throw error;
message.success(`${fileName} 上传成功`);
message.success(`${originalName} 上传成功`);
onSuccess(data);
fetchAllFiles();
} catch (error) {
@@ -202,10 +207,10 @@ const StorageManager = () => {
if (selectedType === "全部") return matchesSearch;
const mimetype = file.metadata?.mimetype;
const matchesType = FILE_TYPES[selectedType]?.includes(mimetype);
return matchesSearch && matchesType;
const mimetype = file.metadata?.mimetype || '';
return matchesType && FILE_TYPES[selectedType]?.some(type =>
mimetype.startsWith(type) || mimetype === type
);
});
}, [displayFiles, searchText, selectedType]);
@@ -214,7 +219,7 @@ const StorageManager = () => {
// 获取文件类型统计
const typeStats = useMemo(() => {
const stats = { 全部: displayFiles.length };
const stats = { 全部: 0, 其他: 0 };
// 初始化所有类型的计数为0
Object.keys(FILE_TYPES).forEach(type => {
@@ -223,21 +228,25 @@ const StorageManager = () => {
// 统计每个文件的类型
displayFiles.forEach((file) => {
const mimetype = file.metadata?.mimetype;
let counted = false;
const mimetype = file.metadata?.mimetype || '';
let matched = false;
// 遍历所有文件类型配置
Object.entries(FILE_TYPES).forEach(([type, mimetypes]) => {
if (mimetypes.includes(mimetype)) {
for (const [type, mimetypes] of Object.entries(FILE_TYPES)) {
if (mimetypes.some(t => mimetype.startsWith(t) || mimetype === t)) {
stats[type]++;
counted = true;
matched = true;
break; // 找到匹配后就跳出循环
}
});
}
// 如果文件类型不在预定义类型,归类为"其他"
if (!counted) {
// 如果没有匹配任何预定义类型,归类为"其他"
if (!matched) {
stats['其他']++;
}
// 更新总数
stats['全部']++;
});
return stats;
@@ -268,7 +277,7 @@ const StorageManager = () => {
const blob = new Blob([fileContent], { type: "text/plain" });
const file = new File([blob], selectedFile.name, { type: "text/plain" });
// 上<EFBFBD><EFBFBD>更新后的文件
// 上更新后的文件
const { error } = await supabase.storage
.from("file")
.update(selectedFile.name, file);
@@ -358,7 +367,7 @@ const StorageManager = () => {
// 加载更多数据
const loadMoreFiles = () => {
if (!hasMore || loading || hasFilters) return; // 有过滤条件不加载更多
if (!hasMore || loading || hasFilters) return; // 有过滤条件<EFBFBD><EFBFBD>不加载更多
fetchAllFiles(false);
};
@@ -378,6 +387,25 @@ const StorageManager = () => {
// 不需要重新调用 fetchAllFiles因为类型筛选是在前端过滤
};
// 处理文件名中的空格
const handleFileName = (fileName) => {
// 替换空格为下划线或编码空格
return fileName.replace(/\s+/g, '_');
};
// 修改文件类型判断
const getFileType = (mimetype) => {
if (!mimetype) return '其他';
for (const [type, mimetypes] of Object.entries(FILE_TYPES)) {
if (mimetypes.some(t => mimetype.startsWith(t) || mimetype === t)) {
return type;
}
}
return '其他';
};
// 渲染文件列表
const renderFileList = () => (
<div className="flex-1 overflow-y-auto" id="scrollableDiv">
@@ -475,12 +503,12 @@ const StorageManager = () => {
// 渲染文件类型标签
const renderTypeTags = () => (
<div className="flex flex-wrap gap-2">
{Object.entries({ 全部: null, ...FILE_TYPES }).map(([type]) => (
{Object.entries({ 全部: null, ...FILE_TYPES, 其他: null }).map(([type]) => (
<Tag.CheckableTag
key={type}
checked={selectedType === type}
onChange={(checked) => handleTypeChange(checked ? type : "全部")}
className="cursor-pointer"
className={`cursor-pointer ${typeStats[type] === 0 ? 'opacity-50' : ''}`}
>
{`${type} (${typeStats[type] || 0})`}
</Tag.CheckableTag>