Achrou / goindex-theme-acrou

This is a goindex theme.一个goindex的扩展主题。
https://ossdev.node6.workers.dev/
MIT License
1.62k stars 868 forks source link

文件大小显示不太准 #227

Open ixuner opened 3 years ago

ixuner commented 3 years ago

同一个文件,大小945M,在goindex显示的是990.90M。算了一下,应该是按1000换算的,能不能改回按1024换算?在哪里改?

1 2

Achrou commented 3 years ago

https://github.com/Achrou/goindex-theme-acrou/blob/facd77d7f9bc2858d2f50636b0b7ac4311fe402e/src/utils/AcrouUtil.js#L153

ixuner commented 3 years ago

https://github.com/NUSC/goindex-theme-acrou/blob/f51634fa5b30ddeaf92f907e43fdbb3da3290b97/src/utils/AcrouUtil.js#L153 这样改应该没错吧。不过打开网页看大小还是没变,感觉还是引用的你的文件。我都改成自己仓库地址和生成新的Releases,还是没效果。 要不大佬直接修复一下,Releases一个新版本吧。

layahcn commented 3 years ago

我认为应该是:

export function formatFileSize(bytes) {  
    if (bytes >= 1048576000) {  
    bytes = (bytes / 1073741824).toFixed(2) + " GB";  
  } else if (bytes >= 1024000) {  
    bytes = (bytes / 1048576).toFixed(2) + " MB";  
  } else if (bytes >= 1000) {  
    bytes = (bytes / 1024).toFixed(2) + " KB";  
  } else if (bytes > 1) {  
    bytes = bytes + " bytes";  
  } else if (bytes == 1) {  
    bytes = bytes + " byte";  
  } else {  
    bytes = "";  
  }  
  return bytes;  
}

这样就能避免显示成比如1023KB的情况,还能正确地显示大小