mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 16:23:07 -07:00
parent
582e4dcb59
commit
2edb1a0765
1 changed files with 36 additions and 27 deletions
|
@ -354,15 +354,18 @@ window.addEvent('load', function() {
|
||||||
const serverState = {};
|
const serverState = {};
|
||||||
|
|
||||||
const removeTorrentFromCategoryList = function(hash) {
|
const removeTorrentFromCategoryList = function(hash) {
|
||||||
if (hash === null || hash === "")
|
if (!hash)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
let removed = false;
|
let removed = false;
|
||||||
Object.each(category_list, function(category) {
|
for (const key in category_list) {
|
||||||
if (Object.contains(category.torrents, hash)) {
|
if (!Object.hasOwn(category_list, key))
|
||||||
removed = true;
|
continue;
|
||||||
category.torrents.splice(category.torrents.indexOf(hash), 1);
|
|
||||||
|
const category = category_list[key];
|
||||||
|
const deleteResult = category.torrents.delete(hash);
|
||||||
|
removed ||= deleteResult;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return removed;
|
return removed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -370,35 +373,39 @@ window.addEvent('load', function() {
|
||||||
const category = torrent['category'];
|
const category = torrent['category'];
|
||||||
if (typeof category === 'undefined')
|
if (typeof category === 'undefined')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
const hash = torrent['hash'];
|
||||||
if (category.length === 0) { // Empty category
|
if (category.length === 0) { // Empty category
|
||||||
removeTorrentFromCategoryList(torrent['hash']);
|
removeTorrentFromCategoryList(hash);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const categoryHash = genHash(category);
|
const categoryHash = genHash(category);
|
||||||
if (!category_list[categoryHash]) // This should not happen
|
if (!category_list[categoryHash]) { // This should not happen
|
||||||
category_list[categoryHash] = {
|
category_list[categoryHash] = {
|
||||||
name: category,
|
name: category,
|
||||||
torrents: []
|
torrents: []
|
||||||
};
|
};
|
||||||
if (!Object.contains(category_list[categoryHash].torrents, torrent['hash'])) {
|
}
|
||||||
removeTorrentFromCategoryList(torrent['hash']);
|
if (!category_list[categoryHash].torrents.has(hash)) {
|
||||||
category_list[categoryHash].torrents = category_list[categoryHash].torrents.combine([torrent['hash']]);
|
removeTorrentFromCategoryList(hash);
|
||||||
|
category_list[categoryHash].torrents.add(hash);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeTorrentFromTagList = function(hash) {
|
const removeTorrentFromTagList = function(hash) {
|
||||||
if ((hash === null) || (hash === ""))
|
if (!hash)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
let removed = false;
|
let removed = false;
|
||||||
for (const key in tagList) {
|
for (const key in tagList) {
|
||||||
|
if (!Object.hasOwn(tagList, key))
|
||||||
|
continue;
|
||||||
|
|
||||||
const tag = tagList[key];
|
const tag = tagList[key];
|
||||||
if (Object.contains(tag.torrents, hash)) {
|
const deleteResult = tag.torrents.delete(hash);
|
||||||
removed = true;
|
removed ||= deleteResult;
|
||||||
tag.torrents.splice(tag.torrents.indexOf(hash), 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return removed;
|
return removed;
|
||||||
};
|
};
|
||||||
|
@ -407,7 +414,8 @@ window.addEvent('load', function() {
|
||||||
if (torrent['tags'] === undefined) // Tags haven't changed
|
if (torrent['tags'] === undefined) // Tags haven't changed
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
removeTorrentFromTagList(torrent['hash']);
|
const hash = torrent['hash'];
|
||||||
|
removeTorrentFromTagList(hash);
|
||||||
|
|
||||||
if (torrent['tags'].length === 0) // No tags
|
if (torrent['tags'].length === 0) // No tags
|
||||||
return true;
|
return true;
|
||||||
|
@ -419,12 +427,12 @@ window.addEvent('load', function() {
|
||||||
if (!tagList[tagHash]) { // This should not happen
|
if (!tagList[tagHash]) { // This should not happen
|
||||||
tagList[tagHash] = {
|
tagList[tagHash] = {
|
||||||
name: tags,
|
name: tags,
|
||||||
torrents: []
|
torrents: new Set()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!Object.contains(tagList[tagHash].torrents, torrent['hash'])) {
|
if (!tagList[tagHash].torrents.has(hash)) {
|
||||||
|
tagList[tagHash].torrents.add(hash);
|
||||||
added = true;
|
added = true;
|
||||||
tagList[tagHash].torrents.push(torrent['hash']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return added;
|
return added;
|
||||||
|
@ -507,12 +515,13 @@ window.addEvent('load', function() {
|
||||||
for (let i = 0; i < sortedCategories.length; ++i) {
|
for (let i = 0; i < sortedCategories.length; ++i) {
|
||||||
const categoryName = sortedCategories[i];
|
const categoryName = sortedCategories[i];
|
||||||
const categoryHash = genHash(categoryName);
|
const categoryHash = genHash(categoryName);
|
||||||
let categoryCount = category_list[categoryHash].torrents.length;
|
let categoryCount = category_list[categoryHash].torrents.size;
|
||||||
|
|
||||||
if (useSubcategories) {
|
if (useSubcategories) {
|
||||||
for (let j = i + 1; j < sortedCategories.length && sortedCategories[j].startsWith(categoryName + "/"); ++j) {
|
for (let j = (i + 1);
|
||||||
|
(j < sortedCategories.length) && sortedCategories[j].startsWith(categoryName + "/"); ++j) {
|
||||||
const hash = genHash(sortedCategories[j]);
|
const hash = genHash(sortedCategories[j]);
|
||||||
categoryCount += category_list[hash].torrents.length;
|
categoryCount += category_list[hash].torrents.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,7 +580,7 @@ window.addEvent('load', function() {
|
||||||
for (let i = 0; i < sortedTags.length; ++i) {
|
for (let i = 0; i < sortedTags.length; ++i) {
|
||||||
const tagName = sortedTags[i];
|
const tagName = sortedTags[i];
|
||||||
const tagHash = genHash(tagName);
|
const tagHash = genHash(tagName);
|
||||||
const tagCount = tagList[tagHash].torrents.length;
|
const tagCount = tagList[tagHash].torrents.size;
|
||||||
tagFilterList.appendChild(createLink(tagHash, tagName, tagCount));
|
tagFilterList.appendChild(createLink(tagHash, tagName, tagCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,7 +693,7 @@ window.addEvent('load', function() {
|
||||||
category_list[categoryHash] = {
|
category_list[categoryHash] = {
|
||||||
name: category.name,
|
name: category.name,
|
||||||
savePath: category.savePath,
|
savePath: category.savePath,
|
||||||
torrents: []
|
torrents: new Set()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -703,7 +712,7 @@ window.addEvent('load', function() {
|
||||||
if (!tagList[tagHash]) {
|
if (!tagList[tagHash]) {
|
||||||
tagList[tagHash] = {
|
tagList[tagHash] = {
|
||||||
name: tag,
|
name: tag,
|
||||||
torrents: []
|
torrents: new Set()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue