You've already forked my-video-workflow
容量单位及小数
This commit is contained in:
@ -16,8 +16,8 @@ def _get_disk_info(path):
|
||||
return {
|
||||
'exist': True,
|
||||
'percent': disk_info.percent,
|
||||
'free': disk_info.free / (1024 ** 2),
|
||||
'total': disk_info.total / (1024 ** 2)
|
||||
'free': _better_size_unit(disk_info.free),
|
||||
'total': _better_size_unit(disk_info.total)
|
||||
}
|
||||
else:
|
||||
return {
|
||||
@ -27,6 +27,27 @@ def _get_disk_info(path):
|
||||
'total': 0
|
||||
}
|
||||
|
||||
|
||||
def _better_size_unit(bytes: int) -> str:
|
||||
if bytes > 8*1024:
|
||||
kbytes = bytes / 1024
|
||||
if kbytes > 8*1024:
|
||||
mbytes = kbytes / 1024
|
||||
if mbytes > 4*1024:
|
||||
gbytes = mbytes / 1024
|
||||
if gbytes > 4*1024:
|
||||
tbytes = gbytes / 1024
|
||||
return "{:.2f}TB".format(tbytes)
|
||||
else:
|
||||
return "{:.2f}GB".format(gbytes)
|
||||
else:
|
||||
return "{:.2f}MB".format(mbytes)
|
||||
else:
|
||||
return "{:.1f}KB".format(kbytes)
|
||||
else:
|
||||
return "{}B".format(bytes)
|
||||
|
||||
|
||||
@blueprint.get("/")
|
||||
def collect_basic_status():
|
||||
return jsonify({
|
||||
|
Reference in New Issue
Block a user