Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/715.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,27 @@ export const PLUGIN_SERVICE_RUNTIMES = [
export const CHAT_SERVICE_API_BASE = 'http://127.0.0.1:8000';

export const BRAINDRIVE_CORE_API = 'http://localhost:8005';

// File Upload Constants
export const maxFileSizeBytes = 10 * 1024 * 1024; // 10MB default

export const allowedFileTypes = [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'text/markdown',
'text/html',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.ms-powerpoint',
];

export const allowedFileExtensions = [
'.pdf',
'.doc',
'.docx',
'.md',
'.html',
'.htm',
'.pptx',
'.ppt'
];
3 changes: 2 additions & 1 deletion src/document-view/DocumentManagerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { DocumentList } from './DocumentList';
import { showToast } from '../helpers';
import { DocumentService } from './DocumentService';
import { allowedFileExtensions } from '../constants';

export class DocumentManagerModal extends React.Component<DocumentManagerModalInjectedProps, DocumentManagerModalState> {
// service instance
Expand Down Expand Up @@ -164,7 +165,7 @@ export class DocumentManagerModal extends React.Component<DocumentManagerModalIn
type="file"
ref={this.fileInputRef}
onChange={this.handleFileSelect}
accept=".pdf,.doc,.docx,.md,.html,.htm,.pptx,.ppt"
accept={allowedFileExtensions.join(',')}
className="hidden"
/>
<button
Expand Down
14 changes: 1 addition & 13 deletions src/document-view/DocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,7 @@ export class DocumentService implements IDocumentService {

public uploadFile = async (file: File, collectionId: string): Promise<void> => {
// ... (File validation logic is now here) ...
const validation = validateFile(file, {
maxSizeBytes: 10 * 1024 * 1024,
allowedExtensions: [
'.pdf',
'.doc',
'.docx',
'.md',
'.html',
'.htm',
'.pptx',
'.ppt'
],
});
const validation = validateFile(file);
if (!validation.isValid) {
showToast(validation.error!, 'error');
return;
Expand Down
20 changes: 5 additions & 15 deletions src/helpers/fileValidation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { allowedFileExtensions, maxFileSizeBytes } from "../constants";

export interface FileValidationOptions {
maxSizeBytes?: number;
allowedTypes?: string[];
Expand Down Expand Up @@ -35,14 +37,10 @@ export function formatFileSize(bytes: number): string {
*/
export function validateFile(
file: File,
options: FileValidationOptions = {}
): FileValidationResult {
const {
maxSizeBytes = 10 * 1024 * 1024, // 10MB default
allowedTypes = ['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
allowedExtensions = ['.pdf', '.doc', '.docx']
} = options;

const maxSizeBytes = maxFileSizeBytes;
const allowedExtensions = allowedFileExtensions;

// Check file size
if (file.size > maxSizeBytes) {
return {
Expand All @@ -51,14 +49,6 @@ export function validateFile(
};
}

// Check file type
if (allowedTypes.length > 0 && !allowedTypes.includes(file.type)) {
return {
isValid: false,
error: `File "${file.name}" has an unsupported type. Allowed types: ${allowedTypes.join(', ')}`
};
}

// Check file extension
if (allowedExtensions.length > 0) {
const fileExtension = getFileExtension(file.name);
Expand Down