mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
First pass of response: shared file
This commit is contained in:
parent
bf4d476f67
commit
feeced7ed3
|
@ -4,6 +4,7 @@ const { v4: uuidv4 } = require("uuid");
|
||||||
const imageCompression = require("browser-image-compression");
|
const imageCompression = require("browser-image-compression");
|
||||||
const blobUtil = require("blob-util");
|
const blobUtil = require("blob-util");
|
||||||
const FD = require("./freedata");
|
const FD = require("./freedata");
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
// https://stackoverflow.com/a/26227660
|
// https://stackoverflow.com/a/26227660
|
||||||
var appDataFolder =
|
var appDataFolder =
|
||||||
|
@ -806,7 +807,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
obj.type = "request";
|
obj.type = "request";
|
||||||
obj.status = "received";
|
obj.status = "received";
|
||||||
obj.snr = "null";
|
obj.snr = "null";
|
||||||
obj.msg = splitted_data[2];
|
obj.msg = "Request for station info";
|
||||||
obj.filename = "null";
|
obj.filename = "null";
|
||||||
obj.filetype = "null";
|
obj.filetype = "null";
|
||||||
obj.file = "null";
|
obj.file = "null";
|
||||||
|
@ -822,7 +823,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
obj.type = "request";
|
obj.type = "request";
|
||||||
obj.status = "received";
|
obj.status = "received";
|
||||||
obj.snr = "null";
|
obj.snr = "null";
|
||||||
obj.msg = splitted_data[2];
|
obj.msg = "Request for shared folder list";
|
||||||
obj.filename = "null";
|
obj.filename = "null";
|
||||||
obj.filetype = "null";
|
obj.filetype = "null";
|
||||||
obj.file = "null";
|
obj.file = "null";
|
||||||
|
@ -830,7 +831,9 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
if (config.enable_request_shared_folder == "True") {
|
if (config.enable_request_shared_folder == "True") {
|
||||||
sendSharedFolderList(item.dxcallsign);
|
sendSharedFolderList(item.dxcallsign);
|
||||||
}
|
}
|
||||||
} else if (splitted_data[1] == "req" && splitted_data[2] == "2") {
|
} else if (splitted_data[1] == "req" && splitted_data[2].substring(0,1) == "2") {
|
||||||
|
let name = splitted_data[2].substring(1);
|
||||||
|
//console.log("In handle req for shared folder file");
|
||||||
obj.uuid = uuidv4().toString();
|
obj.uuid = uuidv4().toString();
|
||||||
obj.timestamp = Math.floor(Date.now() / 1000);
|
obj.timestamp = Math.floor(Date.now() / 1000);
|
||||||
obj.dxcallsign = item.dxcallsign;
|
obj.dxcallsign = item.dxcallsign;
|
||||||
|
@ -838,13 +841,13 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
obj.type = "request";
|
obj.type = "request";
|
||||||
obj.status = "received";
|
obj.status = "received";
|
||||||
obj.snr = "null";
|
obj.snr = "null";
|
||||||
obj.msg = splitted_data[2];
|
obj.msg = "Request for shared file " + name;
|
||||||
obj.filename = "null";
|
obj.filename = "null";
|
||||||
obj.filetype = "null";
|
obj.filetype = "null";
|
||||||
obj.file = "null";
|
obj.file = "null";
|
||||||
|
|
||||||
if (config.enable_request_shared_folder == "True") {
|
if (config.enable_request_shared_folder == "True") {
|
||||||
sendSharedFolderFile(item.dxcallsign);
|
sendSharedFolderFile(item.dxcallsign,name);
|
||||||
}
|
}
|
||||||
} else if (splitted_data[1] == "res-0") {
|
} else if (splitted_data[1] == "res-0") {
|
||||||
obj.uuid = uuidv4().toString();
|
obj.uuid = uuidv4().toString();
|
||||||
|
@ -854,7 +857,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
obj.type = "response";
|
obj.type = "response";
|
||||||
obj.status = "received";
|
obj.status = "received";
|
||||||
obj.snr = "null";
|
obj.snr = "null";
|
||||||
obj.msg = splitted_data[2];
|
obj.msg = "Response for station info";
|
||||||
obj.filename = "null";
|
obj.filename = "null";
|
||||||
obj.filetype = "null";
|
obj.filetype = "null";
|
||||||
obj.file = "null";
|
obj.file = "null";
|
||||||
|
@ -883,7 +886,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
obj.type = "response";
|
obj.type = "response";
|
||||||
obj.status = "received";
|
obj.status = "received";
|
||||||
obj.snr = "null";
|
obj.snr = "null";
|
||||||
obj.msg = splitted_data[2];
|
obj.msg = "Response for shared file list";
|
||||||
obj.filename = "null";
|
obj.filename = "null";
|
||||||
obj.filetype = "null";
|
obj.filetype = "null";
|
||||||
obj.file = "null";
|
obj.file = "null";
|
||||||
|
@ -898,6 +901,21 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
userData.user_shared_folder = filelist;
|
userData.user_shared_folder = filelist;
|
||||||
addFileListToUserDatabaseIfNotExists(userData);
|
addFileListToUserDatabaseIfNotExists(userData);
|
||||||
getSetUserInformation(selected_callsign);
|
getSetUserInformation(selected_callsign);
|
||||||
|
} else if (splitted_data[1] == "res-2") {
|
||||||
|
console.log("In received respons-2");
|
||||||
|
let sharedFileInfo = splitted_data[2].split("/",2);
|
||||||
|
|
||||||
|
obj.uuid = uuidv4().toString();
|
||||||
|
obj.timestamp = Math.floor(Date.now() / 1000);
|
||||||
|
obj.dxcallsign = item.dxcallsign;
|
||||||
|
obj.command = splitted_data[1];
|
||||||
|
obj.type = "received";
|
||||||
|
obj.status = "received";
|
||||||
|
obj.snr = "null";
|
||||||
|
obj.msg = "Response for shared file download";
|
||||||
|
obj.filename = sharedFileInfo[0];
|
||||||
|
obj.filetype = "application/octet-stream";
|
||||||
|
obj.file = FD.btoa_FD(sharedFileInfo[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
add_obj_to_database(obj);
|
add_obj_to_database(obj);
|
||||||
|
@ -1112,7 +1130,7 @@ update_chat = function (obj) {
|
||||||
if (obj.type == "request") {
|
if (obj.type == "request") {
|
||||||
var new_message = `
|
var new_message = `
|
||||||
<div class="p-0 rounded m-auto mt-1 w-50 bg-warning bg-gradient" id="msg-${obj._id}">
|
<div class="p-0 rounded m-auto mt-1 w-50 bg-warning bg-gradient" id="msg-${obj._id}">
|
||||||
<p class="text-small text-white text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-info"></i>Request - ${timestamp} </p>
|
<p class="text-small text-white text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-info"></i>${obj.msg} - ${timestamp} </p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -2109,8 +2127,39 @@ function sendSharedFolderList(dxcallsign) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendSharedFolderFile(dxcallsign) {
|
function sendSharedFolderFile(dxcallsign,filename) {
|
||||||
console.log("DUMMY");
|
|
||||||
|
let filePath = path.join(config.shared_folder_path,filename);
|
||||||
|
console.log("In fuction sendSharedFolderFile ", filePath);
|
||||||
|
|
||||||
|
//Make sure nothing sneaky is going on
|
||||||
|
if (!filePath.startsWith(config.shared_folder_path)) {
|
||||||
|
console.error("File is outside of shared folder path!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
console.warn("File doesn't seem to exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Read file's data
|
||||||
|
let fileData = null;
|
||||||
|
try {
|
||||||
|
//Has to be binary
|
||||||
|
let data = fs.readFileSync(filePath)
|
||||||
|
fileData = data.toString("utf-8");
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcRenderer.send("run-tnc-command", {
|
||||||
|
command: "responseSharedFile",
|
||||||
|
dxcallsign: dxcallsign,
|
||||||
|
file: filename,
|
||||||
|
filedata: fileData
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendUserData(dxcallsign) {
|
function sendUserData(dxcallsign) {
|
||||||
|
|
|
@ -2715,6 +2715,9 @@ ipcRenderer.on("run-tnc-command", (event, arg) => {
|
||||||
if (arg.command == "responseSharedFolderList") {
|
if (arg.command == "responseSharedFolderList") {
|
||||||
sock.sendResponseSharedFolderList(arg.dxcallsign, arg.folderFileList);
|
sock.sendResponseSharedFolderList(arg.dxcallsign, arg.folderFileList);
|
||||||
}
|
}
|
||||||
|
if (arg.command == "responseSharedFile") {
|
||||||
|
sock.sendResponseSharedFile(arg.dxcallsign, arg.file, arg.filedata);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// IPC ACTION FOR AUTO UPDATER
|
// IPC ACTION FOR AUTO UPDATER
|
||||||
|
|
16
gui/sock.js
16
gui/sock.js
|
@ -708,6 +708,7 @@ function sendResponse(dxcallsign, mode, frames, data, command) {
|
||||||
exports.sendRequestInfo = function (dxcallsign) {
|
exports.sendRequestInfo = function (dxcallsign) {
|
||||||
//Command 0 = user/station information
|
//Command 0 = user/station information
|
||||||
//Command 1 = shared folder list
|
//Command 1 = shared folder list
|
||||||
|
//Command 2 = shared file transfer
|
||||||
sendRequest(dxcallsign, 255, 1, "0", "req");
|
sendRequest(dxcallsign, 255, 1, "0", "req");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -715,6 +716,7 @@ exports.sendRequestInfo = function (dxcallsign) {
|
||||||
exports.sendRequestSharedFolderList = function (dxcallsign) {
|
exports.sendRequestSharedFolderList = function (dxcallsign) {
|
||||||
//Command 0 = user/station information
|
//Command 0 = user/station information
|
||||||
//Command 1 = shared folder list
|
//Command 1 = shared folder list
|
||||||
|
//Command 2 = shared file transfer
|
||||||
sendRequest(dxcallsign, 255, 1, "1", "req");
|
sendRequest(dxcallsign, 255, 1, "1", "req");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -722,6 +724,7 @@ exports.sendRequestSharedFolderList = function (dxcallsign) {
|
||||||
exports.sendRequestSharedFile = function (dxcallsign, file) {
|
exports.sendRequestSharedFile = function (dxcallsign, file) {
|
||||||
//Command 0 = user/station information
|
//Command 0 = user/station information
|
||||||
//Command 1 = shared folder list
|
//Command 1 = shared folder list
|
||||||
|
//Command 2 = shared file transfer
|
||||||
sendRequest(dxcallsign, 255, 1, "2" + file, "req");
|
sendRequest(dxcallsign, 255, 1, "2" + file, "req");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -729,16 +732,27 @@ exports.sendRequestSharedFile = function (dxcallsign, file) {
|
||||||
exports.sendResponseInfo = function (dxcallsign, userinfo) {
|
exports.sendResponseInfo = function (dxcallsign, userinfo) {
|
||||||
//Command 0 = user/station information
|
//Command 0 = user/station information
|
||||||
//Command 1 = shared folder list
|
//Command 1 = shared folder list
|
||||||
|
//Command 2 = shared file transfer
|
||||||
sendResponse(dxcallsign, 255, 1, userinfo, "res-0");
|
sendResponse(dxcallsign, 255, 1, userinfo, "res-0");
|
||||||
};
|
};
|
||||||
|
|
||||||
//Send station info response
|
//Send shared folder response
|
||||||
exports.sendResponseSharedFolderList = function (dxcallsign, sharedFolderList) {
|
exports.sendResponseSharedFolderList = function (dxcallsign, sharedFolderList) {
|
||||||
//Command 0 = user/station information
|
//Command 0 = user/station information
|
||||||
//Command 1 = shared folder list
|
//Command 1 = shared folder list
|
||||||
|
//Command 2 = shared file transfer
|
||||||
sendResponse(dxcallsign, 255, 1, sharedFolderList, "res-1");
|
sendResponse(dxcallsign, 255, 1, sharedFolderList, "res-1");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Send shared file response
|
||||||
|
exports.sendResponseSharedFile = function (dxcallsign, sharedFile, sharedFileData) {
|
||||||
|
console.log("In sendResponseSharedFile",dxcallsign,sharedFile,sharedFileData)
|
||||||
|
//Command 0 = user/station information
|
||||||
|
//Command 1 = shared folder list
|
||||||
|
//Command 2 = shared file transfer
|
||||||
|
sendResponse(dxcallsign, 255, 1, sharedFile + "/" + sharedFileData, "res-2");
|
||||||
|
};
|
||||||
|
|
||||||
//STOP TRANSMISSION
|
//STOP TRANSMISSION
|
||||||
exports.stopTransmission = function () {
|
exports.stopTransmission = function () {
|
||||||
command = '{"type" : "arq", "command": "stop_transmission"}';
|
command = '{"type" : "arq", "command": "stop_transmission"}';
|
||||||
|
|
Loading…
Reference in a new issue