Этот коммит содержится в:
Mario Vitale
2023-03-27 16:28:42 +02:00
родитель da7a6825ce
Коммит ba6b97fb62
1142 изменённых файлов: 44 добавлений и 44 удалений

27
e2e-tests/cypress/tests/utils/file.js Обычный файл
Просмотреть файл

@@ -0,0 +1,27 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Converts a file size in bytes into a human-readable string of the form '123MB'.
export function fileSizeToString(bytes) {
// it's unlikely that we'll have files bigger than this
if (bytes > 1024 ** 4) {
// check if file is smaller than 10 to display fractions
if (bytes < (1024 ** 4) * 10) {
return (Math.round((bytes / (1024 ** 4)) * 10) / 10) + 'TB';
}
return Math.round(bytes / (1024 ** 4)) + 'TB';
} else if (bytes > 1024 ** 3) {
if (bytes < (1024 ** 3) * 10) {
return (Math.round((bytes / (1024 ** 3)) * 10) / 10) + 'GB';
}
return Math.round(bytes / (1024 ** 3)) + 'GB';
} else if (bytes > 1024 ** 2) {
if (bytes < (1024 ** 2) * 10) {
return (Math.round((bytes / (1024 ** 2)) * 10) / 10) + 'MB';
}
return Math.round(bytes / (1024 ** 2)) + 'MB';
} else if (bytes > 1024) {
return Math.round(bytes / 1024) + 'KB';
}
return bytes + 'B';
}