Compare commits
3 commits
a2bdf2b1bf
...
765aa5357e
Author | SHA1 | Date | |
---|---|---|---|
765aa5357e | |||
0a7b0b7d4a | |||
54137139e2 |
8 changed files with 69 additions and 25 deletions
|
@ -3,7 +3,37 @@ import { RSA_dec_data as RSA_dec } from "./rsa.js";
|
||||||
window.addEventListener("load", () => main());
|
window.addEventListener("load", () => main());
|
||||||
|
|
||||||
const main = () => {
|
const main = () => {
|
||||||
const pub_key = window.location.hash.slice(1).split(":");
|
/* Handle when a file is added to the input element */
|
||||||
const hash = window.location.pathname.split("/").pop();
|
const button = document.getElementById("download");
|
||||||
console.log(pub_key, hash);
|
button.addEventListener("click", () => {
|
||||||
|
const req = new XMLHttpRequest();
|
||||||
|
req.open("POST", "/api/download");
|
||||||
|
req.setRequestHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
const pub_key = window.location.hash
|
||||||
|
.slice(1)
|
||||||
|
.split(":")
|
||||||
|
.map((v) => BigInt(v));
|
||||||
|
const hash = window.location.pathname.split("/").pop();
|
||||||
|
|
||||||
|
// Send the hash to the server
|
||||||
|
req.send(JSON.stringify(hash));
|
||||||
|
|
||||||
|
req.onload = () => {
|
||||||
|
if (req.status == 200) {
|
||||||
|
// Decrypt the file
|
||||||
|
const decrypted_file = RSA_dec(
|
||||||
|
req.responseText
|
||||||
|
.slice(1, -2)
|
||||||
|
.split(",")
|
||||||
|
.map((v) => BigInt(v)),
|
||||||
|
pub_key
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(decrypted_file);
|
||||||
|
} else {
|
||||||
|
console.error("Download failed.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,8 +70,9 @@ const send = (file, element) => {
|
||||||
gen_RSA_keypair(1024).then(([pub_key, sec_key]) => {
|
gen_RSA_keypair(1024).then(([pub_key, sec_key]) => {
|
||||||
element = update(element, "Chiffrement du fichier...", "H3");
|
element = update(element, "Chiffrement du fichier...", "H3");
|
||||||
|
|
||||||
|
console.log(RSA_enc(content, sec_key));
|
||||||
let data = {
|
let data = {
|
||||||
file: RSA_enc(content, sec_key).map((v) => v.toString()),
|
file: RSA_enc(content, sec_key).join(","),
|
||||||
};
|
};
|
||||||
|
|
||||||
element = update(element, "Téléversement...", "H3");
|
element = update(element, "Téléversement...", "H3");
|
||||||
|
@ -109,7 +110,6 @@ const send = (file, element) => {
|
||||||
input.readOnly = true;
|
input.readOnly = true;
|
||||||
div.appendChild(input);
|
div.appendChild(input);
|
||||||
|
|
||||||
// TODO: Change button textContent on click
|
|
||||||
let button = document.createElement("BUTTON");
|
let button = document.createElement("BUTTON");
|
||||||
button.textContent = "Copier le lien";
|
button.textContent = "Copier le lien";
|
||||||
div.appendChild(button);
|
div.appendChild(button);
|
||||||
|
|
|
@ -73,7 +73,8 @@ main {
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-area,
|
.upload-area,
|
||||||
.link-area {
|
.link-area,
|
||||||
|
.download-area {
|
||||||
border: 2px dashed var(--border);
|
border: 2px dashed var(--border);
|
||||||
height: 70vh;
|
height: 70vh;
|
||||||
width: 65vw;
|
width: 65vw;
|
||||||
|
@ -124,7 +125,8 @@ main {
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-area > button {
|
.link-area > button,
|
||||||
|
.download-area > button {
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
border: 2px solid var(--shadow);
|
border: 2px solid var(--shadow);
|
||||||
width: 50%;
|
width: 50%;
|
||||||
|
@ -137,7 +139,8 @@ main {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-area > button:hover {
|
.link-area > button:hover,
|
||||||
|
.download-area > button:hover {
|
||||||
background-color: var(--text-color);
|
background-color: var(--text-color);
|
||||||
color: var(--bg-color);
|
color: var(--bg-color);
|
||||||
box-shadow: 0 4px 15px 0 var(--shadow), 0 4px 15px 0 var(--shadow);
|
box-shadow: 0 4px 15px 0 var(--shadow), 0 4px 15px 0 var(--shadow);
|
||||||
|
@ -150,7 +153,8 @@ main {
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-area,
|
.upload-area,
|
||||||
.link-area {
|
.link-area,
|
||||||
|
.download-area {
|
||||||
height: 65vh;
|
height: 65vh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +166,9 @@ main {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-area {
|
.upload-area,
|
||||||
|
.link-area,
|
||||||
|
.download-area {
|
||||||
width: 35vw;
|
width: 35vw;
|
||||||
height: 55vh;
|
height: 55vh;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
from flask import Blueprint, redirect
|
from config import Config
|
||||||
|
from flask import Blueprint, jsonify, redirect, request
|
||||||
from werkzeug.wrappers.response import Response
|
from werkzeug.wrappers.response import Response
|
||||||
|
|
||||||
router = Blueprint("download", __name__)
|
router = Blueprint("download", __name__)
|
||||||
|
|
||||||
|
|
||||||
@router.route("<file_hash>", methods=["POST"])
|
@router.route("", methods=["POST"])
|
||||||
def download(file_hash: str) -> Response:
|
def download() -> Response:
|
||||||
"""Download interface"""
|
"""Download interface (send file to javascript client)"""
|
||||||
# TODO: Send the encrypted file to the javascript client
|
json = request.get_json()
|
||||||
print("download of file", file_hash)
|
if json:
|
||||||
return redirect("index")
|
data = ""
|
||||||
|
with open(f"{Config.uploads_dir}/{json}", 'r') as f:
|
||||||
|
data = f.read()
|
||||||
|
|
||||||
|
# Send the encrypted file to the javascript client
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
return redirect("/file")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from flask import Blueprint, redirect, request, jsonify
|
from flask import Blueprint, jsonify, redirect, request
|
||||||
from utils.misc import hash_data
|
from utils.misc import hash_data
|
||||||
from werkzeug.wrappers.response import Response
|
from werkzeug.wrappers.response import Response
|
||||||
|
|
||||||
|
@ -14,10 +14,11 @@ def upload() -> Response:
|
||||||
json = request.get_json()
|
json = request.get_json()
|
||||||
if json:
|
if json:
|
||||||
data = "".join(json["file"])
|
data = "".join(json["file"])
|
||||||
data_hash = hash_data(data)
|
data_hash = hash_data(data.replace(",", ""))
|
||||||
with open(f"{Config.uploads_dir}/{data_hash}", 'w') as f:
|
with open(f"{Config.uploads_dir}/{data_hash}", 'w') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
|
# Maybe add the encrypted filename ?
|
||||||
Config.database.add_file(data_hash, int(time()))
|
Config.database.add_file(data_hash, int(time()))
|
||||||
|
|
||||||
# Send the hash to the javascript client
|
# Send the hash to the javascript client
|
||||||
|
|
|
@ -4,8 +4,7 @@ from flask import Blueprint, render_template
|
||||||
router = Blueprint("file", __name__)
|
router = Blueprint("file", __name__)
|
||||||
|
|
||||||
|
|
||||||
@router.route("<int:file_hash>")
|
@router.route("<int:_>")
|
||||||
def file(file_hash: int) -> str:
|
def file(_: int) -> str:
|
||||||
"""Download page"""
|
"""Download page"""
|
||||||
print(f"hash : {file_hash}")
|
|
||||||
return render_template("download.html", config=Config)
|
return render_template("download.html", config=Config)
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
<main>
|
<main>
|
||||||
<div class="download-area">
|
<div class="download-area">
|
||||||
<h3>Téléchargement</h3>
|
<h3>Téléchargement</h3>
|
||||||
<p>Cliquez pour lancer le téléchargement du fichier</p>
|
<p>Cliquez sur le bouton pour lancer le téléchargement</p>
|
||||||
<button>Hihi</button>
|
<button id="download">Télécharger</button>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<p>NPNO</p>
|
<p>NPNO</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script src="https://unpkg.com/node-forge@1.0.0/dist/forge.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/node-forge@1.0.0/dist/forge.min.js"></script>
|
||||||
<script type="module" src="../js/index.js"></script>
|
<script type="module" src="../js/index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Reference in a new issue