Skip to content

Commit

Permalink
Path file from FE to BE when decrypting. Note: it uses a fake path - …
Browse files Browse the repository at this point in the history
…FIX.
  • Loading branch information
loosla committed Jul 13, 2024
1 parent 683a06d commit 3a3b6eb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

type FilesContentRequest struct {
Password string `json:"password"`
// TODO: add file
File string `json:"file"`
}

type FilesContentResponse struct {
Expand Down
4 changes: 4 additions & 0 deletions backend/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"log"
"net/http"
"sync"
Expand All @@ -23,6 +24,9 @@ func filesContentHandler(w http.ResponseWriter, r *http.Request) {
return
}

fmt.Println("File: ", req.File)
fmt.Println("Password: ", req.Password)

fileContent, err := readFromFile(defaultFile)
if err != nil {
http.Error(w, "file not found", http.StatusNotFound)
Expand Down
4 changes: 2 additions & 2 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ app.whenReady().then(() => {
await axios.put('http://localhost:8080/files/save', data);
});

ipcMain.handle('files-content', async (event, password) => {
ipcMain.handle('files-content', async (event, data) => {
try {
const response = await axios.post('http://localhost:8080/files/content', { password });
const response = await axios.post('http://localhost:8080/files/content', data);
return response.data.content;
} catch (error) {
console.error('Error getting the content of the file with the password:', error);
Expand Down
2 changes: 1 addition & 1 deletion electron/preload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { contextBridge, ipcRenderer } = require('electron/renderer');

contextBridge.exposeInMainWorld('api', {
filesContent: (password) => ipcRenderer.invoke('files-content', password),
filesContent: (data) => ipcRenderer.invoke('files-content', data),
filesSave: (data) => ipcRenderer.invoke('files-save', data),
});
12 changes: 3 additions & 9 deletions frontend/src/components/MainComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ import React, { useState, useRef } from 'react';
const TextAreaComponent = () => {
const [textAreaValue, setTextAreaValue] = useState('');
const [password, setPassword] = useState('');
const [file, handleFileUpload] = useState('');

const fileInputRef = useRef(null);

const handleFileUpload = (event) => {
const file = event.target.files[0];
if (file) {
console.log('Selected file:', file);
}
};

const openFileDialog = () => {
fileInputRef.current.click();
};
Expand All @@ -24,7 +18,7 @@ const TextAreaComponent = () => {
};

const handleFetchContent = async () => {
const content = await window.api.filesContent(password);
const content = await window.api.filesContent({file: file, password:password});
setTextAreaValue(content);
};

Expand All @@ -36,7 +30,7 @@ const TextAreaComponent = () => {
type="file"
ref={fileInputRef}
style={{ display: 'none' }}
onChange={handleFileUpload}
onChange={(e) => handleFileUpload(e.target.value)}
/>
<div>
<label htmlFor="password">Password: </label>
Expand Down

0 comments on commit 3a3b6eb

Please sign in to comment.