1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-09 07:30:57 +02:00

Speed up listing saved images #1804

This commit is contained in:
Julian Tatsch
2022-12-30 13:52:27 +01:00
parent 982cdaacc0
commit 9b661e79a8
2 changed files with 67 additions and 72 deletions

View File

@@ -26,18 +26,9 @@ if [ -n "$F_cmd" ]; then
fi
;;
getFiles)
ip_addr=$(ip -o -4 addr show | sed 's/.* inet \([^/]*\).*/\1/' | grep -v "127.0.0.1")
for file in $(find /system/sdcard/DCIM/${F_dir}/ -type f)
do
if [[ -f $file ]]; then
file_size=$(ls -lh $file | awk '{print $5}')
file_url=$(ls -lh $file | awk '{print $9}' | sed 's/\/system\/sdcard\/DCIM/viewer/')
file_date=$(ls -lh $file | awk '{print $6 "-" $7 "-" $8}')
file_name=$(ls -lh $file | awk '{print $9}' | awk -F / '{print $(NF)}')
echo "${file_name}#:#${file_size}#:#${file_date}#:#${file_url}"
fi
done
return
if [[ -d /system/sdcard/DCIM/${F_dir} ]]; then
find /system/sdcard/DCIM/${F_dir}/ -type f | xargs ls -lh
fi
;;
sdcardInfo)
echo "sdcardSize#:#$(df -h /system/sdcard | awk 'NR==2{print$4}')"

View File

