feature: display total size by tag or tracker of torrents on sidebar (#369)

Bug: #244
This commit is contained in:
Saber
2021-07-15 00:28:15 +08:00
committed by GitHub
parent aa75f44c70
commit ad764648dd
7 changed files with 63 additions and 4 deletions

View File

@@ -15,7 +15,9 @@ class TaxonomyService extends BaseService<TaxonomyServiceEvents> {
taxonomy: Taxonomy = {
statusCounts: {'': 0},
tagCounts: {'': 0, untagged: 0},
tagSizes: {},
trackerCounts: {'': 0},
trackerSizes: {},
};
lastTaxonomy: Taxonomy = this.taxonomy;
@@ -61,7 +63,9 @@ class TaxonomyService extends BaseService<TaxonomyServiceEvents> {
this.lastTaxonomy = {
statusCounts: {...this.taxonomy.statusCounts},
tagCounts: {...this.taxonomy.tagCounts},
tagSizes: {...this.taxonomy.tagSizes},
trackerCounts: {...this.taxonomy.trackerCounts},
trackerSizes: {...this.taxonomy.trackerSizes},
};
torrentStatusMap.forEach((status) => {
@@ -70,7 +74,9 @@ class TaxonomyService extends BaseService<TaxonomyServiceEvents> {
this.taxonomy.statusCounts[''] = 0;
this.taxonomy.tagCounts = {'': 0, untagged: 0};
this.taxonomy.tagSizes = {};
this.taxonomy.trackerCounts = {'': 0};
this.taxonomy.trackerSizes = {};
};
handleProcessTorrentListEnd = ({torrents}: {torrents: TorrentList}) => {
@@ -93,7 +99,9 @@ class TaxonomyService extends BaseService<TaxonomyServiceEvents> {
handleProcessTorrent = (torrentProperties: TorrentProperties) => {
this.incrementStatusCounts(torrentProperties.status);
this.incrementTagCounts(torrentProperties.tags);
this.incrementTagSizes(torrentProperties.tags, torrentProperties.sizeBytes);
this.incrementTrackerCounts(torrentProperties.trackerURIs);
this.incrementTrackerSizes(torrentProperties.trackerURIs, torrentProperties.sizeBytes);
};
incrementStatusCounts(statuses: Array<TorrentStatus>) {
@@ -116,6 +124,16 @@ class TaxonomyService extends BaseService<TaxonomyServiceEvents> {
});
}
incrementTagSizes(tags: TorrentProperties['tags'], sizeBytes: TorrentProperties['sizeBytes']) {
tags.forEach((tag) => {
if (this.taxonomy.tagSizes[tag] != null) {
this.taxonomy.tagSizes[tag] += sizeBytes;
} else {
this.taxonomy.tagSizes[tag] = sizeBytes;
}
});
}
incrementTrackerCounts(trackers: TorrentProperties['trackerURIs']) {
trackers.forEach((tracker) => {
if (this.taxonomy.trackerCounts[tracker] != null) {
@@ -125,6 +143,16 @@ class TaxonomyService extends BaseService<TaxonomyServiceEvents> {
}
});
}
incrementTrackerSizes(trackers: TorrentProperties['trackerURIs'], sizeBytes: TorrentProperties['sizeBytes']) {
trackers.forEach((tracker) => {
if (this.taxonomy.trackerSizes[tracker] != null) {
this.taxonomy.trackerSizes[tracker] += sizeBytes;
} else {
this.taxonomy.trackerSizes[tracker] = sizeBytes;
}
});
}
}
export default TaxonomyService;