Skip to content

Commit 083d93a

Browse files
committed
fix(upload): allow markdown (.md) file uploads
Fixes issue #3 markdown files were previously rejected due to MIME type mismatch. This change updates file validation to rely on file extensions only, ensuring consistent support across browsers (e.g., Safari/Windows where MIME may be missing). Also updates the input element to use centralized allowed file constants.
1 parent b9182f0 commit 083d93a

File tree

6 files changed

+34
-31
lines changed

6 files changed

+34
-31
lines changed

dist/715.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,27 @@ export const PLUGIN_SERVICE_RUNTIMES = [
127127
export const CHAT_SERVICE_API_BASE = 'http://127.0.0.1:8000';
128128

129129
export const BRAINDRIVE_CORE_API = 'http://localhost:8005';
130+
131+
// File Upload Constants
132+
export const maxFileSizeBytes = 10 * 1024 * 1024; // 10MB default
133+
134+
export const allowedFileTypes = [
135+
'application/pdf',
136+
'application/msword',
137+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
138+
'text/markdown',
139+
'text/html',
140+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
141+
'application/vnd.ms-powerpoint',
142+
];
143+
144+
export const allowedFileExtensions = [
145+
'.pdf',
146+
'.doc',
147+
'.docx',
148+
'.md',
149+
'.html',
150+
'.htm',
151+
'.pptx',
152+
'.ppt'
153+
];

src/document-view/DocumentManagerModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { DocumentList } from './DocumentList';
1111
import { showToast } from '../helpers';
1212
import { DocumentService } from './DocumentService';
13+
import { allowedFileExtensions } from '../constants';
1314

1415
export class DocumentManagerModal extends React.Component<DocumentManagerModalInjectedProps, DocumentManagerModalState> {
1516
// service instance
@@ -164,7 +165,7 @@ export class DocumentManagerModal extends React.Component<DocumentManagerModalIn
164165
type="file"
165166
ref={this.fileInputRef}
166167
onChange={this.handleFileSelect}
167-
accept=".pdf,.doc,.docx,.md,.html,.htm,.pptx,.ppt"
168+
accept={allowedFileExtensions.join(',')}
168169
className="hidden"
169170
/>
170171
<button

src/document-view/DocumentService.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,7 @@ export class DocumentService implements IDocumentService {
6666

6767
public uploadFile = async (file: File, collectionId: string): Promise<void> => {
6868
// ... (File validation logic is now here) ...
69-
const validation = validateFile(file, {
70-
maxSizeBytes: 10 * 1024 * 1024,
71-
allowedExtensions: [
72-
'.pdf',
73-
'.doc',
74-
'.docx',
75-
'.md',
76-
'.html',
77-
'.htm',
78-
'.pptx',
79-
'.ppt'
80-
],
81-
});
69+
const validation = validateFile(file);
8270
if (!validation.isValid) {
8371
showToast(validation.error!, 'error');
8472
return;

src/helpers/fileValidation.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { allowedFileExtensions, maxFileSizeBytes } from "../constants";
2+
13
export interface FileValidationOptions {
24
maxSizeBytes?: number;
35
allowedTypes?: string[];
@@ -35,14 +37,10 @@ export function formatFileSize(bytes: number): string {
3537
*/
3638
export function validateFile(
3739
file: File,
38-
options: FileValidationOptions = {}
3940
): FileValidationResult {
40-
const {
41-
maxSizeBytes = 10 * 1024 * 1024, // 10MB default
42-
allowedTypes = ['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
43-
allowedExtensions = ['.pdf', '.doc', '.docx']
44-
} = options;
45-
41+
const maxSizeBytes = maxFileSizeBytes;
42+
const allowedExtensions = allowedFileExtensions;
43+
4644
// Check file size
4745
if (file.size > maxSizeBytes) {
4846
return {
@@ -51,14 +49,6 @@ export function validateFile(
5149
};
5250
}
5351

54-
// Check file type
55-
if (allowedTypes.length > 0 && !allowedTypes.includes(file.type)) {
56-
return {
57-
isValid: false,
58-
error: `File "${file.name}" has an unsupported type. Allowed types: ${allowedTypes.join(', ')}`
59-
};
60-
}
61-
6252
// Check file extension
6353
if (allowedExtensions.length > 0) {
6454
const fileExtension = getFileExtension(file.name);

0 commit comments

Comments
 (0)