Skip to content

Commit 3dfefc8

Browse files
authored
API for Recently Used Items (#8792)
* feat: add file creation time to model file metadata and user file info * fix linting
1 parent bff60b5 commit 3dfefc8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

app/model_manager.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,21 @@ def recursive_search_models_(self, directory: str, pathIndex: int) -> tuple[list
130130

131131
for file_name in filenames:
132132
try:
133-
relative_path = os.path.relpath(os.path.join(dirpath, file_name), directory)
134-
result.append(relative_path)
135-
except:
136-
logging.warning(f"Warning: Unable to access {file_name}. Skipping this file.")
133+
full_path = os.path.join(dirpath, file_name)
134+
relative_path = os.path.relpath(full_path, directory)
135+
136+
# Get file metadata
137+
file_info = {
138+
"name": relative_path,
139+
"pathIndex": pathIndex,
140+
"modified": os.path.getmtime(full_path), # Add modification time
141+
"created": os.path.getctime(full_path), # Add creation time
142+
"size": os.path.getsize(full_path) # Add file size
143+
}
144+
result.append(file_info)
145+
146+
except Exception as e:
147+
logging.warning(f"Warning: Unable to access {file_name}. Error: {e}. Skipping this file.")
137148
continue
138149

139150
for d in subdirs:
@@ -144,7 +155,7 @@ def recursive_search_models_(self, directory: str, pathIndex: int) -> tuple[list
144155
logging.warning(f"Warning: Unable to access {path}. Skipping this path.")
145156
continue
146157

147-
return [{"name": f, "pathIndex": pathIndex} for f in result], dirs, time.perf_counter()
158+
return result, dirs, time.perf_counter()
148159

149160
def get_model_previews(self, filepath: str) -> list[str | BytesIO]:
150161
dirname = os.path.dirname(filepath)

app/user_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ class FileInfo(TypedDict):
2020
path: str
2121
size: int
2222
modified: int
23+
created: int
2324

2425

2526
def get_file_info(path: str, relative_to: str) -> FileInfo:
2627
return {
2728
"path": os.path.relpath(path, relative_to).replace(os.sep, '/'),
2829
"size": os.path.getsize(path),
29-
"modified": os.path.getmtime(path)
30+
"modified": os.path.getmtime(path),
31+
"created": os.path.getctime(path)
3032
}
3133

3234

0 commit comments

Comments
 (0)