Skip to content

Commit ca0899d

Browse files
committed
feat(media): 清空刮削、删除已失效
1 parent 105dc40 commit ca0899d

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

src/pages/manage/media/MediaManage.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
adminStartMediaScan,
1616
adminStartMediaScrape,
1717
adminClearMediaDB,
18+
adminClearMediaScrape,
19+
adminDeleteInvalidMedia,
1820
adminExportMediaDB,
1921
adminImportMediaDB,
2022
adminGetMediaScanProgress,
@@ -499,6 +501,48 @@ export const MediaManagePage = (props: MediaManagePageProps) => {
499501
})
500502
}
501503

504+
// 仅清空刮削数据(保留扫描记录)
505+
const handleClearScrape = async () => {
506+
showConfirm({
507+
title: `清空 ${props.title} 刮削数据`,
508+
message: `确定要清空 ${props.title} 的所有刮削结果吗?\n(扫描得到的文件记录会保留,仅清空封面、简介、评分、刮削时间等字段,便于重新刮削。)`,
509+
confirmText: "清空刮削",
510+
type: "warning",
511+
onConfirm: async () => {
512+
const resp = await adminClearMediaScrape(props.mediaType)
513+
if (resp.code === 200) {
514+
const affected = resp.data?.affected ?? 0
515+
showToast(`已清空刮削数据,共影响 ${affected} 条`)
516+
refetchItems()
517+
} else {
518+
showToast("清空刮削失败: " + resp.message, "error")
519+
}
520+
},
521+
})
522+
}
523+
524+
// 删除已失效条目(对应文件已不存在)
525+
const handleDeleteInvalid = async () => {
526+
showConfirm({
527+
title: `删除 ${props.title} 失效条目`,
528+
message: `将检测 ${props.title} 中所有条目对应的文件 / 文件夹是否仍存在,已失效的条目会被删除。\n此过程可能耗时较久(取决于条目数量),是否继续?`,
529+
confirmText: "删除已失效",
530+
type: "danger",
531+
onConfirm: async () => {
532+
showToast("正在检测失效条目...", "info")
533+
const resp = await adminDeleteInvalidMedia(props.mediaType)
534+
if (resp.code === 200) {
535+
const checked = resp.data?.checked ?? 0
536+
const deleted = resp.data?.deleted ?? 0
537+
showToast(`检测 ${checked} 条,删除 ${deleted} 条已失效条目`)
538+
refetchItems()
539+
} else {
540+
showToast("删除失败: " + resp.message, "error")
541+
}
542+
},
543+
})
544+
}
545+
502546
// ============== 导入 / 导出 ==============
503547

504548
// 触发浏览器下载 Blob
@@ -806,6 +850,12 @@ export const MediaManagePage = (props: MediaManagePageProps) => {
806850
<button onClick={handleImportAll} style={btnStyle("#8b5cf6")}>
807851
⬆️ 导入数据
808852
</button>
853+
<button onClick={handleDeleteInvalid} style={btnStyle("#f97316")}>
854+
🧹 删除已失效
855+
</button>
856+
<button onClick={handleClearScrape} style={btnStyle("#eab308")}>
857+
♻️ 清空刮削
858+
</button>
809859
<button onClick={handleClearAll} style={btnStyle("#ef4444")}>
810860
🗑️ 清空全部
811861
</button>

src/utils/media_api.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ export const adminClearMediaDB = (mediaType: MediaType) =>
142142
params: { media_type: mediaType },
143143
}) as Promise<Resp<null>>
144144

145+
/** 清空刮削数据(保留扫描记录,只清空刮削结果字段)
146+
* mediaType 为空表示清空所有类型
147+
*/
148+
export const adminClearMediaScrape = (mediaType?: MediaType) =>
149+
r.post("/admin/media/clear_scrape", null, {
150+
params: mediaType ? { media_type: mediaType } : {},
151+
}) as Promise<Resp<{ affected: number }>>
152+
153+
/** 删除已失效的媒体条目(对应文件已不存在)
154+
* mediaType 为空表示扫描所有类型
155+
*/
156+
export const adminDeleteInvalidMedia = (mediaType?: MediaType) =>
157+
r.post("/admin/media/delete_invalid", null, {
158+
params: mediaType ? { media_type: mediaType } : {},
159+
}) as Promise<Resp<{ checked: number; deleted: number }>>
160+
145161
/** 导出媒体数据
146162
* - mediaType 为空 + scanPathId 为空 => 全部导出
147163
* - 仅 mediaType => 导出指定类型

0 commit comments

Comments
 (0)