Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文件大小显示不太准 #227

Open
ixuner opened this issue May 27, 2021 · 3 comments
Open

文件大小显示不太准 #227

ixuner opened this issue May 27, 2021 · 3 comments

Comments

@ixuner
Copy link

ixuner commented May 27, 2021

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

1
2

@Achrou
Copy link
Owner

Achrou commented May 27, 2021

export function formatFileSize(bytes) {

@ixuner ixuner closed this as completed May 28, 2021
@ixuner ixuner reopened this May 28, 2021
@ixuner ixuner closed this as completed May 28, 2021
@ixuner ixuner reopened this May 30, 2021
@ixuner
Copy link
Author

ixuner commented May 30, 2021

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

@layahcn
Copy link

layahcn commented Jul 16, 2021

我认为应该是:

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的情况,还能正确地显示大小

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants