mirror of
https://github.com/fireinrain/JHS-enhance.git
synced 2026-09-28 07:36:38 +08:00
多目录可选删除,暂时无法删除下载记录
This commit is contained in:
Vendored
+72
-23
@@ -8082,7 +8082,6 @@ ${err.stack}` : "");
|
||||
}
|
||||
return fileId;
|
||||
}
|
||||
|
||||
async deleteOfflineTasksByKeyword(keyword) {
|
||||
try {
|
||||
const singInfo = await (async () => {
|
||||
@@ -8715,7 +8714,7 @@ ${err.stack}` : "");
|
||||
title="点击查看匹配详情">匹配${matchList.length}个</a>`);
|
||||
const $deleteBtn = $box2.find(".delete115Svg");
|
||||
if ($deleteBtn.length > 0 && matchList[0].dirId) {
|
||||
$deleteBtn.attr("data-dir-id", matchList[0].dirId);
|
||||
$deleteBtn.attr("data-match", JSON.stringify(matchList));
|
||||
$deleteBtn.show();
|
||||
}
|
||||
} else {
|
||||
@@ -8723,7 +8722,7 @@ ${err.stack}` : "");
|
||||
title="点击重新尝试匹配">未匹配</a>`);
|
||||
const $deleteBtn = $box2.find(".delete115Svg");
|
||||
if ($deleteBtn.length > 0) {
|
||||
$deleteBtn.removeAttr("data-dir-id");
|
||||
$deleteBtn.removeAttr("data-match");
|
||||
$deleteBtn.hide();
|
||||
}
|
||||
}
|
||||
@@ -8788,7 +8787,7 @@ ${err.stack}` : "");
|
||||
title="${title}">匹配${matchList.length}个</a>`);
|
||||
const $deleteBtn = $box2.find(".delete115Svg");
|
||||
if ($deleteBtn.length > 0 && matchList[0].dirId) {
|
||||
$deleteBtn.attr("data-dir-id", matchList[0].dirId);
|
||||
$deleteBtn.attr("data-match", JSON.stringify(matchList));
|
||||
$deleteBtn.show();
|
||||
}
|
||||
} else $box2.find(".video-title").prepend(`<a class='jhs-match-error-btn a-info'
|
||||
@@ -10107,37 +10106,87 @@ ${err.stack}` : "");
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const $btn = $(event.currentTarget);
|
||||
const dirId = $btn.attr("data-dir-id");
|
||||
if (!dirId) {
|
||||
show.error("未找到115目录ID");
|
||||
const matchData = $btn.attr("data-match");
|
||||
if (!matchData) {
|
||||
show.error("未找到115匹配数据");
|
||||
return;
|
||||
}
|
||||
const matchList = JSON.parse(matchData);
|
||||
const $box2 = $btn.closest(".item");
|
||||
const { carNum: carNum2 } = this.getBoxCarInfo($box2);
|
||||
utils.q(event, `确认删除115中作品 "${carNum2}" 的整个目录吗?此操作不可撤销!`, (async () => {
|
||||
this.showDeleteDialog(carNum2, matchList, $box2);
|
||||
}));
|
||||
}
|
||||
|
||||
showDeleteDialog(carNum2, matchList, $box2) {
|
||||
const formatSize = (bytes) => {
|
||||
if (!bytes) return "-";
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
let size = parseFloat(bytes), unit = 0;
|
||||
for (; size >= 1024 && unit < units.length - 1;) size /= 1024, unit++;
|
||||
return size.toFixed(2) + " " + units[unit];
|
||||
};
|
||||
let html = '<div style="padding: 15px; max-height: 400px; overflow-y: auto;">';
|
||||
html += `<div style="margin-bottom: 12px; font-size: 14px;">作品 <b>${carNum2}</b> 匹配到 <b>${matchList.length}</b> 个文件夹:</div>`;
|
||||
html += '<div style="margin-bottom: 10px;"><label style="cursor: pointer;"><input type="checkbox" class="jhs-delete-select-all" checked> <b>全选</b></label></div>';
|
||||
for (let i = 0; i < matchList.length; i++) {
|
||||
const m = matchList[i];
|
||||
html += `<div style="margin-bottom: 6px; padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 4px; background: #fafafa;">
|
||||
<label style="display: flex; align-items: flex-start; cursor: pointer; width: 100%;">
|
||||
<input type="checkbox" class="jhs-delete-folder-cb" data-index="${i}" checked style="margin-top: 3px; flex-shrink: 0;">
|
||||
<span style="margin-left: 8px; flex: 1;">
|
||||
<div style="word-break: break-all;">${m.name}</div>
|
||||
<div style="font-size: 12px; color: #888; margin-top: 2px;">${formatSize(m.size)} | ${m.createTime}</div>
|
||||
</span>
|
||||
</label>
|
||||
</div>`;
|
||||
}
|
||||
html += "</div>";
|
||||
const layerIndex = layer.open({
|
||||
type: 1,
|
||||
title: `删除115作品文件夹`,
|
||||
content: html,
|
||||
area: ["520px", "auto"],
|
||||
btn: ["确定删除", "取消"],
|
||||
shadeClose: false,
|
||||
yes: async (index) => {
|
||||
const $layer = $(`#layui-layer${index}`);
|
||||
const checked = $layer.find(".jhs-delete-folder-cb:checked");
|
||||
if (0 === checked.length) {
|
||||
show.error("请至少选择一个文件夹");
|
||||
return;
|
||||
}
|
||||
const selected = checked.map((function () {
|
||||
return parseInt($(this).data("index"));
|
||||
})).get();
|
||||
layer.close(index);
|
||||
let loadObj = loading();
|
||||
let deletedCount = 0;
|
||||
try {
|
||||
const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", {
|
||||
pid: 0,
|
||||
"fid[0]": dirId
|
||||
});
|
||||
loadObj.close();
|
||||
if (result && result.state) {
|
||||
show.ok(`作品 "${carNum2}" 已从115删除`);
|
||||
const matchPlugin = this.getBean("WangPan115MatchPlugin");
|
||||
const matchList = await matchPlugin.searchFiles(carNum2);
|
||||
matchPlugin.updateMatchStatus($box2, carNum2, matchList);
|
||||
this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2);
|
||||
} else {
|
||||
const errMsg = result && result.error_msg ? result.error_msg : "未知错误";
|
||||
show.error(`删除失败: ${errMsg}`);
|
||||
for (const i of selected) {
|
||||
const m = matchList[i];
|
||||
const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", {
|
||||
pid: m.dirId,
|
||||
"fid[0]": m.folderId
|
||||
});
|
||||
result && result.state ? deletedCount++ : console.error(`删除失败: ${m.name}`, result);
|
||||
}
|
||||
loadObj.close();
|
||||
show.ok(`作品 "${carNum2}" 已删除 ${deletedCount} 个文件夹`);
|
||||
const matchPlugin = this.getBean("WangPan115MatchPlugin");
|
||||
const newMatchList = await matchPlugin.searchFiles(carNum2);
|
||||
matchPlugin.updateMatchStatus($box2, carNum2, newMatchList);
|
||||
this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2);
|
||||
} catch (error) {
|
||||
loadObj.close();
|
||||
console.error("删除115文件失败:", error);
|
||||
show.error(`删除失败: ${error.message || "网络错误"}`);
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
$(`#layui-layer${layerIndex}`).on("change", ".jhs-delete-select-all", (function () {
|
||||
const checked = $(this).prop("checked");
|
||||
$(`#layui-layer${layerIndex} .jhs-delete-folder-cb`).prop("checked", checked);
|
||||
}));
|
||||
}
|
||||
showImg($svgElement, $img, carNum2) {
|
||||
|
||||
+70
-22
@@ -139,40 +139,88 @@ class CoverButtonPlugin extends BasePlugin {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const $btn = $(event.currentTarget);
|
||||
const dirId = $btn.attr("data-dir-id");
|
||||
if (!dirId) {
|
||||
show.error("未找到115目录ID");
|
||||
const matchData = $btn.attr("data-match");
|
||||
if (!matchData) {
|
||||
show.error("未找到115匹配数据");
|
||||
return;
|
||||
}
|
||||
const matchList = JSON.parse(matchData);
|
||||
const $box2 = $btn.closest(".item");
|
||||
const {carNum: carNum2} = this.getBoxCarInfo($box2);
|
||||
utils.q(event, `确认删除115中作品 "${carNum2}" 的整个目录吗?此操作不可撤销!`, (async () => {
|
||||
this.showDeleteDialog(carNum2, matchList, $box2);
|
||||
}));
|
||||
}
|
||||
|
||||
showDeleteDialog(carNum2, matchList, $box2) {
|
||||
const formatSize = bytes => {
|
||||
if (!bytes) return "-";
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
let size = parseFloat(bytes), unit = 0;
|
||||
for (; size >= 1024 && unit < units.length - 1;) size /= 1024, unit++;
|
||||
return size.toFixed(2) + " " + units[unit];
|
||||
};
|
||||
let html = '<div style="padding: 15px; max-height: 400px; overflow-y: auto;">';
|
||||
html += `<div style="margin-bottom: 12px; font-size: 14px;">作品 <b>${carNum2}</b> 匹配到 <b>${matchList.length}</b> 个文件夹:</div>`;
|
||||
html += '<div style="margin-bottom: 10px;"><label style="cursor: pointer;"><input type="checkbox" class="jhs-delete-select-all" checked> <b>全选</b></label></div>';
|
||||
for (let i = 0; i < matchList.length; i++) {
|
||||
const m = matchList[i];
|
||||
html += `<div style="margin-bottom: 6px; padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 4px; background: #fafafa;">
|
||||
<label style="display: flex; align-items: flex-start; cursor: pointer; width: 100%;">
|
||||
<input type="checkbox" class="jhs-delete-folder-cb" data-index="${i}" checked style="margin-top: 3px; flex-shrink: 0;">
|
||||
<span style="margin-left: 8px; flex: 1;">
|
||||
<div style="word-break: break-all;">${m.name}</div>
|
||||
<div style="font-size: 12px; color: #888; margin-top: 2px;">${formatSize(m.size)} | ${m.createTime}</div>
|
||||
</span>
|
||||
</label>
|
||||
</div>`;
|
||||
}
|
||||
html += "</div>";
|
||||
const layerIndex = layer.open({
|
||||
type: 1,
|
||||
title: `删除115作品文件夹`,
|
||||
content: html,
|
||||
area: ["520px", "auto"],
|
||||
btn: ["确定删除", "取消"],
|
||||
shadeClose: !1,
|
||||
yes: async index => {
|
||||
const $layer = $(`#layui-layer${index}`);
|
||||
const checked = $layer.find(".jhs-delete-folder-cb:checked");
|
||||
if (0 === checked.length) {
|
||||
show.error("请至少选择一个文件夹");
|
||||
return;
|
||||
}
|
||||
const selected = checked.map((function () {
|
||||
return parseInt($(this).data("index"));
|
||||
})).get();
|
||||
layer.close(index);
|
||||
let loadObj = loading();
|
||||
let deletedCount = 0;
|
||||
try {
|
||||
// 使用旧版115删除API删除整个作品目录
|
||||
// 删除后也会尝试删除对应的离线下载任务记录,避免重新下载时提示"任务已存在"
|
||||
// 注意:旧版任务删除接口(task_del)可能已失效,新版接口需要安全验证,若删除失败请手动清理
|
||||
const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", {
|
||||
pid: 0,
|
||||
"fid[0]": dirId
|
||||
});
|
||||
loadObj.close();
|
||||
if (result && result.state) {
|
||||
show.ok(`作品 "${carNum2}" 已从115删除`);
|
||||
const matchPlugin = this.getBean("WangPan115MatchPlugin");
|
||||
const matchList = await matchPlugin.searchFiles(carNum2);
|
||||
matchPlugin.updateMatchStatus($box2, carNum2, matchList);
|
||||
// this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2);
|
||||
} else {
|
||||
const errMsg = result && result.error_msg ? result.error_msg : "未知错误";
|
||||
show.error(`删除失败: ${errMsg}`);
|
||||
for (const i of selected) {
|
||||
const m = matchList[i];
|
||||
const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", {
|
||||
pid: m.dirId,
|
||||
"fid[0]": m.folderId
|
||||
});
|
||||
result && result.state ? deletedCount++ : console.error(`删除失败: ${m.name}`, result);
|
||||
}
|
||||
loadObj.close();
|
||||
show.ok(`作品 "${carNum2}" 已删除 ${deletedCount} 个文件夹`);
|
||||
const matchPlugin = this.getBean("WangPan115MatchPlugin");
|
||||
const newMatchList = await matchPlugin.searchFiles(carNum2);
|
||||
matchPlugin.updateMatchStatus($box2, carNum2, newMatchList);
|
||||
//暂时没有删除离线任务的功能
|
||||
//this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2);
|
||||
} catch (error) {
|
||||
loadObj.close();
|
||||
console.error("删除115文件失败:", error);
|
||||
show.error(`删除失败: ${error.message || "网络错误"}`);
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
$(`#layui-layer${layerIndex}`).on("change", ".jhs-delete-select-all", (function () {
|
||||
const checked = $(this).prop("checked");
|
||||
$(`#layui-layer${layerIndex} .jhs-delete-folder-cb`).prop("checked", checked);
|
||||
}));
|
||||
}
|
||||
showImg($svgElement, $img, carNum2) {
|
||||
|
||||
@@ -146,6 +146,7 @@ class WangPan115TaskPlugin extends BasePlugin {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
//TODO: 暂时没有删除离线任务
|
||||
// async deleteOfflineTasksByKeyword(keyword) {
|
||||
// try {
|
||||
// const singInfo = await (async () => {
|
||||
|
||||
@@ -345,14 +345,14 @@ const _WangPan115MatchPlugin = class _WangPan115MatchPlugin extends BasePlugin {
|
||||
$box2.find(".jhs-match-btn").replaceWith(`<a class='jhs-match-btn a-success' \n data-keyword="${carNum2}"\n data-match='${JSON.stringify(matchList)}'\n title="点击查看匹配详情">匹配${matchList.length}个</a>`);
|
||||
const $deleteBtn = $box2.find(".delete115Svg");
|
||||
if ($deleteBtn.length > 0 && matchList[0].dirId) {
|
||||
$deleteBtn.attr("data-dir-id", matchList[0].dirId);
|
||||
$deleteBtn.attr("data-match", JSON.stringify(matchList));
|
||||
$deleteBtn.show();
|
||||
}
|
||||
} else {
|
||||
$box2.find(".jhs-match-btn").replaceWith(`<a class='jhs-match-error-btn a-info' data-keyword="${carNum2}" \n title="点击重新尝试匹配">未匹配</a>`);
|
||||
const $deleteBtn = $box2.find(".delete115Svg");
|
||||
if ($deleteBtn.length > 0) {
|
||||
$deleteBtn.removeAttr("data-dir-id");
|
||||
$deleteBtn.removeAttr("data-match");
|
||||
$deleteBtn.hide();
|
||||
}
|
||||
}
|
||||
@@ -409,7 +409,7 @@ const _WangPan115MatchPlugin = class _WangPan115MatchPlugin extends BasePlugin {
|
||||
$box2.find(".video-title").prepend(`<a class='jhs-match-btn a-success' \n data-keyword="${carNum2}"\n data-match='${JSON.stringify(matchList)}'\n title="${title}">匹配${matchList.length}个</a>`);
|
||||
const $deleteBtn = $box2.find(".delete115Svg");
|
||||
if ($deleteBtn.length > 0 && matchList[0].dirId) {
|
||||
$deleteBtn.attr("data-dir-id", matchList[0].dirId);
|
||||
$deleteBtn.attr("data-match", JSON.stringify(matchList));
|
||||
$deleteBtn.show();
|
||||
}
|
||||
} else $box2.find(".video-title").prepend(`<a class='jhs-match-error-btn a-info' \n data-keyword="${carNum2}" \n title="未匹配,点击重试">未匹配</a>`);
|
||||
|
||||
Reference in New Issue
Block a user