From cfa77463ea324fd50687e5268725e598cb3217e3 Mon Sep 17 00:00:00 2001
From: Ada <ada@gnous.eu>
Date: Tue, 26 Sep 2023 11:32:42 +0200
Subject: [PATCH] add(front): expiration time field

---
 LICENSE                         |  0
 paste/__init__.py               |  1 +
 paste/app.py                    |  0
 paste/config.py                 |  0
 paste/db.py                     |  2 +-
 paste/home.py                   | 11 +++++++----
 paste/templates/content.html.j2 |  0
 paste/templates/home.html.j2    |  8 +++++---
 paste/utils.py                  |  4 +++-
 pyproject.toml                  |  0
 requirements.txt                |  0
 11 files changed, 17 insertions(+), 9 deletions(-)
 mode change 100644 => 100755 LICENSE
 mode change 100644 => 100755 paste/__init__.py
 mode change 100644 => 100755 paste/app.py
 mode change 100644 => 100755 paste/config.py
 mode change 100644 => 100755 paste/db.py
 mode change 100644 => 100755 paste/home.py
 mode change 100644 => 100755 paste/templates/content.html.j2
 mode change 100644 => 100755 paste/templates/home.html.j2
 mode change 100644 => 100755 paste/utils.py
 mode change 100644 => 100755 pyproject.toml
 mode change 100644 => 100755 requirements.txt

diff --git a/LICENSE b/LICENSE
old mode 100644
new mode 100755
diff --git a/paste/__init__.py b/paste/__init__.py
old mode 100644
new mode 100755
index e69de29..678be53
--- a/paste/__init__.py
+++ b/paste/__init__.py
@@ -0,0 +1 @@
+"""Paste package."""
\ No newline at end of file
diff --git a/paste/app.py b/paste/app.py
old mode 100644
new mode 100755
diff --git a/paste/config.py b/paste/config.py
old mode 100644
new mode 100755
diff --git a/paste/db.py b/paste/db.py
old mode 100644
new mode 100755
index 2e6fc78..938672e
--- a/paste/db.py
+++ b/paste/db.py
@@ -39,4 +39,4 @@ def insert_content_db(url_id: str, expiration: int, content: str) -> None:
         db.set(url_id, content)
         db.expire(url_id, expiration)
     else:
-        logging.error(f"Key : {url_id} already exist")
+        logging.error(f"Key : {url_id} already exist") # noqa: G004
diff --git a/paste/home.py b/paste/home.py
old mode 100644
new mode 100755
index 574ac3b..48670d2
--- a/paste/home.py
+++ b/paste/home.py
@@ -15,7 +15,7 @@ from paste.utils import generate_id
 home = Blueprint("home", __name__, url_prefix="/")
 
 
-def create_paste(content: str) -> str:
+def create_paste(content: str, time:int) -> str:
     """
     Create paste in DB.
     :param content: Content to add in redis.
@@ -24,7 +24,7 @@ def create_paste(content: str) -> str:
     url_id = generate_id()
     while check_content_exist(url_id):
         url_id = generate_id()
-    insert_content_db(url_id, 3600, content)
+    insert_content_db(url_id, time, content)
     return url_id
 
 
@@ -44,8 +44,11 @@ def create() -> Response:
     :return: Redirection to homapage.
     """
     content = request.form.get("content")
-    url_id = create_paste(content)
-    flash(f"Paste available at {request.host_url}{url_id}")
+    time = request.form.get("time")
+    time = 86400 if time == "" else int(time)
+
+    url_id = create_paste(content, time)
+    flash(f"{request.host_url}{url_id}")
     return redirect(url_for("home.homepage"))
 
 
diff --git a/paste/templates/content.html.j2 b/paste/templates/content.html.j2
old mode 100644
new mode 100755
diff --git a/paste/templates/home.html.j2 b/paste/templates/home.html.j2
old mode 100644
new mode 100755
index 1a3e653..580c897
--- a/paste/templates/home.html.j2
+++ b/paste/templates/home.html.j2
@@ -1,9 +1,11 @@
 <form id="paste-content" method="POST" accept-charset="UTF-8" action="{{ url_for('home.create') }}">
-    <input name="content">
-    <button>Create</button>
+     <textarea name="content" form="paste-content">Enter text here...</textarea>
+    <label for="time">Time in second</label>
+    <input id="time" name="time">
+    <input type="submit">
 </form>
 {% with messages = get_flashed_messages() %}
     {% if messages %}
-        <p>{{ messages[0] }}</p>
+        <p>Paste available at : <a href="{{ messages[0] }}">{{ messages[0] }}</a></p>
     {% endif %}
 {% endwith %}
diff --git a/paste/utils.py b/paste/utils.py
old mode 100644
new mode 100755
index d128385..3135afb
--- a/paste/utils.py
+++ b/paste/utils.py
@@ -1,3 +1,4 @@
+# ruff: noqa: S311
 """Shared utils function."""
 import random
 import string
@@ -11,5 +12,6 @@ def generate_id() -> str:
     :return: Url id.
     """
     return "".join(
-        random.choices(string.ascii_letters + string.digits, k=config.URL_LENGTH)
+        random.choices(string.ascii_letters + string.digits,
+                       k=config.URL_LENGTH)
     )
diff --git a/pyproject.toml b/pyproject.toml
old mode 100644
new mode 100755
diff --git a/requirements.txt b/requirements.txt
old mode 100644
new mode 100755