mirror of
https://github.com/anasty17/mirror-leech-telegram-bot.git
synced 2025-01-07 03:26:46 +08:00
File rename Implemented in only qbittorrent
This commit is contained in:
parent
69da540d80
commit
3ee6343f34
@ -693,6 +693,16 @@
|
||||
renderFileTree(nodes);
|
||||
}
|
||||
|
||||
function getFullPath(node) {
|
||||
const path = [];
|
||||
let currentNode = findParent(files[0], node.id);
|
||||
while (currentNode) {
|
||||
path.unshift(currentNode.name);
|
||||
currentNode = findParent(files[0], currentNode.id);
|
||||
}
|
||||
return path.length > 0 ? path.join('/') : '';
|
||||
}
|
||||
|
||||
function openEditFileNameModal(node) {
|
||||
modalTitle.textContent = 'Edit File Name';
|
||||
modalBody.innerHTML = `
|
||||
@ -707,12 +717,32 @@
|
||||
const editNameInput = document.getElementById('editNameInput');
|
||||
|
||||
saveNameBtn.addEventListener('click', () => {
|
||||
closeModal();
|
||||
const newName = editNameInput.value.trim();
|
||||
if (newName && newName !== node.name) {
|
||||
node.name = newName;
|
||||
renderFileTree(currentFolder ? currentFolder.children : files);
|
||||
const fullPath = getFullPath(node);
|
||||
const requestUrl = `/app/files/torrent?gid=${urlParams.gid}&pin=${pinInput.value}&mode=rename`;
|
||||
const body = {
|
||||
old_path: fullPath ? `${fullPath}/${node.name}` : node.name,
|
||||
new_path: fullPath ? `${fullPath}/${newName}` : newName,
|
||||
};
|
||||
fetch(requestUrl, {
|
||||
'method': 'POST',
|
||||
'body': JSON.stringify(body),
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
modalTitle.textContent = 'Success!';
|
||||
modalBody.innerHTML = '<p>Your Rename has been submitted successfully.</p>';
|
||||
node.name = newName;
|
||||
renderFileTree(currentFolder ? currentFolder.children : files);
|
||||
} else {
|
||||
modalTitle.textContent = 'Error';
|
||||
modalBody.innerHTML = '<p>There was an error submitting your Rename. Please try again.</p>';
|
||||
}
|
||||
modalFooter.innerHTML = '<button class="btn btn-primary" onclick="closeModal()">Okay</button>';
|
||||
openModal();
|
||||
});
|
||||
}
|
||||
closeModal();
|
||||
});
|
||||
|
||||
editNameInput.addEventListener('keypress', (e) => {
|
||||
@ -746,7 +776,7 @@
|
||||
modalBody.innerHTML = `<p>Submitting your selection ${selectedCount.innerText} ... </p>`;
|
||||
modalFooter.innerHTML = '';
|
||||
openModal();
|
||||
const requestUrl = `/app/files/torrent?gid=${urlParams.gid}&pin=${pinInput.value}`;
|
||||
const requestUrl = `/app/files/torrent?gid=${urlParams.gid}&pin=${pinInput.value}&mode=selection`;
|
||||
fetch(requestUrl, { 'method': 'POST', 'body': JSON.stringify(files) }).then(response => {
|
||||
if (reusableModal.style.display === 'block') {
|
||||
closeModal();
|
||||
@ -785,7 +815,7 @@
|
||||
openModal();
|
||||
return false;
|
||||
}
|
||||
const requestUrl = `/app/files/torrent?gid=${urlParams.gid}&pin=${pinInput.value}`;
|
||||
const requestUrl = `/app/files/torrent?gid=${urlParams.gid}&pin=${pinInput.value}&mode=get`;
|
||||
fetch(requestUrl).then(function (response) {
|
||||
if (response.ok) {
|
||||
return response.json().then(data => {
|
||||
|
@ -8,6 +8,7 @@ from web.nodes import extract_file_ids, make_tree
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
qbittorrent_client = qbClient(
|
||||
host="localhost",
|
||||
port=8090,
|
||||
@ -99,6 +100,7 @@ def handle_torrent():
|
||||
"message": "PIN not specified",
|
||||
}
|
||||
)
|
||||
|
||||
code = ""
|
||||
for nbr in gid:
|
||||
if nbr.isdigit():
|
||||
@ -115,16 +117,42 @@ def handle_torrent():
|
||||
}
|
||||
)
|
||||
if request.method == "POST":
|
||||
if not (mode := request.args.get("mode")):
|
||||
return jsonify(
|
||||
{
|
||||
"files": [],
|
||||
"engine": "",
|
||||
"error": "Mode is not specified",
|
||||
"message": "Mode is not specified",
|
||||
}
|
||||
)
|
||||
data = request.get_json(cache=False, force=True)
|
||||
selected_files, unselected_files = extract_file_ids(data)
|
||||
if len(gid) > 20:
|
||||
selected_files = "|".join(selected_files)
|
||||
unselected_files = "|".join(unselected_files)
|
||||
set_qbittorrent(gid, selected_files, unselected_files)
|
||||
if mode == "rename":
|
||||
if len(gid) > 20:
|
||||
handle_rename(gid, data)
|
||||
content = {
|
||||
"files": [],
|
||||
"engine": "",
|
||||
"error": "",
|
||||
"message": "Rename successfully.",
|
||||
}
|
||||
else:
|
||||
content = {
|
||||
"files": [],
|
||||
"engine": "",
|
||||
"error": "Rename failed.",
|
||||
"message": "Cannot rename aria2c torrent file",
|
||||
}
|
||||
else:
|
||||
selected_files = ",".join(selected_files)
|
||||
set_aria2(gid, selected_files)
|
||||
content = {
|
||||
selected_files, unselected_files = extract_file_ids(data)
|
||||
if len(gid) > 20:
|
||||
selected_files = "|".join(selected_files)
|
||||
unselected_files = "|".join(unselected_files)
|
||||
set_qbittorrent(gid, selected_files, unselected_files)
|
||||
else:
|
||||
selected_files = ",".join(selected_files)
|
||||
set_aria2(gid, selected_files)
|
||||
content = {
|
||||
"files": [],
|
||||
"engine": "",
|
||||
"error": "",
|
||||
@ -149,6 +177,15 @@ def handle_torrent():
|
||||
return jsonify(content)
|
||||
|
||||
|
||||
def handle_rename(gid, data):
|
||||
try:
|
||||
qbittorrent_client.torrents_rename_file(torrent_hash=gid, **data)
|
||||
except NotFound404Error as e:
|
||||
raise NotFound404Error from e
|
||||
except Exception as e:
|
||||
LOGGER.error(f"{e} Errored in renaming")
|
||||
|
||||
|
||||
def set_qbittorrent(gid, selected_files, unselected_files):
|
||||
try:
|
||||
qbittorrent_client.torrents_file_priority(
|
||||
|
Loading…
Reference in New Issue
Block a user