Coverage for seedboxsync/front/views/info.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-26 17:46 +0000

1# 

2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr> 

3# 

4# For the full copyright and license information, please view the LICENSE 

5# file that was distributed with this source code. 

6# 

7"""SeedboxSync Flask vierw for info.""" 

8 

9from datetime import datetime 

10from flask import render_template 

11from humanize import filesize, precisedelta 

12from peewee import fn 

13from seedboxsync.__version__ import __version__ as version 

14from seedboxsync.core.dao import Download, SeedboxSync, TaskStatus 

15from seedboxsync.front.cache import cache 

16from seedboxsync.front.utils import init_flash 

17from seedboxsync.front.views import bp 

18 

19 

20@bp.route("/info") 

21@cache.cached(timeout=60) # pyright: ignore [reportUntypedFunctionDecorator] 

22def info() -> str: 

23 """Information page view.""" 

24 init_flash() 

25 

26 # Download statistics 

27 query_stats = Download.select().where(Download.finished != 0) 

28 total_files = query_stats.count() 

29 total_size = sum([d.seedbox_size for d in query_stats if d.seedbox_size]) 

30 sync_blackhole: TaskStatus | bool 

31 sync_seedbox: TaskStatus | bool 

32 

33 # Get statues 

34 keys = ["sync-blackhole", "sync-seedbox", "heartbeat"] 

35 statuses = {ts.key: ts for ts in TaskStatus.select().where(TaskStatus.key.in_(keys))} 

36 sync_blackhole = statuses.get("sync-blackhole", False) 

37 sync_seedbox = statuses.get("sync-seedbox", False) 

38 heartbeat = statuses.get("heartbeat", False) 

39 

40 # First download statistics 

41 first_date = Download.select(fn.MIN(Download.finished)).where(Download.finished != 0).scalar() 

42 first_delta = "" 

43 if first_date is not None: 

44 first_delta = datetime.now() - first_date 

45 first_delta = precisedelta(first_delta, minimum_unit="days") 

46 

47 info = { 

48 "stats_total_files": total_files, 

49 "stats_total_size": filesize.naturalsize(total_size, True), 

50 "stats_first": first_date, 

51 "stats_first_delta": first_delta, 

52 "version": version, 

53 "seedboxsync_db_version": SeedboxSync.get_db_version(), 

54 "sync_blackhole": sync_blackhole, 

55 "sync_seedbox": sync_seedbox, 

56 "heartbeat": heartbeat, 

57 } 

58 

59 return render_template("info.html", info=info)