mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-03 04:42:39 +02:00
refactor(file_intent): remove _infer_text_file_extension function and standardize fallback filename to 'notes.md'
This commit is contained in:
parent
7bcb6306c5
commit
7134b0feae
2 changed files with 5 additions and 36 deletions
|
|
@ -109,37 +109,6 @@ def _sanitize_path_segment(value: str) -> str:
|
|||
return segment
|
||||
|
||||
|
||||
def _infer_text_file_extension(user_text: str) -> str:
|
||||
lowered = user_text.lower()
|
||||
if any(token in lowered for token in ("json", ".json")):
|
||||
return ".json"
|
||||
if any(token in lowered for token in ("yaml", "yml", ".yaml", ".yml")):
|
||||
return ".yaml"
|
||||
if any(token in lowered for token in ("csv", ".csv")):
|
||||
return ".csv"
|
||||
if any(token in lowered for token in ("python", ".py")):
|
||||
return ".py"
|
||||
if any(token in lowered for token in ("typescript", ".ts", ".tsx")):
|
||||
return ".ts"
|
||||
if any(token in lowered for token in ("javascript", ".js", ".mjs", ".cjs")):
|
||||
return ".js"
|
||||
if any(token in lowered for token in ("html", ".html")):
|
||||
return ".html"
|
||||
if any(token in lowered for token in ("css", ".css")):
|
||||
return ".css"
|
||||
if any(token in lowered for token in ("sql", ".sql")):
|
||||
return ".sql"
|
||||
if any(token in lowered for token in ("toml", ".toml")):
|
||||
return ".toml"
|
||||
if any(token in lowered for token in ("ini", ".ini")):
|
||||
return ".ini"
|
||||
if any(token in lowered for token in ("xml", ".xml")):
|
||||
return ".xml"
|
||||
if any(token in lowered for token in ("markdown", ".md", "readme")):
|
||||
return ".md"
|
||||
return ".md"
|
||||
|
||||
|
||||
def _normalize_directory(value: str) -> str:
|
||||
raw = value.strip().replace("\\", "/")
|
||||
raw = raw.strip("/")
|
||||
|
|
@ -193,7 +162,6 @@ def _fallback_path(
|
|||
suggested_path: str | None = None,
|
||||
user_text: str,
|
||||
) -> str:
|
||||
default_extension = _infer_text_file_extension(user_text)
|
||||
inferred_dir = _infer_directory_from_user_text(user_text)
|
||||
|
||||
sanitized_filename = ""
|
||||
|
|
@ -202,9 +170,9 @@ def _fallback_path(
|
|||
if sanitized_filename.lower().endswith(".txt"):
|
||||
sanitized_filename = f"{sanitized_filename[:-4]}.md"
|
||||
if not sanitized_filename:
|
||||
sanitized_filename = f"notes{default_extension}"
|
||||
sanitized_filename = "notes.md"
|
||||
elif "." not in sanitized_filename:
|
||||
sanitized_filename = f"{sanitized_filename}{default_extension}"
|
||||
sanitized_filename = f"{sanitized_filename}.md"
|
||||
|
||||
normalized_suggested_path = (
|
||||
_normalize_file_path(suggested_path) if suggested_path else ""
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { ChevronDown, ChevronRight, FileText, Folder } from "lucide-react";
|
||||
import { ChevronDown, ChevronRight, FileText, Folder, FolderOpen } from "lucide-react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { DEFAULT_EXCLUDE_PATTERNS } from "@/components/sources/FolderWatchDialog";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
|
|
@ -329,6 +329,7 @@ export function LocalFilesystemBrowser({
|
|||
const renderFolder = useCallback(
|
||||
(folder: LocalFolderNode, depth: number, mount: string) => {
|
||||
const isExpanded = expandedFolderKeys.has(folder.key);
|
||||
const FolderIcon = isExpanded ? FolderOpen : Folder;
|
||||
const childFolders = Array.from(folder.folders.values()).sort((a, b) =>
|
||||
a.name.localeCompare(b.name)
|
||||
);
|
||||
|
|
@ -347,7 +348,7 @@ export function LocalFilesystemBrowser({
|
|||
) : (
|
||||
<ChevronRight className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
)}
|
||||
<Folder className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
<FolderIcon className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
<span className="truncate">{folder.name}</span>
|
||||
</button>
|
||||
{isExpanded && (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue