aboutsummaryrefslogtreecommitdiff
path: root/src/db.py
diff options
context:
space:
mode:
authorJoris2024-05-20 09:40:11 +0200
committerJoris2024-05-20 09:40:11 +0200
commit436ddf6f23242eb709b591cd5e9cbf1553f8d390 (patch)
treedfed58b5e553f131fd3009f03f095ca40efc5949 /src/db.py
parent6baa0419d3b5eb63c70be446226a321f900e433d (diff)
Allow to upload file and download from given link
Diffstat (limited to 'src/db.py')
-rw-r--r--src/db.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/db.py b/src/db.py
new file mode 100644
index 0000000..8aa20f8
--- /dev/null
+++ b/src/db.py
@@ -0,0 +1,20 @@
+import secrets
+
+def insert_file(conn, filename: str, expiration_days: int, content_length: int):
+ cur = conn.cursor()
+ file_id = secrets.token_urlsafe()
+ cur.execute(
+ 'INSERT INTO files(id, filename, created, expires, content_length) VALUES(?, ?, datetime(), datetime(datetime(), ?), ?)',
+ (file_id, filename, f'+{expiration_days} days', content_length)
+ )
+ conn.commit()
+ return file_id
+
+def get_file(conn, file_id: str):
+ cur = conn.cursor()
+ res = cur.execute(
+ 'SELECT filename, expires, content_length FROM files WHERE id = ?',
+ (file_id,)
+ )
+ return res.fetchone()
+