Skip to content

Commit

Permalink
支持批量删除种子缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
wushuo894 committed Nov 26, 2024
1 parent ca034c3 commit 50887ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
7 changes: 6 additions & 1 deletion src/main/java/ani/rss/action/TorrentAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import ani.rss.util.TorrentUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.Method;
import cn.hutool.http.server.HttpServerRequest;
import cn.hutool.http.server.HttpServerResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;

/**
Expand Down Expand Up @@ -46,12 +48,15 @@ public void del() {
resultErrorMsg("此订阅不存在");
return;
}

List<String> infoHashList = StrUtil.split(infoHash, ",", true, true);

Ani ani = first.get();
File torrentDir = TorrentUtil.getTorrentDir(ani);
File[] files = ObjectUtil.defaultIfNull(torrentDir.listFiles(), new File[]{});
for (File file : files) {
String s = FileUtil.mainName(file);
if (infoHash.equals(s)) {
if (infoHashList.contains(s)) {
log.info("删除种子 {}", file);
FileUtil.del(file);
}
Expand Down
25 changes: 11 additions & 14 deletions ui/src/home/Items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
<el-button bg text :disabled="!selectViews.length" @click="allowDownload" icon="Check" type="primary">允许下载
</el-button>
<el-button bg text :disabled="!selectViews.length" @click="notDownload" icon="Close">禁止下载</el-button>
<popconfirm @confirm="delTorrent" :title="`删除${selectViews.filter(it => it.local).length}个种子缓存?`">
<template #reference>
<el-button icon="Remove" bg text
:disabled="!selectViews.filter(it => it.local).length">
删除种子
</el-button>
</template>
</popconfirm>
</div>
<div style="padding: 0 12px">
<el-table :data="showItems" height="500"
Expand Down Expand Up @@ -51,18 +59,6 @@
<el-button bg text @click="copy(showItems[it.$index])">复制</el-button>
</template>
</el-table-column>
<el-table-column label="操作" width="120">
<template #default="it">
<popconfirm @confirm="delTorrent(showItems[it.$index])" title="删除种子缓存?">
<template #reference>
<el-button bg text
:disabled="!showItems[it.$index].local">
删除种子
</el-button>
</template>
</popconfirm>
</template>
</el-table-column>
</el-table>
</div>
<div style="margin: 4px 0;display: flex;justify-content: end;">
Expand Down Expand Up @@ -146,8 +142,9 @@ let load = () => {
})
}
let delTorrent = (item) => {
api.del(`api/torrent?id=${props.ani.id}&infoHash=${item['infoHash']}`)
let delTorrent = () => {
let infoHash = selectViews.value.filter(it => it['local']).map(it => it['infoHash']).join(",")
api.del(`api/torrent?id=${props.ani.id}&infoHash=${infoHash}`)
.then(res => {
ElMessage.success(res.message)
load()
Expand Down

0 comments on commit 50887ce

Please sign in to comment.