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

Method _build_file_status_insights

apps/admin/services.py:1131–1193  ·  view source on GitHub ↗
(
        self,
        file_code: FileCodes,
        detail: dict[str, Any],
        now: datetime,
        has_download_limit: bool,
        is_permanent: bool,
        can_download: bool,
    )

Source from the content-addressed store, hash-verified

1129 return f"view_{seed}_{digest}"
1130
1131 def _build_file_status_insights(
1132 self,
1133 file_code: FileCodes,
1134 detail: dict[str, Any],
1135 now: datetime,
1136 has_download_limit: bool,
1137 is_permanent: bool,
1138 can_download: bool,
1139 ) -> dict[str, Any]:
1140 remaining_downloads = detail["remainingDownloads"]
1141 seconds_until_expiration = self._seconds_between(now, file_code.expired_at)
1142 age_seconds = self._seconds_between(file_code.created_at, now)
1143 reasons = []
1144
1145 if detail["isExpired"]:
1146 reasons.append("expired")
1147 if has_download_limit and remaining_downloads == 0:
1148 reasons.append("download_limit_exhausted")
1149 if seconds_until_expiration is not None and 0 < seconds_until_expiration <= 86400:
1150 reasons.append("expires_soon")
1151 if file_code.used_count == 0:
1152 reasons.append("never_retrieved")
1153 if not can_download:
1154 reasons.append("storage_metadata_incomplete")
1155 if file_code.is_chunked:
1156 reasons.append("chunked_upload")
1157
1158 severity = "success"
1159 state = "available"
1160 next_action = "monitor"
1161 if detail["isExpired"] or (has_download_limit and remaining_downloads == 0):
1162 severity = "danger"
1163 state = "expired"
1164 next_action = "extend_or_delete"
1165 elif not can_download:
1166 severity = "danger"
1167 state = "storage_incomplete"
1168 next_action = "inspect_storage"
1169 elif "expires_soon" in reasons:
1170 severity = "warning"
1171 state = "expiring_soon"
1172 next_action = "extend_expiration"
1173 elif is_permanent:
1174 state = "permanent"
1175 next_action = "monitor"
1176
1177 return {
1178 "severity": severity,
1179 "state": state,
1180 "nextAction": next_action,
1181 "next_action": next_action,
1182 "reasons": reasons,
1183 "metrics": {
1184 "ageSeconds": max(age_seconds or 0, 0),
1185 "age_seconds": max(age_seconds or 0, 0),
1186 "secondsUntilExpiration": seconds_until_expiration,
1187 "seconds_until_expiration": seconds_until_expiration,
1188 "remainingDownloads": remaining_downloads,

Callers 2

get_file_detailMethod · 0.95

Calls 1

_seconds_betweenMethod · 0.95

Tested by

no test coverage detected