Compare commits

..

No commits in common. "604c28a85aa9e2961b18e386653a27749e7d0073" and "27248e9518258e5c74c0681c9062f6c0ae1fb99f" have entirely different histories.

14 changed files with 9 additions and 28 deletions

1
.gitignore vendored Executable file → Normal file
View file

@ -1,4 +1,3 @@
.ruff_cache/
venv/
.idea/
__pycache__/

View file

@ -1,7 +0,0 @@
steps:
ruff:
image: ubuntu:23.04
commands:
- apt -y install python3 python3-pip
- pip3 install -r requirements-dev.txt
- ruff check .

0
LICENSE Executable file → Normal file
View file

1
paste/__init__.py Executable file → Normal file
View file

@ -1 +0,0 @@
"""Paste package."""

0
paste/app.py Executable file → Normal file
View file

0
paste/config.py Executable file → Normal file
View file

2
paste/db.py Executable file → Normal file
View file

@ -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") # noqa: G004
logging.error(f"Key : {url_id} already exist")

11
paste/home.py Executable file → Normal file
View file

@ -15,7 +15,7 @@ from paste.utils import generate_id
home = Blueprint("home", __name__, url_prefix="/")
def create_paste(content: str, time:int) -> str:
def create_paste(content: str) -> str:
"""
Create paste in DB.
:param content: Content to add in redis.
@ -24,7 +24,7 @@ def create_paste(content: str, time:int) -> str:
url_id = generate_id()
while check_content_exist(url_id):
url_id = generate_id()
insert_content_db(url_id, time, content)
insert_content_db(url_id, 3600, content)
return url_id
@ -44,11 +44,8 @@ def create() -> Response:
:return: Redirection to homapage.
"""
content = request.form.get("content")
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}")
url_id = create_paste(content)
flash(f"Paste available at {request.host_url}{url_id}")
return redirect(url_for("home.homepage"))

0
paste/templates/content.html.j2 Executable file → Normal file
View file

8
paste/templates/home.html.j2 Executable file → Normal file
View file

@ -1,11 +1,9 @@
<form id="paste-content" method="POST" accept-charset="UTF-8" action="{{ url_for('home.create') }}">
<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">
<input name="content">
<button>Create</button>
</form>
{% with messages = get_flashed_messages() %}
{% if messages %}
<p>Paste available at : <a href="{{ messages[0] }}">{{ messages[0] }}</a></p>
<p>{{ messages[0] }}</p>
{% endif %}
{% endwith %}

4
paste/utils.py Executable file → Normal file
View file

@ -1,4 +1,3 @@
# ruff: noqa: S311
"""Shared utils function."""
import random
import string
@ -12,6 +11,5 @@ 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)
)

0
pyproject.toml Executable file → Normal file
View file

View file

@ -1,3 +0,0 @@
flask==2.3.3
redis==5.0.0
ruff==0.0.291

0
requirements.txt Executable file → Normal file
View file