-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30d28af
commit a44be46
Showing
8 changed files
with
440 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Annotated | ||
from fastapi import APIRouter, Depends | ||
from sqlmodel import Session | ||
|
||
from db import get_db | ||
import os | ||
|
||
|
||
setting_router = APIRouter(prefix="/setting", tags=["setting"]) | ||
|
||
SessionDep = Annotated[Session, Depends(get_db)] | ||
|
||
|
||
@setting_router.get("/dir") | ||
async def get_system_dir(path: str = "/") -> dict: | ||
try: | ||
items = os.listdir(path) | ||
files = [] | ||
dirs = [] | ||
|
||
for item in items: | ||
full_path = os.path.join(path, item) | ||
if os.path.isfile(full_path): | ||
files.append(item) | ||
elif os.path.isdir(full_path): | ||
dirs.append(item) | ||
|
||
except NotADirectoryError: | ||
return {"error": "該路徑不是目錄"} | ||
except FileNotFoundError: | ||
return {"error": "找不到路徑"} | ||
except PermissionError: | ||
return {"error": "沒有權限訪問該路徑"} | ||
|
||
return {"files": files, "dirs": dirs, "path": path} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.