@@ -1,30 +1,30 @@
//Function to delete a file
function deleteFile(fileName,dir,askuser) {
function deleteFile(fileName, dir, askuser) {
if (askuser) {
var del = confirm("Confirm delete file: "+fileName);
if ( del ) {
$.get("cgi-bin/ui_sdcard.cgi", {cmd: "del_file",file: fileName});
var del = confirm("Confirm delete file: " + fileName);
if (del) {
$.get("cgi-bin/ui_sdcard.cgi", { cmd: "del_file", file: fileName });
getFiles(dir);
}
}
else {
$.get("cgi-bin/ui_sdcard.cgi", {cmd: "del_file",file: fileName});
$.get("cgi-bin/ui_sdcard.cgi", { cmd: "del_file", file: fileName });
getFiles(dir);
}
}
//Function to open picure
function openPicture(img) {
$('#modal_picture_content').html("<img class='w3-modal-content w3-center' src="+img+">");
document.getElementById('modal_picture').style.display='block'
$('#modal_picture_content').html("<img class='w3-modal-content w3-center' src=" + img + ">");
document.getElementById('modal_picture').style.display = 'block'
}
//Function to get video and images files from dir
function getFiles(dir) {
// Get files from dir
$.get("cgi-bin/ui_sdcard.cgi", {cmd: "getFiles", dir: dir}, function(config){
$('#'+dir).html(" <p><button id='del_"+dir+"' class='w3-btn w3-theme'>Delete selected</button></p>\
<table class='w3-table-all' id='result_"+dir+"'>\
$.get("cgi-bin/ui_sdcard.cgi", { cmd: "getFiles", dir: dir }, function (config) {
$('#' + dir).html(" <p><button id='del_" + dir + "' class='w3-btn w3-theme'>Delete selected</button></p>\
<table class='w3-table-all' id='result_"+ dir + "'>\
<thead>\
<tr class='w3-theme'>\
<th>Filename</th>\
@@ -34,41 +34,43 @@ function getFiles(dir) {
</tr>\
</thead>\
<tbody>");
var config_all = config.split("\n");
if ( config_all.length == 1)
$('#'+dir).html("<h1>No files found</h1>");
for (var i = 0; i < config_all.length-1; i++) {
var config_info = config_all[i].split("#:#");
var file_info = config_info[3].split(".");
var html_photo = "";
if (file_info[1] == "jpg")
html_photo = "<span onclick='openPicture(\""+config_info[3]+"\");' title='View picture'><i class='far fa-eye'></i>";
$('#result_'+dir).append("<tr> \
<td>"+config_info[0]+"</td> \
<td>"+config_info[1]+"</td> \
<td>"+config_info[2]+"</td> \
<td> \
<a href=\""+config_info[3]+"\" download><i class='fas fa-download' title='Download file'></i></a> \
<span onclick=\"deleteFile('"+config_info[3]+"','"+dir+"',true)\"><i class='fas fa-trash' title='Delete file'></i></span>\
"+html_photo+"\
</td></tr>");
var config_all = config.split("\n");
if (config_all.length == 1)
$('#' + dir).html("<h1>No files found</h1>");
for (var i = 0; i < config_all.length - 1; i++) {
var config_trim = config_all[i].trim().replace(/\s+/g, " "); // Replace all multiple whitespaces with single space
var config_info = config_trim.split(" ");
var file_path = config_info[8].replace('/system/sdcard/DCIM', '/viewer');
var file_info = file_path.split(".");
var html_photo = "";
if (file_info[1] == "jpg")
html_photo = "<span onclick='openPicture(\"" + file_path + "\");' title='View picture'><i class='far fa-eye'></i>";
var file_full = file_path.split('/');
var file_name = file_full[file_full.length - 1];
var file_date = config_info[5] + "-" + config_info[6] + "-" + config_info[7];
$('#result_' + dir).append("<tr> \
<td>"+ file_name + "</td> \
<td>"+ config_info[4] + "</td> \
<td>"+ file_date + "</td> \
<td><a href=\""+ file_path + "\" download><i class='fas fa-download' title='Download file'></i></a> \
<span onclick=\"deleteFile('"+ file_path + "','" + dir + ",true')\"><i class='fas fa-trash' title='Delete file'></i></span>" + html_photo + "</td></tr>");
}
$('#'+dir).append("</tbody></table><p></p>");
$('#' + dir).append("</tbody></table><p></p>");
var table = $('#result_'+dir).DataTable();
$('#result_'+dir+' tbody').on( 'click', 'tr', function () {
var table = $('#result_' + dir).DataTable();
$('#result_' + dir + ' tbody').on('click', 'tr', function () {
$(this).toggleClass('selected');
} );
$('#del_'+dir).click( function () {
var del = confirm("Confirm delete of "+ table.rows('.selected').data().length +" files");
if(del) {
table.rows('.selected').data().each( function ( value, index ) {
filename = value[3].split("\"");
deleteFile(filename[1],dir,false);
} );
});
$('#del_' + dir).click(function () {
var del = confirm("Confirm delete of " + table.rows('.selected').data().length + " files");
if (del) {
table.rows('.selected').data().each(function (value, index) {
filename = value[3].split("\"");
deleteFile(filename[1], dir, false);
});
}
} );
});
});
@@ -76,27 +78,29 @@ function getFiles(dir) {
function showEvents() {
$.getJSON("cgi-bin/ui_sdcard.cgi", {cmd: "events"}, function(data){
var events = data.filter(item => item.file.endsWith("jpg") ).map(item => {
return { date: new Date(item.date),
detail: {
file : item.file
}};
$.getJSON("cgi-bin/ui_sdcard.cgi", { cmd: "events" }, function (data) {
var events = data.filter(item => item.file.endsWith("jpg")).map(item => {
return {
date: new Date(item.date),
detail: {
file: item.file
}
};
});
var chart = eventDrops({
range: {
start: events.reduce((a, b) => a.date < b.date ? a : b).date,
end: events.reduce((a, b) => a.date > b.date ? a : b).date
},
drop: {
date: d => d.date,
onClick : data => {
openPicture(data.detail.file);
}
}
var chart = eventDrops({
range: {
start: events.reduce((a, b) => a.date < b.date ? a : b).date,
end: events.reduce((a, b) => a.date > b.date ? a : b).date
},
drop: {
date: d => d.date,
onClick: data => {
openPicture(data.detail.file);
}
}
});
d3.select('#events-graph').html("").datum([{ name: "Events", data : events}]).call(chart);
d3.select('#events-graph').html("").datum([{ name: "Events", data: events }]).call(chart);
});
}