Request file implementation

This commit is contained in:
Mashintime 2023-03-05 01:32:22 -05:00
parent 04d92b2d8c
commit 6afcb82626
3 changed files with 36 additions and 3 deletions

View file

@ -1946,15 +1946,27 @@ function getSetUserInformation(selected_callsign) {
if (typeof data.user_shared_folder !== "undefined") { if (typeof data.user_shared_folder !== "undefined") {
// shared folder table // shared folder table
var icons = ["aac","ai","bmp","cs","css","csv","doc","docx","exe","gif","heic","html","java","jpg","js","json","jsx","key","m4p","md","mdx","mov","mp3","mp4","otf","pdf","php","png","ppt","pptx","psd","py","raw","rb","sass","scss","sh","sql","svg","tiff","tsx","ttf","txt","wav","woff","xls","xlsx","xml","yml"];
var tbl = document.getElementById("sharedFolderTableDX"); var tbl = document.getElementById("sharedFolderTableDX");
tbl.innerHTML = ""; tbl.innerHTML = "";
let counter = 0; let counter = 0;
data.user_shared_folder.forEach((file) => { data.user_shared_folder.forEach((file) => {
var row = document.createElement("tr"); var row = document.createElement("tr");
let dxcall = selected_callsign;
let name = file["name"];
let type = file["extension"];
if (icons.indexOf(type) == -1 ) {
type="bi-file-earmark"
} else {
type="bi-filetype-" + type;
}
let id = document.createElement("td"); let id = document.createElement("td");
let idText = document.createElement("span"); let idText = document.createElement("span");
idText.innerText = counter += 1; counter += 1;
idText.innerHTML += "<i class=\"bi bi-file-earmark-arrow-down\" style=\"font-size: 1.8rem\"></i> " + counter;
id.appendChild(idText); id.appendChild(idText);
row.appendChild(id); row.appendChild(id);
@ -1966,7 +1978,7 @@ function getSetUserInformation(selected_callsign) {
let filetype = document.createElement("td"); let filetype = document.createElement("td");
let filetypeText = document.createElement("span"); let filetypeText = document.createElement("span");
filetypeText.innerHTML = `<i class="bi bi-filetype-${file["extension"]}" style="font-size: 1.8rem"></i>`; filetypeText.innerHTML = `<i class="bi ${type}" style="font-size: 1.8rem"></i>`;
filetype.appendChild(filetypeText); filetype.appendChild(filetypeText);
row.appendChild(filetype); row.appendChild(filetype);
@ -1975,7 +1987,10 @@ function getSetUserInformation(selected_callsign) {
filesizeText.innerText = formatBytes(file["size"], 2); filesizeText.innerText = formatBytes(file["size"], 2);
filesize.appendChild(filesizeText); filesize.appendChild(filesizeText);
row.appendChild(filesize); row.appendChild(filesize);
row.addEventListener("click", function () {
//console.log(name," clicked");
sendFileReq(dxcall,name);
});
tbl.appendChild(row); tbl.appendChild(row);
}); });
} else { } else {
@ -2110,3 +2125,10 @@ function formatBytes(bytes, decimals = 2) {
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
} }
function sendFileReq(dxcall, file) {
//console.log(file," clicked");
ipcRenderer.send("run-tnc-command", {
command: "requestSharedFile",
dxcallsign: dxcall,
file: file
})};

View file

@ -2703,6 +2703,10 @@ ipcRenderer.on("run-tnc-command", (event, arg) => {
sock.sendRequestSharedFolderList(arg.dxcallsign); sock.sendRequestSharedFolderList(arg.dxcallsign);
} }
if (arg.command == "requestSharedFile") {
sock.sendRequestSharedFile(arg.dxcallsign,arg.file);
}
// responses // responses
if (arg.command == "responseUserInfo") { if (arg.command == "responseUserInfo") {
sock.sendResponseInfo(arg.dxcallsign, arg.userinfo); sock.sendResponseInfo(arg.dxcallsign, arg.userinfo);

View file

@ -718,6 +718,13 @@ exports.sendRequestSharedFolderList = function (dxcallsign) {
sendRequest(dxcallsign, 255, 1, "1", "req"); sendRequest(dxcallsign, 255, 1, "1", "req");
}; };
//Send shared file request
exports.sendRequestSharedFile = function (dxcallsign,file) {
//Command 0 = user/station information
//Command 1 = shared folder list
sendRequest(dxcallsign, 255, 1, "2" + file, "req");
};
//Send station info response //Send station info response
exports.sendResponseInfo = function (dxcallsign, userinfo) { exports.sendResponseInfo = function (dxcallsign, userinfo) {
//Command 0 = user/station information //Command 0 = user/station information