(feat:dir-reader) store mime types, file size in db

This commit is contained in:
ManishMadan2882 committed 2025-07-03 18:09:19 +05:30
1 parent 82fc19e7b7
commit 0f7ebcd8e4
1 file changed
+13 -5
+13 -5
View File
@@ -232,16 +232,24 @@ class SimpleDirectoryReader(BaseReader):
continue continue
if self.required_exts is not None and item.suffix not in self.required_exts: if self.required_exts is not None and item.suffix not in self.required_exts:
continue continue
# Store file with its token count if available
full_path = str(item.resolve()) full_path = str(item.resolve())
file_size_bytes = item.stat().st_size
import mimetypes
mime_type = mimetypes.guess_type(item.name)[0] or "application/octet-stream"
if hasattr(self, 'file_token_counts') and full_path in self.file_token_counts: if hasattr(self, 'file_token_counts') and full_path in self.file_token_counts:
current_dict[item.name] = { current_dict[item.name] = {
"type": "file", "type": mime_type,
"token_count": self.file_token_counts[full_path] "token_count": self.file_token_counts[full_path],
"size_bytes": file_size_bytes
} }
else: else:
current_dict[item.name] = {"type": "file"} current_dict[item.name] = {
"type": mime_type,
"size_bytes": file_size_bytes
}
_build_tree(base_path, structure) _build_tree(base_path, structure)
return structure return structure