use api endpoint

This commit is contained in:
Mylloon 2022-10-27 14:46:19 +02:00
parent d57a6ae06a
commit 930eeacd2e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 19 additions and 12 deletions

View file

@ -1,13 +1,15 @@
from flask import Flask, redirect
from routes.index import router as index
from routes.upload import router as upload
from routes.api.upload import router as api_upload
from routes.api.download import router as api_download
from utils.font import init as init_font
from utils.libjs import init as init_libjs
app = Flask(__name__, static_url_path="/", static_folder="public")
app.register_blueprint(index, url_prefix="/index")
app.register_blueprint(upload, url_prefix="/upload")
app.register_blueprint(api_upload, url_prefix="/api/upload")
app.register_blueprint(api_download, url_prefix="/api/download")
init_font("1.3.0")
init_libjs("fc5e3c53e41490e24ca7f67cb24e7ab389b770f9")

View file

@ -62,24 +62,23 @@ const send = (file, element) => {
// Encrypt the file
file.text().then((content) => {
gen_RSA_keypair(1024).then((keys) => {
let x = RSA_enc(content, keys[1]);
console.log(RSA_dec(x, keys[0]));
gen_RSA_keypair(1024).then(([pub_key, sec_key]) => {
let encoded_file = RSA_enc(content, sec_key);
// Send it
const data = new FormData();
data.append("file", file);
data.append("file", encoded_file);
const req = new XMLHttpRequest();
req.open("POST", "upload");
req.open("POST", "api/upload");
req.send(data);
/* Here we need to store the public key and then wait for a response
* from the server. When the server send us a hash of the file
* salted (so 2 same file don't have a different URL) we redirect
* the user the a wait page so the uploader can copy a link like:
* Wait page: https://d/done
* Copy link: https://d/file/hash#pub_key_0:pub_key_1
* Wait page: https://d/upload
* Copy link: https://d/download/hash#pub_key_0:pub_key_1
* When the user click on the link, he can download the file, asking
* to the server with the hash of the link and the public key
* encoded in the URL */

View file

@ -0,0 +1,8 @@
from flask import Blueprint, redirect, request
router = Blueprint("download", __name__)
@router.route("", methods=["POST"])
def download():
return redirect("index")

View file

@ -6,8 +6,6 @@ router = Blueprint("upload", __name__)
@router.route("", methods=["POST"])
def upload():
if request.method == "POST":
if "file" in request.files:
file = request.files["file"]
print(file)
print(request.get_data())
return redirect("index")