MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / dashboard

Function dashboard

apps/admin/views.py:88–156  ·  view source on GitHub ↗
(file_service: FileService = Depends(get_file_service))

Source from the content-addressed store, hash-verified

86
87@admin_api.get("/dashboard")
88async def dashboard(file_service: FileService = Depends(get_file_service)):
89 all_codes = await FileCodes.all()
90 all_size = sum([code.size for code in all_codes])
91 sys_start = await KeyValue.filter(key="sys_start").first()
92 now = await get_now()
93 today_start = now.replace(hour=0, minute=0, second=0, microsecond=0)
94 yesterday_start = today_start - datetime.timedelta(days=1)
95 yesterday_end = today_start - datetime.timedelta(microseconds=1)
96 yesterday_codes = FileCodes.filter(
97 created_at__gte=yesterday_start, created_at__lte=yesterday_end
98 )
99 today_codes = FileCodes.filter(created_at__gte=today_start)
100 yesterday_file_codes = await yesterday_codes
101 today_file_codes = await today_codes
102 expired_count = 0
103 for file_code in all_codes:
104 if await file_code.is_expired():
105 expired_count += 1
106 health_summary = await file_service.build_file_health_summary(all_codes, now=now)
107
108 text_count = sum(1 for file_code in all_codes if file_code.text is not None)
109 chunked_count = sum(1 for file_code in all_codes if file_code.is_chunked)
110 used_count = sum([file_code.used_count for file_code in all_codes])
111 suffix_counter = Counter(
112 "Text" if file_code.text is not None else (file_code.suffix or "file")
113 for file_code in all_codes
114 )
115 recent_file_codes = sorted(
116 all_codes,
117 key=lambda file_code: file_code.created_at.timestamp()
118 if file_code.created_at
119 else 0,
120 reverse=True,
121 )[:8]
122 recent_activities = await file_service.list_admin_activities(limit=8)
123 return APIResponse(
124 detail={
125 "totalFiles": len(all_codes),
126 "storageUsed": str(all_size),
127 "sysUptime": sys_start.value if sys_start else None,
128 "yesterdayCount": len(yesterday_file_codes),
129 "yesterdaySize": str(sum([code.size for code in yesterday_file_codes])),
130 "todayCount": len(today_file_codes),
131 "todaySize": str(sum([code.size for code in today_file_codes])),
132 "activeCount": len(all_codes) - expired_count,
133 "expiredCount": expired_count,
134 "textCount": text_count,
135 "fileCount": len(all_codes) - text_count,
136 "chunkedCount": chunked_count,
137 "usedCount": used_count,
138 "storageBackend": settings.file_storage,
139 "uploadSizeLimit": settings.uploadSize,
140 "openUpload": settings.openUpload,
141 "enableChunk": settings.enableChunk,
142 "maxSaveSeconds": settings.max_save_seconds,
143 **health_summary,
144 "healthSummary": health_summary,
145 "topSuffixes": [

Callers

nothing calls this directly

Calls 8

get_nowFunction · 0.90
APIResponseClass · 0.90
list_admin_activitiesMethod · 0.80
firstMethod · 0.45
filterMethod · 0.45
is_expiredMethod · 0.45

Tested by

no test coverage detected