diff --git a/src/app/[locale]/pages/search/page.tsx b/src/app/[locale]/pages/search/page.tsx
index 83d2b71..bae66e5 100644
--- a/src/app/[locale]/pages/search/page.tsx
+++ b/src/app/[locale]/pages/search/page.tsx
@@ -2,7 +2,14 @@ import SectionSearchFile from '@/app/ui/search/section-search-file';
import { SupportedFormats } from '@/app/ui/search/supported-formats';
import { SearchStats } from '@/app/ui/search/search-stats';
import { RecentSearches } from '@/app/ui/search/recent-searches';
-export default function Page() {
+import { getAllowedFilesExtensions } from '@/app/actions/fileUpload';
+
+export default async function Page() {
+ const { file_extension: extensionVideo, max_file_size } = await getAllowedFilesExtensions('video');
+ const { file_extension: extensionAudio } = await getAllowedFilesExtensions('audio');
+ const { file_extension: extensionImage } = await getAllowedFilesExtensions('image');
+ const { file_extension: extensionDocument } = await getAllowedFilesExtensions('document');
+
return (
<>
@@ -15,12 +22,22 @@ export default function Page() {
-
+
diff --git a/src/app/styles/pages-styles.scss b/src/app/styles/pages-styles.scss
index c7c36c5..eebb307 100644
--- a/src/app/styles/pages-styles.scss
+++ b/src/app/styles/pages-styles.scss
@@ -3819,6 +3819,7 @@
color: v.$text-s;
font-size: 14px;
line-height: 1.5;
+ text-transform: uppercase;
}
.stat-item {
diff --git a/src/app/ui/search/file-search-panel.tsx b/src/app/ui/search/file-search-panel.tsx
index e762d0e..a21defb 100644
--- a/src/app/ui/search/file-search-panel.tsx
+++ b/src/app/ui/search/file-search-panel.tsx
@@ -23,6 +23,7 @@ export function FileSearchPanel({ fileId, ref }: { fileId: string | null, ref: a
const [paginationLoading, setPaginationLoading] = useState
(false);
const [showGlobalSearch, setShowGlobalSearch] = useState(false);
const queryClient = useQueryClient();
+ const [errorMessage, setErrorMessage] = useState(null);
const [searchTotalPages, setSearchTotalPages] = useState(0);
const [searchCurrentPages, setSearchCurrentPages] = useState(1);
@@ -41,20 +42,21 @@ export function FileSearchPanel({ fileId, ref }: { fileId: string | null, ref: a
const handlerSearchUserFile = useCallback(async (fileId: string, page: number): Promise => {
+ setErrorMessage(null);
try {
let result = await searchUserFiles(fileId);
if (result.content.length) {
setSearchedUserFiles(result.content);
+ setShowGlobalSearch(true);
+ handlerSearchGlobalFile(fileId, page)
} else {
setSearchedUserFilesShowNull(true);
}
} catch (error) {
-
+ setErrorMessage('error');
}
- setShowGlobalSearch(true);
- handlerSearchGlobalFile(fileId, page)
}, [fileId])
@@ -106,6 +108,12 @@ export function FileSearchPanel({ fileId, ref }: { fileId: string | null, ref: a
>
Начать поиск
+
+ {errorMessage && (
+
+ Ошибка поиска
+
+ )}
{(searchedUserFiles.length !== 0) && (
diff --git a/src/app/ui/search/section-search-file.tsx b/src/app/ui/search/section-search-file.tsx
index e93ea28..b89f212 100644
--- a/src/app/ui/search/section-search-file.tsx
+++ b/src/app/ui/search/section-search-file.tsx
@@ -24,12 +24,16 @@ interface FileUploadInitResponse {
}
interface SectionSearchFile {
- fileType: string
- allowedExtensions: string[]
+ allowedExtensions: {
+ images: string[],
+ videos: string[],
+ audios: string[],
+ documents: string[]
+ }
maxFileSize: number
}
-export default function SectionSearchFile({ fileType, allowedExtensions, maxFileSize }: SectionSearchFile) {
+export default function SectionSearchFile({ allowedExtensions, maxFileSize }: SectionSearchFile) {
const fileInputRef = useRef(null);
const [isDragging, setIsDragging] = useState(false);
const [selectedFile, setSelectedFile] = useState(null);
@@ -45,17 +49,49 @@ export default function SectionSearchFile({ fileType, allowedExtensions, maxFile
const t = useTranslations('Global');
+ const allExtensions = useMemo(() => { return [...allowedExtensions.images, ...allowedExtensions.videos, ...allowedExtensions.audios, ...allowedExtensions.documents] }, []);
+
const acceptString = useMemo(() => {
- if (!allowedExtensions || !Array.isArray(allowedExtensions)) {
+ if (!allExtensions || !Array.isArray(allExtensions)) {
return '';
}
- return allowedExtensions.map(e => `.${e}`).join(', ');
- }, [allowedExtensions]);
+ return allExtensions.map(e => `.${e}`).join(', ');
+ }, [allExtensions]);
+
+
+ const getFileType = (fileName: string, allowedExtensions: {
+ images: string[],
+ videos: string[],
+ audios: string[],
+ documents: string[]
+ }): 'image' | 'video' | 'audio' | 'document' | 'unknown' => {
+
+ const lastDotIndex = fileName.lastIndexOf('.');
+ const extension = fileName.substring(lastDotIndex + 1).toLowerCase();
+
+ if (allowedExtensions.images.includes(extension)) {
+ return 'image';
+ }
+
+ if (allowedExtensions.videos.includes(extension)) {
+ return 'video';
+ }
+
+ if (allowedExtensions.audios.includes(extension)) {
+ return 'audio';
+ }
+
+ if (allowedExtensions.documents.includes(extension)) {
+ return 'document';
+ }
+
+ return 'unknown';
+ }
const validateFile = (file: File): { isValid: boolean; errorMessage?: string } => {
- if (!allowedExtensions.includes(file.type as string)) {
+ if (!allExtensions.includes(file.type as string)) {
const extension = file.name.split('.').pop()?.toLowerCase();
- if (!extension || !allowedExtensions.includes(extension as string)) {
+ if (!extension || !allExtensions.includes(extension as string)) {
return {
isValid: false,
errorMessage: t('unsupported-file-format')
@@ -117,7 +153,7 @@ export default function SectionSearchFile({ fileType, allowedExtensions, maxFile
preview: file.size < 10 * 1024 * 1024 ? URL.createObjectURL(file) : undefined
});
- }, [fileType, t]);
+ }, [t]);
const handleFileInputChange = (event: ChangeEvent): void => {
const file = event.target.files?.[0] || null;
@@ -157,6 +193,7 @@ export default function SectionSearchFile({ fileType, allowedExtensions, maxFile
setError(null);
isCancelledRef.current = false;
const file = fileInfo.file;
+ const fileType = getFileType(fileInfo.file.name, allowedExtensions);
try {
const extension = file.name.split('.').pop() || '';
@@ -225,7 +262,7 @@ export default function SectionSearchFile({ fileType, allowedExtensions, maxFile
} finally {
setUploadId(null);
}
- }, [uploadId, fileType]);
+ }, [uploadId, allowedExtensions]);
useEffect(() => {
// Обработка закрытия вкладки
diff --git a/src/app/ui/search/supported-formats.tsx b/src/app/ui/search/supported-formats.tsx
index c73d794..ce9b7ae 100644
--- a/src/app/ui/search/supported-formats.tsx
+++ b/src/app/ui/search/supported-formats.tsx
@@ -1,5 +1,13 @@
import { IconImageFile, IconVideoFile, IconAudioFile, IconDocument } from '@/app/ui/icons/icons';
-export function SupportedFormats() {
+
+interface supportedFormats {
+ extensionVideo: string[]
+ extensionAudio: string[]
+ extensionImage: string[]
+ extensionDocument: string[]
+}
+
+export function SupportedFormats({ extensionVideo, extensionAudio, extensionImage, extensionDocument }: supportedFormats) {
return (
@@ -11,34 +19,34 @@ export function SupportedFormats() {
Изображения
- JPEG, PNG, GIF, BMP
+ {extensionImage.join(', ')}
-
+
Видео
- MP4, AVI, MOV, WMV
+ {extensionVideo.join(', ')}
-
+
Аудио
- MP3, WAV, FLAC, AAC
+ {extensionAudio.join(', ')}
-
+
Документы
- PDF, DOC, DOCX
+ {extensionDocument.join(', ')}