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

Update filemanager.py to fix filesize issues #1160

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion filemanager/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def changeOwner(self, path):
ProcessUtilities.executioner(command, website.externalApp)
except:
print("Permisson not changed")



def listForTable(self):
try:
finalData = {}
Expand Down
25 changes: 24 additions & 1 deletion filemanager/static/filemanager/js/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ function getCookie(name) {
return cookieValue;
}

// JavaScript function to convert bytes to a human-readable format
function bytesToHumanReadable(bytes, suffix = 'B') {
let units = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z'];
let i = 0;
while (Math.abs(bytes) >= 1024 && i < units.length - 1) {
bytes /= 1024;
++i;
}
return bytes.toFixed(1) + units[i] + suffix;
}

// JavaScript function to convert kilobytes to a human-readable format
function kilobytesToHumanReadable(kilobytes, suffix = 'KB') {
let units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let i = 0;
while (Math.abs(kilobytes) >= 1024 && i < units.length - 1) {
kilobytes /= 1024;
++i;
}
return kilobytes.toFixed(2) + ' ' + units[i];
}

var fileManager = angular.module('fileManager', ['angularFileUpload']);

fileManager.config(['$interpolateProvider', function ($interpolateProvider) {
Expand Down Expand Up @@ -721,7 +743,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
} else {
var fileName = filesData[keys[i]][0];
var lastModified = filesData[keys[i]][2];
var fileSize = filesData[keys[i]][3];
var fileSizeBytes = parseInt(filesData[keys[i]][3], 10); // Assuming this is the size in kilobytes
var fileSize = kilobytesToHumanReadable(fileSizeBytes); // Convert to human-readable format
var permissions = filesData[keys[i]][4];
var dirCheck = filesData[keys[i]][5];
// console.log(fileName);
Expand Down
4 changes: 2 additions & 2 deletions filemanager/templates/filemanager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<tr>
<th scope="col"></th>
<th scope="col">{% trans "File Name" %}</th>
<th scope="col">{% trans "Size (KB)" %}</th>
<th scope="col">{% trans "Size" %}</th>
<th scope="col">{% trans "Last Modified" %}</th>
<th scope="col">{% trans "Permissions" %}</th>
</tr>
Expand Down Expand Up @@ -738,4 +738,4 @@ <h5 class="modal-title" >{% trans "Confirm Restore!" %} <img ng-hide="cyberPanel
</div>

</body>
</html>
</html>
Loading