Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
黄南光
/
wiki_knowledge
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b92fc870
authored
Jun 26, 2026
by
黄南光
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增前端传参排序,筛选
1 parent
eb68a201
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
8 deletions
frontend/src/app/page.tsx
src/api/routes/files.py
frontend/src/app/page.tsx
View file @
b92fc87
This diff is collapsed.
Click to expand it.
src/api/routes/files.py
View file @
b92fc87
...
...
@@ -8,7 +8,7 @@ import logging
logger
=
logging
.
getLogger
(
__name__
)
from
fastapi
import
APIRouter
,
HTTPException
,
UploadFile
,
File
,
Body
from
fastapi
import
APIRouter
,
HTTPException
,
UploadFile
,
File
,
Body
,
Query
from
fastapi.responses
import
FileResponse
from
fastapi.concurrency
import
run_in_threadpool
from
sqlalchemy
import
select
,
func
,
delete
...
...
@@ -21,23 +21,99 @@ from src.tools.document_parser import extract_text_from_file
router
=
APIRouter
()
FILE_LIST_SORT_COLUMNS
=
{
"time"
:
WikiFile
.
created_at
,
"name"
:
WikiFile
.
name
,
"size"
:
WikiFile
.
size
,
"status"
:
WikiFile
.
status
,
"format"
:
WikiFile
.
format
,
"id"
:
WikiFile
.
id
,
}
FILE_LIST_STATUSES
=
{
"All"
,
"Indexed"
,
"Pending"
,
"Ingesting"
,
"Uploading"
,
"Failed"
}
def
_normalize_file_list_options
(
sort_by
:
str
=
"time"
,
sort_order
:
str
=
"desc"
,
status
:
str
=
"All"
,
file_format
:
str
=
"All"
,
)
->
tuple
[
str
,
str
,
str
,
str
]:
normalized_sort_by
=
sort_by
if
sort_by
in
FILE_LIST_SORT_COLUMNS
else
"time"
normalized_sort_order
=
sort_order
.
lower
()
if
sort_order
and
sort_order
.
lower
()
in
{
"asc"
,
"desc"
}
else
"desc"
normalized_status
=
status
if
status
in
FILE_LIST_STATUSES
else
"All"
normalized_format
=
file_format
.
strip
()
if
file_format
and
file_format
.
strip
()
else
"All"
return
normalized_sort_by
,
normalized_sort_order
,
normalized_status
,
normalized_format
def
_apply_file_list_filters
(
query
,
search
:
str
=
""
,
status
:
str
=
"All"
,
file_format
:
str
=
"All"
):
if
search
:
query
=
query
.
where
(
WikiFile
.
name
.
ilike
(
f
"
%
{search}
%
"
))
if
status
!=
"All"
:
query
=
query
.
where
(
WikiFile
.
status
==
status
)
if
file_format
!=
"All"
:
query
=
query
.
where
(
WikiFile
.
format
==
file_format
)
return
query
def
_file_list_order_by
(
sort_by
:
str
=
"time"
,
sort_order
:
str
=
"desc"
):
sort_column
=
FILE_LIST_SORT_COLUMNS
.
get
(
sort_by
,
WikiFile
.
created_at
)
if
sort_order
==
"asc"
:
order_by
=
[
sort_column
.
asc
()]
stability_order
=
WikiFile
.
id
.
asc
()
else
:
order_by
=
[
sort_column
.
desc
()]
stability_order
=
WikiFile
.
id
.
desc
()
if
sort_by
!=
"id"
:
order_by
.
append
(
stability_order
)
return
order_by
@router.get
(
"/files"
)
async
def
list_files
(
page
:
int
=
1
,
page_size
:
int
=
10
,
search
:
str
=
""
):
async
def
list_files
(
page
:
int
=
1
,
page_size
:
int
=
10
,
search
:
str
=
""
,
sort_by
:
str
=
"time"
,
sort_order
:
str
=
"desc"
,
status
:
str
=
"All"
,
file_format
:
str
=
Query
(
"All"
,
alias
=
"format"
),
):
"""从数据库获取原始文件列表及其状态。
状态包括:Pending(待处理)、Ingesting(摄入中)、Indexed(已完成索引)、Failed(失败)。
"""
logger
.
info
(
f
"获取文件列表: page={page}, page_size={page_size}, search='{search}'"
)
sort_by
,
sort_order
,
status
,
file_format
=
_normalize_file_list_options
(
sort_by
=
sort_by
,
sort_order
=
sort_order
,
status
=
status
,
file_format
=
file_format
,
)
logger
.
info
(
"获取文件列表: page=
%
s, page_size=
%
s, search='
%
s', sort_by=
%
s, sort_order=
%
s, status=
%
s, format=
%
s"
,
page
,
page_size
,
search
,
sort_by
,
sort_order
,
status
,
file_format
,
)
async
with
AsyncSessionLocal
()
as
session
:
query
=
select
(
WikiFile
)
if
search
:
query
=
query
.
where
(
WikiFile
.
name
.
ilike
(
f
"
%
{search}
%
"
))
query
=
_apply_file_list_filters
(
select
(
WikiFile
),
search
,
status
,
file_format
)
count_query
=
select
(
func
.
count
())
.
select_from
(
query
.
subquery
())
total_result
=
await
session
.
execute
(
count_query
)
total_count
=
total_result
.
scalar
()
or
0
query
=
query
.
order_by
(
WikiFile
.
created_at
.
desc
())
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
formats_query
=
_apply_file_list_filters
(
select
(
WikiFile
.
format
)
.
distinct
(),
search
=
search
,
status
=
status
,
file_format
=
"All"
,
)
.
order_by
(
WikiFile
.
format
.
asc
())
formats_result
=
await
session
.
execute
(
formats_query
)
format_options
=
[
fmt
for
fmt
in
formats_result
.
scalars
()
.
all
()
if
fmt
]
query
=
query
.
order_by
(
*
_file_list_order_by
(
sort_by
,
sort_order
))
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
result
=
await
session
.
execute
(
query
)
db_files
=
result
.
scalars
()
.
all
()
...
...
@@ -78,7 +154,10 @@ async def list_files(page: int = 1, page_size: int = 10, search: str = ""):
"files"
:
files_list
,
"total"
:
total_count
,
"page"
:
page
,
"page_size"
:
page_size
"page_size"
:
page_size
,
"filter_options"
:
{
"formats"
:
format_options
,
},
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment