Skip to content

Commit b6cee0f

Browse files
committed
remove redundant code
1 parent 7dd9c86 commit b6cee0f

File tree

6 files changed

+8
-13
lines changed

6 files changed

+8
-13
lines changed

templates/components/llamaindex/typescript/documents/helper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ export async function storeFile(
3636
if (!fileExt) throw new Error(`Unsupported document type: ${mimeType}`);
3737

3838
const fileId = crypto.randomUUID();
39-
const newFilename = `${fileId}_${sanitizeFileName(name)}`;
39+
const newFilename = `${sanitizeFileName(name)}_${fileId}.${fileExt}`;
4040
const filepath = path.join(UPLOADED_FOLDER, newFilename);
4141
const fileUrl = await saveDocument(filepath, fileBuffer);
4242
return {
4343
id: fileId,
4444
name: newFilename,
45-
original_name: name,
4645
size: fileBuffer.length,
4746
type: fileExt,
4847
url: fileUrl,

templates/components/llamaindex/typescript/streaming/annotations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export type DocumentFileType = "csv" | "pdf" | "txt" | "docx";
66
export type DocumentFile = {
77
id: string;
88
name: string;
9-
original_name: string;
109
size: number;
1110
type: string;
1211
url: string;

templates/types/streaming/fastapi/app/api/routers/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class Config:
2626
{
2727
"content": "Name, Age\nAlice, 25\nBob, 30",
2828
"name": "example.csv",
29-
"original_name": "example.csv",
3029
"size": 123,
3130
"id": "123",
3231
"type": "text/csv",

templates/types/streaming/fastapi/app/services/file.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
class DocumentFile(BaseModel):
3030
id: str
3131
name: str # Stored file name
32-
original_name: str # Original file name
3332
type: str = None
3433
size: int = None
3534
url: str = None
@@ -116,7 +115,11 @@ def save_file(
116115
save_dir = os.path.join("output", "uploaded")
117116

118117
file_id = str(uuid.uuid4())
119-
new_file_name = f"{file_id}_{_sanitize_file_name(file_name)}"
118+
sanitized_name = _sanitize_file_name(file_name)
119+
file_extension = os.path.splitext(file_name)[1].lstrip(".")
120+
if file_extension == "":
121+
raise ValueError("File is not supported")
122+
new_file_name = f"{sanitized_name}_{file_id}.{file_extension}"
120123

121124
file_path = os.path.join(save_dir, new_file_name)
122125

@@ -150,9 +153,6 @@ def save_file(
150153
)
151154
file_url_prefix = "http://localhost:8000/api/files"
152155
file_size = os.path.getsize(file_path)
153-
file_type = mimetypes.guess_extension(
154-
mimetypes.guess_type(file_path)[0]
155-
).lstrip(".")
156156

157157
file_url = os.path.join(
158158
file_url_prefix,
@@ -163,8 +163,7 @@ def save_file(
163163
return DocumentFile(
164164
id=file_id,
165165
name=new_file_name,
166-
original_name=file_name,
167-
type=file_type,
166+
type=file_extension,
168167
size=file_size,
169168
path=file_path,
170169
url=file_url,

templates/types/streaming/nextjs/app/components/ui/chat/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const DOCUMENT_FILE_TYPES: DocumentFileType[] = [
3030
export type DocumentFile = {
3131
id: string;
3232
name: string; // The uploaded file name in the backend
33-
original_name: string; // The original file name
3433
size: number; // The file size in bytes
3534
type: DocumentFileType;
3635
url: string; // The URL of the uploaded file in the backend

templates/types/streaming/nextjs/app/components/ui/document-preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function DocumentPreview(props: DocumentPreviewProps) {
4545
<div className="space-y-2">
4646
<DrawerTitle>{type.toUpperCase()} Raw Content</DrawerTitle>
4747
<DrawerDescription>
48-
{name} ({inKB(size)} KB)
48+
{display_name} ({inKB(size)} KB)
4949
</DrawerDescription>
5050
</div>
5151
<DrawerClose asChild>

0 commit comments

Comments
 (0)