Add option to set uploadspeed limit to consider torrents as active
This commit is contained in:
@@ -13,6 +13,9 @@
|
|||||||
"displayActiveTorrents": {
|
"displayActiveTorrents": {
|
||||||
"label": "Show active torrents when completed torrents are hidden"
|
"label": "Show active torrents when completed torrents are hidden"
|
||||||
},
|
},
|
||||||
|
"SpeedLimitOfActiveTorrents": {
|
||||||
|
"label": "Upload speed to consider a torrent as active (ko/s)"
|
||||||
|
},
|
||||||
"displayStaleTorrents": {
|
"displayStaleTorrents": {
|
||||||
"label": "Display stale torrents"
|
"label": "Display stale torrents"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
"displayActiveTorrents": {
|
"displayActiveTorrents": {
|
||||||
"label": "Afficher les torrents actifs quand les torrents terminés sont masqués"
|
"label": "Afficher les torrents actifs quand les torrents terminés sont masqués"
|
||||||
},
|
},
|
||||||
|
"SpeedLimitOfActiveTorrents": {
|
||||||
|
"label": "Débit d'upload pour considérer un torrent comme actif (ko/s)"
|
||||||
|
},
|
||||||
"displayStaleTorrents": {
|
"displayStaleTorrents": {
|
||||||
"label": "Afficher les torrents périmés"
|
"label": "Afficher les torrents périmés"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ describe('TorrentTile', () => {
|
|||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: true,
|
displayCompletedTorrents: true,
|
||||||
displayActiveTorrents: true,
|
displayActiveTorrents: true,
|
||||||
|
SpeedLimitOfActiveTorrents: 10,
|
||||||
displayStaleTorrents: false,
|
displayStaleTorrents: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -57,6 +58,7 @@ describe('TorrentTile', () => {
|
|||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: true,
|
displayCompletedTorrents: true,
|
||||||
displayActiveTorrents: true,
|
displayActiveTorrents: true,
|
||||||
|
SpeedLimitOfActiveTorrents: 10,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -93,6 +95,7 @@ describe('TorrentTile', () => {
|
|||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: false,
|
displayCompletedTorrents: false,
|
||||||
displayActiveTorrents: false,
|
displayActiveTorrents: false,
|
||||||
|
SpeedLimitOfActiveTorrents: 10,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -129,12 +132,14 @@ describe('TorrentTile', () => {
|
|||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: false,
|
displayCompletedTorrents: false,
|
||||||
displayActiveTorrents: true,
|
displayActiveTorrents: true,
|
||||||
|
SpeedLimitOfActiveTorrents: 10,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const torrents: NormalizedTorrent[] = [
|
const torrents: NormalizedTorrent[] = [
|
||||||
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
|
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
|
||||||
constructTorrent('HH', 'I am completed and uploading', true, 0, 672),
|
constructTorrent('HH', 'I am completed and uploading less than 10 ko/s (81919 = 9.99ko/s)', true, 0, 81919),
|
||||||
|
constructTorrent('HH', 'I am completed and uploading more than 10 ko/s (81921 = 10.01ko/s)', true, 0, 81921),
|
||||||
constructTorrent('HH', 'I am completed', true, 0, 0),
|
constructTorrent('HH', 'I am completed', true, 0, 0),
|
||||||
constructTorrent('HH', 'I am stale', false, 0, 0),
|
constructTorrent('HH', 'I am stale', false, 0, 0),
|
||||||
];
|
];
|
||||||
@@ -145,9 +150,10 @@ describe('TorrentTile', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(filtered.length).toBe(3);
|
expect(filtered.length).toBe(3);
|
||||||
expect(filtered.at(0)).toBe(torrents[0]);
|
expect(filtered.at(0)).toBe(torrents[0]);
|
||||||
expect(filtered.at(1)).toBe(torrents[1]);
|
expect(filtered.includes(torrents[1])).toBe(false);
|
||||||
expect(filtered.includes(torrents[2])).toBe(false);
|
expect(filtered.at(1)).toBe(torrents[2]);
|
||||||
expect(filtered.at(2)).toBe(torrents[3]);
|
expect(filtered.includes(torrents[3])).toBe(false);
|
||||||
|
expect(filtered.at(2)).toBe(torrents[4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filter by label when whitelist', () => {
|
it('filter by label when whitelist', () => {
|
||||||
@@ -167,6 +173,7 @@ describe('TorrentTile', () => {
|
|||||||
labelFilterIsWhitelist: true,
|
labelFilterIsWhitelist: true,
|
||||||
displayCompletedTorrents: true,
|
displayCompletedTorrents: true,
|
||||||
displayActiveTorrents: true,
|
displayActiveTorrents: true,
|
||||||
|
SpeedLimitOfActiveTorrents: 10,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -203,6 +210,7 @@ describe('TorrentTile', () => {
|
|||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: false,
|
displayCompletedTorrents: false,
|
||||||
displayActiveTorrents: false,
|
displayActiveTorrents: false,
|
||||||
|
SpeedLimitOfActiveTorrents: 10,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ const definition = defineWidget({
|
|||||||
type: 'switch',
|
type: 'switch',
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
},
|
},
|
||||||
|
SpeedLimitOfActiveTorrents: { // Unit : ko/s
|
||||||
|
type: 'number',
|
||||||
|
defaultValue: 10,
|
||||||
|
},
|
||||||
displayStaleTorrents: {
|
displayStaleTorrents: {
|
||||||
type: 'switch',
|
type: 'switch',
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
@@ -198,7 +202,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
|
|||||||
export const filterTorrents = (widget: ITorrent, torrents: NormalizedTorrent[]) => {
|
export const filterTorrents = (widget: ITorrent, torrents: NormalizedTorrent[]) => {
|
||||||
let result = torrents;
|
let result = torrents;
|
||||||
if (!widget.properties.displayCompletedTorrents) {
|
if (!widget.properties.displayCompletedTorrents) {
|
||||||
result = result.filter((torrent) => !torrent.isCompleted || (widget.properties.displayActiveTorrents && torrent.uploadSpeed > 0));
|
result = result.filter((torrent) => !torrent.isCompleted || (widget.properties.displayActiveTorrents && torrent.uploadSpeed > widget.properties.SpeedLimitOfActiveTorrents * 1024 * 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.properties.labelFilter.length > 0) {
|
if (widget.properties.labelFilter.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user