Skip to content

Commit

Permalink
Download fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Donatello-Carboni committed Sep 29, 2024
1 parent 23e8a7e commit b7c9dca
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Backend/Django/testApp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,4 +1440,4 @@ def getUserAgentConnections(request):

return Response(
{"agents": agents, "users": users}, status=status.HTTP_200_OK
)
)
Binary file added Desktop/models/yolov8n.pt
Binary file not shown.
23 changes: 5 additions & 18 deletions Desktop/src/components/GallaryCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,14 @@
console.error("Error calling openFTP:", error);
}
await window.electronAPI.downloadToClient(aip, aport, VideoName, uid, size, token);
await window.electronAPI.downloadToClient(aip, aport, videoName, uid, size, token, videoSource);
// move the video to the download folder
let currentFilePath = VideoName;
let currentFilePath = videoName;
console.log("Current File Path: ", currentFilePath);
console.log("videoSource: ", VideoSource);
await window.electronAPI.moveVideo(currentFilePath, VideoName);
// try {
// const response = await window.electronAPI.downloadVideo(
// VideoName,
// VideoSource
// );
// console.log(response.success, response.filePath);
// } catch (error) {}
// setTimeout(() => {
// // isDownloading.set(false);
// }, 1000);
isDownloading = false;
console.log("videoSource: ", videoSource);
isDownloading = false;
showMoreModal = false;
isDownloaded = true;
Expand Down
8 changes: 4 additions & 4 deletions Desktop/src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,11 @@ ipcMain.handle('upload-to-agent', async (event, ip, port, filepath, uid, size, t



ipcMain.handle('download-to-client', async (event, ip, port, filepath, uid, size, token) => {
ipcMain.handle('download-to-client', async (event, ip, port, filepath, uid, size, token, videoDestination) => {
const scriptPath = 'src/routes/pythonDownload.py';
let rec = await LookupTable.findOne({where: {mname: filepath, uid: uid}});
const mid = rec.mid;
const args = [ip, port, filepath, uid, size, token, mid];
const args = [ip, port, filepath, uid, size, token, mid, videoDestination];

return new Promise((resolve, reject) => {
const {spawn} = require('child_process');
Expand Down Expand Up @@ -908,8 +908,8 @@ ipcMain.handle('get-video-frame', async (event, videoPath) => {
// IPC handler to move a video file from the Deleted folder to the Downloads folder
ipcMain.handle('move-deleted-video-to-downloads', async (event, videoName, filePath) => {
try {
const deletedDir = path.join(path.dirname(filePath), 'Deleted', path.basename(filePath, path.extname(filePath)));
const videoFilePath = path.join(deletedDir, `${videoName}`);
// const deletedDir = path.join(path.dirname(filePath), 'Deleted', path.basename(filePath, path.extname(filePath)));/
const videoFilePath = filePath;

if (!fs.existsSync(videoFilePath)) {
return {success: false, error: 'Video file does not exist'};
Expand Down
2 changes: 1 addition & 1 deletion Desktop/src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
fileExists: (filePath) => fs.existsSync(path.resolve(filePath)),
runPythonScript: (scriptPath, args) => ipcRenderer.invoke('run-python-script', scriptPath, args),
uploadToAgent: (ip, port, filepath, uid, size, token, mname) => ipcRenderer.invoke('upload-to-agent', ip, port, filepath, uid, size, token, mname),
downloadToClient: (ip, port, filepath, uid, size, token) => ipcRenderer.invoke('download-to-client', ip, port, filepath, uid, size, token),
downloadToClient: (ip, port, filepath, uid, size, token, videoDestination) => ipcRenderer.invoke('download-to-client', ip, port, filepath, uid, size, token, videoDestination),
checkFileExistence: (filePath) => ipcRenderer.invoke('check-file-existence', filePath),
deleteVideoFile: (filePath) => ipcRenderer.invoke('delete-video-file',filePath),
getVideoFrame: (videoPath) => ipcRenderer.invoke('get-video-frame', videoPath),
Expand Down
14 changes: 10 additions & 4 deletions Desktop/src/routes/pythonDownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import sys

def receive_file(ip, port, filename, uid, size, token, mid):
def receive_file(ip, port, filename, uid, size, token, mid, videoDestination):
print("File name: ", filename)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
Expand All @@ -22,6 +22,7 @@ def receive_file(ip, port, filename, uid, size, token, mid):
filepath = "./" + filename
s.sendall(filename.encode() + b"\0")

# move the file to the videoDestination
with open(filepath, "wb") as f:
print(f"Receiving file {filename}...")
while True:
Expand All @@ -30,10 +31,13 @@ def receive_file(ip, port, filename, uid, size, token, mid):
break;
f.write(data)
print(f"File {filename} received and saved to {filepath}")

# move the file to the videoDestination
os.rename(filepath, videoDestination)


if __name__ == "__main__":
if len(sys.argv) != 8:
if len(sys.argv) != 9:
print("Usage: python script.py <ip> <port> <filepath> <uid> <size> <token> <mid>")
sys.exit(1)

Expand All @@ -44,7 +48,9 @@ def receive_file(ip, port, filename, uid, size, token, mid):
size = sys.argv[5]
token = sys.argv[6]
mid = sys.argv[7]
videoDestination = sys.argv[8]

print(f"{ip} {port} {filepath} {uid} {size} {token} {mid}")
print(f"{ip} {port} {filepath} {uid} {size} {token} {mid} {videoDestination}")

receive_file(ip, port, filepath, uid, size, token, mid)
receive_file(ip, port, filepath, uid, size, token, mid, videoDestination)

Binary file added Process/pipe4/laneTest.pt
Binary file not shown.

0 comments on commit b7c9dca

Please sign in to comment.