mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 08:20:58 +00:00 
			
		
		
		
	Enhancement: downloading torrents list for qbittorrent (#4405)
This commit is contained in:
		
							parent
							
								
									3c28e4af44
								
							
						
					
					
						commit
						22c02f4e45
					
				@ -15,4 +15,5 @@ widget:
 | 
				
			|||||||
  url: http://qbittorrent.host.or.ip
 | 
					  url: http://qbittorrent.host.or.ip
 | 
				
			||||||
  username: username
 | 
					  username: username
 | 
				
			||||||
  password: password
 | 
					  password: password
 | 
				
			||||||
 | 
					  enableLeechProgress: true # optional, defaults to false
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
				
			|||||||
@ -479,6 +479,9 @@ export function cleanServiceGroups(groups) {
 | 
				
			|||||||
          // proxmox
 | 
					          // proxmox
 | 
				
			||||||
          node,
 | 
					          node,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // qbittorrent
 | 
				
			||||||
 | 
					          enableLeechProgress,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // speedtest
 | 
					          // speedtest
 | 
				
			||||||
          bitratePrecision,
 | 
					          bitratePrecision,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -671,6 +674,9 @@ export function cleanServiceGroups(groups) {
 | 
				
			|||||||
        if (type === "spoolman") {
 | 
					        if (type === "spoolman") {
 | 
				
			||||||
          if (spoolIds !== undefined) widget.spoolIds = spoolIds;
 | 
					          if (spoolIds !== undefined) widget.spoolIds = spoolIds;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (type === "qbittorrent") {
 | 
				
			||||||
 | 
					          if (enableLeechProgress !== undefined) widget.enableLeechProgress = JSON.parse(enableLeechProgress);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        return widget;
 | 
					        return widget;
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      return cleanedService;
 | 
					      return cleanedService;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +1,13 @@
 | 
				
			|||||||
import { useTranslation } from "next-i18next";
 | 
					import { useTranslation } from "next-i18next";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import QueueEntry from "../../components/widgets/queue/queueEntry";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Container from "components/services/widget/container";
 | 
					import Container from "components/services/widget/container";
 | 
				
			||||||
import Block from "components/services/widget/block";
 | 
					import Block from "components/services/widget/block";
 | 
				
			||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
					import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Component({ service }) {
 | 
					export default function Component({ service }) {
 | 
				
			||||||
  const { t } = useTranslation();
 | 
					  const { t } = useTranslation();
 | 
				
			||||||
 | 
					 | 
				
			||||||
  const { widget } = service;
 | 
					  const { widget } = service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents");
 | 
					  const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents");
 | 
				
			||||||
@ -29,6 +30,7 @@ export default function Component({ service }) {
 | 
				
			|||||||
  let rateDl = 0;
 | 
					  let rateDl = 0;
 | 
				
			||||||
  let rateUl = 0;
 | 
					  let rateUl = 0;
 | 
				
			||||||
  let completed = 0;
 | 
					  let completed = 0;
 | 
				
			||||||
 | 
					  const leechTorrents = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (let i = 0; i < torrentData.length; i += 1) {
 | 
					  for (let i = 0; i < torrentData.length; i += 1) {
 | 
				
			||||||
    const torrent = torrentData[i];
 | 
					    const torrent = torrentData[i];
 | 
				
			||||||
@ -37,16 +39,31 @@ export default function Component({ service }) {
 | 
				
			|||||||
    if (torrent.progress === 1) {
 | 
					    if (torrent.progress === 1) {
 | 
				
			||||||
      completed += 1;
 | 
					      completed += 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (torrent.state.includes("DL") || torrent.state === "downloading") {
 | 
				
			||||||
 | 
					      leechTorrents.push(torrent);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const leech = torrentData.length - completed;
 | 
					  const leech = torrentData.length - completed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <Container service={service}>
 | 
					    <>
 | 
				
			||||||
      <Block label="qbittorrent.leech" value={t("common.number", { value: leech })} />
 | 
					      <Container service={service}>
 | 
				
			||||||
      <Block label="qbittorrent.download" value={t("common.bibyterate", { value: rateDl, decimals: 1 })} />
 | 
					        <Block label="qbittorrent.leech" value={t("common.number", { value: leech })} />
 | 
				
			||||||
      <Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
 | 
					        <Block label="qbittorrent.download" value={t("common.bibyterate", { value: rateDl, decimals: 1 })} />
 | 
				
			||||||
      <Block label="qbittorrent.upload" value={t("common.bibyterate", { value: rateUl, decimals: 1 })} />
 | 
					        <Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
 | 
				
			||||||
    </Container>
 | 
					        <Block label="qbittorrent.upload" value={t("common.bibyterate", { value: rateUl, decimals: 1 })} />
 | 
				
			||||||
 | 
					      </Container>
 | 
				
			||||||
 | 
					      {widget?.enableLeechProgress &&
 | 
				
			||||||
 | 
					        leechTorrents.map((queueEntry) => (
 | 
				
			||||||
 | 
					          <QueueEntry
 | 
				
			||||||
 | 
					            progress={queueEntry.progress * 100}
 | 
				
			||||||
 | 
					            timeLeft={t("common.duration", { value: queueEntry.eta })}
 | 
				
			||||||
 | 
					            title={queueEntry.name}
 | 
				
			||||||
 | 
					            activity={queueEntry.state}
 | 
				
			||||||
 | 
					            key={`${queueEntry.name}-${queueEntry.amount_left}`}
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        ))}
 | 
				
			||||||
 | 
					    </>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user