Compare commits

...

2 commits

9 changed files with 49 additions and 14 deletions

View file

@ -1,6 +1,6 @@
# Sand
## Exécution avec Python 3.10.8
## Exécution avec Python 3.9.2
Préparation de l'environnement

View file

@ -34,7 +34,7 @@ def init() -> None:
# Create upload folder if doesn't exists
if not exist(Config.uploads_dir):
mkdir(path=Config.uploads_dir)
mkdir(Config.uploads_dir)
# TODO: Clear every t mins the uploads directory and database
# TODO: On init, check if files in db are corresponding to the files stored

View file

@ -0,0 +1,9 @@
import { RSA_dec_data as RSA_dec } from "./rsa.js";
window.addEventListener("load", () => main());
const main = () => {
const pub_key = window.location.hash.slice(1).split(":");
const hash = window.location.pathname.split("/").pop();
console.log(pub_key, hash);
};

View file

@ -88,7 +88,7 @@ const send = (file, element) => {
let link = `${url.join("/")}/${req.responseText.slice(
1,
-2
)}/${pub_key[0]}:${pub_key[1]}`;
)}#${pub_key[0]}:${pub_key[1]}`;
let main_div = element.parentElement.parentElement;
main_div.textContent = "";

View file

@ -4,10 +4,8 @@ from flask import Blueprint, render_template
router = Blueprint("file", __name__)
@router.route("<int:file_hash>/<string:key_data>")
def file(file_hash: int, key_data: str) -> str:
@router.route("<int:file_hash>")
def file(file_hash: int) -> str:
"""Download page"""
print(f"hash : {file_hash}")
key = key_data.split(":")
print(f"key : {key}")
return render_template("index.html", config=Config, download=True)
return render_template("download.html", config=Config)

View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ config.name }}</title>
<link rel="stylesheet" href="../styles/style.css" />
</head>
<body>
<header class="text-center">
<h1 class="text-title">{{ config.name }}</h1>
</header>
<main>
<div class="download-area">
<h3>Téléchargement</h3>
<p>Cliquez pour lancer le téléchargement du fichier</p>
<button>Hihi</button>
</div>
</main>
<footer>
<p>NPNO</p>
</footer>
<script type="module" src="../js/download.js"></script>
</body>
</html>

View file

@ -30,6 +30,6 @@
</footer>
<script src="https://unpkg.com/node-forge@1.0.0/dist/forge.min.js"></script>
<script type="module" src="../js/main.js"></script>
<script type="module" src="../js/index.js"></script>
</body>
</html>

View file

@ -1,5 +1,4 @@
from hashlib import sha256
from sys import set_int_max_str_digits
BYTEORDER = "big"
@ -23,6 +22,4 @@ def int_to_bytes(data: int) -> bytes:
def hash_data(string: str) -> str:
"""Hash a string"""
# https://docs.python.org/3/library/sys.html#sys.set_int_max_str_digits
set_int_max_str_digits(len(string))
return str(int.from_bytes(sha256(int_to_bytes(int(string))).digest(), BYTEORDER))

View file

@ -1,5 +1,5 @@
from os import mkdir
from sqlite3 import Cursor, connect
from sqlite3 import connect
from utils.misc import exist
@ -17,7 +17,7 @@ class Database:
self.fullpath = fullpath
def request(self, request: str, valeurs=None) -> tuple[Cursor, int | None]:
def request(self, request: str, valeurs=None) -> tuple:
"""Send a request to the database"""
connection = connect(self.fullpath)
cursor = connection.cursor()