Skip to content

Commit cd89148

Browse files
committed
add disable torrent
1 parent 28605f4 commit cd89148

4 files changed

Lines changed: 80 additions & 2 deletions

File tree

backend/src/module/api/torrent.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ async def delete_torrent(url: str):
6868
)
6969

7070

71+
@router.post("/disable",response_model=APIResponse,dependencies=[Depends(get_current_user)])
72+
async def disable_torrent(url:str,name,_id:int):
73+
"""
74+
禁用对应的种子
75+
"""
76+
try:
77+
await TorrentManager().disable_torrent(url,name, _id)
78+
return ResponseModel(
79+
status_code=200,
80+
status=True,
81+
msg_en=f"Successfully disabled torrent with url {url}",
82+
msg_zh=f"成功禁用 url 为 {url} 的种子",
83+
)
84+
except Exception as e:
85+
logger.error(f"[Bangumi] Error disabling torrent: {e}")
86+
return ResponseModel(
87+
status_code=500,
88+
status=False,
89+
msg_en="Internal server error",
90+
msg_zh="服务器内部错误",
91+
)
92+
93+
7194
@router.post(
7295
"/download",
7396
response_model=APIResponse,

backend/src/module/manager/torrent.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,19 @@ async def fetch_all_bangumi_torrents(self,_id:int)->list[Torrent]:
9191
break
9292
exist_torrents.sort(key=lambda x: x.name, reverse=True)
9393
return exist_torrents
94+
95+
async def disable_torrent(self,url,name,_id:int)->bool:
96+
with Database(engine) as db:
97+
bangumi = db.bangumi.search_id(_id)
98+
if not bangumi:
99+
return False
100+
torrent = db.torrent.search_by_url(url)
101+
if not torrent:
102+
torrent = Torrent(url=url,name=name)
103+
torrent.downloaded = True
104+
torrent.renamed = True
105+
torrent.bangumi_official_title = bangumi.official_title
106+
torrent.bangumi_season = bangumi.season
107+
torrent.rss_link = bangumi.rss_link
108+
db.torrent.add(torrent)
109+
return True

webui/src/api/bangumi.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,22 @@ export const apiBangumi = {
186186
);
187187
return data;
188188
},
189+
190+
/**
191+
* 禁用指定的 torrent(将其标记为已下载和已重命名)
192+
* @param url - torrent url
193+
* @param name - torrent name
194+
* @param bangumiId - bangumi id
195+
* @returns axios 请求返回的数据
196+
*/
197+
async disableTorrent(url: string, name: string, bangumiId: number) {
198+
const { data } = await axios.post<ApiSuccess>(
199+
`api/v1/torrent/disable`,
200+
null,
201+
{
202+
params: { url, name, _id: bangumiId }
203+
}
204+
);
205+
return data;
206+
},
189207
};

webui/src/components/ab-torrent-manage.vue

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { Download, Delete, Refresh } from '@icon-park/vue-next';
2+
import { Download, Delete, Refresh, Forbid } from '@icon-park/vue-next';
33
import { NModal, NButton, NDataTable, NTag } from 'naive-ui';
44
import type { DataTableColumns } from 'naive-ui';
55
import type { BangumiRule } from '#/bangumi';
@@ -65,7 +65,7 @@ const columns = computed((): DataTableColumns<Torrent> => [
6565
{
6666
title: t('torrent.actions'),
6767
key: 'actions',
68-
width: 140,
68+
width: 180,
6969
align: 'center',
7070
render(row: Torrent) {
7171
return h(
@@ -82,6 +82,16 @@ const columns = computed((): DataTableColumns<Torrent> => [
8282
},
8383
{ default: () => h(Download, { size: 16 }) }
8484
),
85+
h(
86+
NButton,
87+
{
88+
size: 'small',
89+
type: 'warning',
90+
disabled: row.downloaded && row.renamed,
91+
onClick: () => handleDisable(row),
92+
},
93+
{ default: () => h(Forbid, { size: 16 }) }
94+
),
8595
h(
8696
NButton,
8797
{
@@ -121,6 +131,17 @@ function handleDownload(torrent: Torrent) {
121131
}).execute(props.bangumi.id, torrent);
122132
}
123133
134+
function handleDisable(torrent: Torrent) {
135+
if (!props.bangumi?.id) return;
136+
137+
useApi(apiBangumi.disableTorrent, {
138+
showMessage: true,
139+
onSuccess() {
140+
fetchTorrents(); // 刷新列表
141+
},
142+
}).execute(torrent.url, torrent.name, props.bangumi.id);
143+
}
144+
124145
function handleDelete(torrent: Torrent) {
125146
useApi(apiBangumi.deleteTorrent, {
126147
showMessage: true,

0 commit comments

Comments
 (0)