Skip to content

Commit cff5e4b

Browse files
authored
Merge pull request #828 from zanllp/feature/media-type-filter
feat: Add media type filter support for search functionality
2 parents 6205a6f + 4df86dc commit cff5e4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+108
-62
lines changed

javascript/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Promise.resolve().then(async () => {
1313
<link rel="icon" href="/favicon.ico" />
1414
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1515
<title>Infinite Image Browsing</title>
16-
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-a454705d.js"></script>
16+
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-56203bfb.js"></script>
1717
<link rel="stylesheet" href="/infinite_image_browsing/fe-static/assets/index-d06b4bd6.css">
1818
</head>
1919

scripts/iib/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ class SearchBySubstrReq(BaseModel):
887887
folder_paths: List[str] = None
888888
size: Optional[int] = 200
889889
path_only: Optional[bool] = False
890+
media_type: Optional[str] = None # "all", "image", "video"
890891

891892
@app.post(db_api_base + "/search_by_substr", dependencies=[Depends(verify_secret)])
892893
async def search_by_substr(req: SearchBySubstrReq):
@@ -903,7 +904,8 @@ async def search_by_substr(req: SearchBySubstrReq):
903904
limit=req.size,
904905
regexp=req.regexp,
905906
folder_paths=folder_paths,
906-
path_only=req.path_only
907+
path_only=req.path_only,
908+
media_type=req.media_type
907909
)
908910
return {
909911
"files": filter_allowed_files([x.to_file_info() for x in imgs]),

scripts/iib/db/datamodel.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def safe_batch_remove(cls, conn: Connection, image_ids: List[int]) -> None:
212212
@classmethod
213213
def find_by_substring(
214214
cls, conn: Connection, substring: str, limit: int = 500, cursor="", regexp="", path_only=False,
215-
folder_paths: List[str] = []
215+
folder_paths: List[str] = [], media_type: str = None
216216
) -> tuple[List["Image"], Cursor]:
217217
api_cur = Cursor()
218218
with closing(conn.cursor()) as cur:
@@ -241,7 +241,20 @@ def find_by_substring(
241241
folder_clauses.append("(image.path LIKE ?)")
242242
params.append(os.path.join(folder_path, "%"))
243243
where_clauses.append("(" + " OR ".join(folder_clauses) + ")")
244-
sql = "SELECT * FROM image"
244+
245+
# 构建SQL查询
246+
if media_type and media_type.lower() != "all":
247+
# 需要JOIN到image_tag和tag表来过滤媒体类型
248+
sql = """SELECT DISTINCT image.* FROM image
249+
INNER JOIN image_tag ON image.id = image_tag.image_id
250+
INNER JOIN tag ON image_tag.tag_id = tag.id"""
251+
# 添加媒体类型过滤条件
252+
media_type_name = "Image" if media_type.lower() == "image" else "Video"
253+
where_clauses.append("(tag.type = 'Media Type' AND tag.name = ?)")
254+
params.append(media_type_name)
255+
else:
256+
sql = "SELECT * FROM image"
257+
245258
if where_clauses:
246259
sql += " WHERE "
247260
sql += " AND ".join(where_clauses)

vue/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ declare module '@vue/runtime-core' {
3434
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
3535
ARow: typeof import('ant-design-vue/es')['Row']
3636
ASelect: typeof import('ant-design-vue/es')['Select']
37+
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
3738
ASkeleton: typeof import('ant-design-vue/es')['Skeleton']
3839
ASlider: typeof import('ant-design-vue/es')['Slider']
3940
ASpin: typeof import('ant-design-vue/es')['Spin']

vue/dist/assets/Checkbox-2442c1b9.js renamed to vue/dist/assets/Checkbox-a2afe2f0.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)