Skip to content

Commit f429efc

Browse files
committed
fix: rename only unrenamed items and add rename button
1 parent 0207742 commit f429efc

File tree

6 files changed

+69
-8
lines changed

6 files changed

+69
-8
lines changed

backend/src/module/api/bangumi.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import APIRouter, Depends
22
from fastapi.responses import JSONResponse
33

4-
from module.manager import TorrentManager
4+
from module.manager import Renamer, TorrentManager
55
from module.models import APIResponse, Bangumi, BangumiUpdate
66
from module.security.api import get_current_user
77

@@ -141,3 +141,21 @@ async def reset_all():
141141
"msg_zh": "重置所有规则成功。",
142142
},
143143
)
144+
145+
146+
@router.post(
147+
"/rename",
148+
response_model=APIResponse,
149+
dependencies=[Depends(get_current_user)],
150+
)
151+
async def rename(data: Bangumi):
152+
with Renamer() as renamer:
153+
bangumi_name, _ = renamer._path_to_bangumi(data.save_path)
154+
renamer.rename(bangumi_name)
155+
return JSONResponse(
156+
status_code=200,
157+
content={
158+
"msg_en": f"Renamed '{data.official_title}' successfully.",
159+
"msg_zh": f"'{data.official_title}' 重命名成功。",
160+
},
161+
)

backend/src/module/manager/renamer.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ def rename_subtitles(
150150
if not renamed:
151151
logger.warning(f"[Renamer] {subtitle_path} rename failed")
152152

153-
def check_multi_version(self):
153+
def check_multi_version(self, tag=None):
154154
if not settings.bangumi_manage.retain_latest_media_version:
155155
return
156-
torrents_info = self.get_torrent_info()
156+
torrents_info = self.get_torrent_info(tag=tag)
157157
grouped_torrents = defaultdict(list)
158158

159159
for torrent_info in torrents_info:
@@ -197,12 +197,15 @@ def check_multi_version(self):
197197
)
198198
self.delete_torrent(torrent_hashes.keys())
199199

200-
def rename(self) -> list[Notification]:
200+
def rename(self, tag="") -> list[Notification]:
201201
# Get torrent info
202202
logger.debug("[Renamer] Start rename process.")
203-
self.check_multi_version()
203+
if tag:
204+
self.check_multi_version(tag=tag)
205+
else:
206+
self.check_multi_version()
204207
rename_method = settings.bangumi_manage.rename_method
205-
torrents_info = self.get_torrent_info()
208+
torrents_info = self.get_torrent_info(tag=tag)
206209
renamed_info: list[Notification] = []
207210
for info in torrents_info:
208211
media_list, subtitle_list = self.check_files(info)

webui/src/api/bangumi.ts

+16
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,20 @@ export const apiBangumi = {
134134
);
135135
return data;
136136
},
137+
/**
138+
* 重新命名
139+
* @param bangumiData - Bangumi 数据
140+
*/
141+
async rename(bangumiData: BangumiRule) {
142+
const postData: BangumiAPI = {
143+
...bangumiData,
144+
filter: bangumiData.filter.join(','),
145+
rss_link: bangumiData.rss_link.join(','),
146+
};
147+
const { data } = await axios.post<ApiSuccess>(
148+
'api/v1/bangumi/rename',
149+
postData
150+
);
151+
return data;
152+
},
137153
};

webui/src/components/ab-edit-rule.vue

+22
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const forceCollectDialog = reactive({
3434
3535
const loading = reactive({
3636
collect: false,
37+
rename: false,
3738
});
3839
3940
watch(show, (val) => {
@@ -91,6 +92,24 @@ function emitEnable() {
9192
emit('enable', rule.value.id);
9293
}
9394
95+
function rename() {
96+
if (rule.value) {
97+
useApi(apiBangumi.rename, {
98+
showMessage: true,
99+
onBeforeExecute() {
100+
loading.rename = true;
101+
},
102+
onSuccess() {
103+
getAll();
104+
show.value = false;
105+
},
106+
onFinally() {
107+
loading.rename = false;
108+
},
109+
}).execute(rule.value);
110+
}
111+
}
112+
94113
const popupTitle = computed(() => {
95114
if (rule.value.deleted) {
96115
return t('homepage.rule.enable_rule');
@@ -136,6 +155,9 @@ const boxSize = computed(() => {
136155
<ab-button size="small" @click="() => showForceCollectDialog(true)">
137156
{{ $t('homepage.rule.force_collect') }}
138157
</ab-button>
158+
<ab-button size="small" :loading="loading.rename" @click="rename">
159+
{{ $t('homepage.rule.rename') }}
160+
</ab-button>
139161
<div fx-cer justify-end gap-x-10>
140162
<ab-button-multi
141163
size="small"

webui/src/i18n/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
"yes_btn": "Yes",
9090
"force_collect": "Force Collect",
9191
"force_collect_hit": "Are you sure you want to force collect?",
92-
"force_collect_title": "Collect"
92+
"force_collect_title": "Collect",
93+
"rename": "Rename again"
9394
}
9495
},
9596
"log": {

webui/src/i18n/zh-CN.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
"yes_btn": "",
9090
"force_collect": "强制收集",
9191
"force_collect_hit": "确定要强制收集吗?",
92-
"force_collect_title": "收集"
92+
"force_collect_title": "收集",
93+
"rename": "重命名"
9394
}
9495
},
9596
"log": {

0 commit comments

Comments
 (0)