feat: initial commit
This commit is contained in:
commit
ae4325a969
28 changed files with 2945 additions and 0 deletions
7
.dockerignore
Normal file
7
.dockerignore
Normal file
|
@ -0,0 +1,7 @@
|
|||
.forgejo
|
||||
*compose.yml
|
||||
Dockerfile
|
||||
.git*
|
||||
Jenkinsfile
|
||||
LICENSE
|
||||
README.md
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.venv*
|
||||
.env
|
||||
__pycache__
|
15
Dockerfile
Normal file
15
Dockerfile
Normal file
|
@ -0,0 +1,15 @@
|
|||
FROM alpine:latest
|
||||
WORKDIR /opt/
|
||||
|
||||
ENV DEBUG_MODE=False
|
||||
ENV PASTE_DIR=pastes
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN apk add --no-cache python3 py3-flask py3-waitress cron
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
HEALTHCHECK --interval=5m CMD wget --delete-after http://localhost:8080
|
||||
|
||||
CMD [ "waitress-serve", "--listen=0.0.0.0:8080", "app:app" ]
|
0
LICENSE
Normal file
0
LICENSE
Normal file
51
app.py
Normal file
51
app.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from flask import Flask, request, render_template, abort, redirect
|
||||
import secrets
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Directory to store paste files
|
||||
paste_dir = os.environ['PASTE_DIR']
|
||||
|
||||
if not os.path.exists(paste_dir):
|
||||
os.makedirs(paste_dir)
|
||||
|
||||
# Route for the main page
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
if request.method == 'POST':
|
||||
# Get content and language from the form
|
||||
content = request.form['content']
|
||||
# Generate a unique ID for the paste
|
||||
paste_id = secrets.token_hex(8)
|
||||
# Create the file path for the paste
|
||||
file_path = os.path.join(paste_dir, paste_id)
|
||||
|
||||
# Save the paste content to a file
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(f"{content}")
|
||||
|
||||
# Generate the URL for the new paste
|
||||
paste_url = request.url_root + paste_id
|
||||
return render_template('bin.j2', paste_url=paste_url)
|
||||
|
||||
# Render the form with available languages
|
||||
return render_template('bin.j2')
|
||||
|
||||
# Route to view a specific paste by its ID
|
||||
@app.route('/<paste_id>')
|
||||
def view_paste(paste_id):
|
||||
# Create the file path for the paste
|
||||
file_path = os.path.join(paste_dir, paste_id)
|
||||
if not os.path.exists(file_path):
|
||||
return redirect("http://localhost:5000", code=302) # Return a 404 error if the paste does not exist
|
||||
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Render the paste with syntax highlighting
|
||||
return render_template('bin.j2', paste_content=content )
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=os.environ['DEBUG_MODE'])
|
1
paste/1129250e41fd939f
Normal file
1
paste/1129250e41fd939f
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
paste/166df7446b9cedd2
Normal file
1
paste/166df7446b9cedd2
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
paste/223d486abe15baac
Normal file
1
paste/223d486abe15baac
Normal file
|
@ -0,0 +1 @@
|
|||
basr
|
1
paste/5c7060da2fde6c70
Normal file
1
paste/5c7060da2fde6c70
Normal file
|
@ -0,0 +1 @@
|
|||
t
|
1
paste/5f061281b5db5798
Normal file
1
paste/5f061281b5db5798
Normal file
|
@ -0,0 +1 @@
|
|||
VW Polo 9n3 1.2
|
1
paste/68acc064f8c810fa
Normal file
1
paste/68acc064f8c810fa
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
paste/700d33e6844602f6
Normal file
1
paste/700d33e6844602f6
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
paste/75f8d4eae450a00d
Normal file
1
paste/75f8d4eae450a00d
Normal file
|
@ -0,0 +1 @@
|
|||
test1
|
1
paste/793e612cd9ebf718
Normal file
1
paste/793e612cd9ebf718
Normal file
|
@ -0,0 +1 @@
|
|||
tset
|
1
paste/7b8940f86990f32e
Normal file
1
paste/7b8940f86990f32e
Normal file
|
@ -0,0 +1 @@
|
|||
tset
|
1
paste/915916ffb2addda0
Normal file
1
paste/915916ffb2addda0
Normal file
|
@ -0,0 +1 @@
|
|||
t
|
1
paste/95b2820464994fa2
Normal file
1
paste/95b2820464994fa2
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
paste/9eb5c03c1be2404c
Normal file
1
paste/9eb5c03c1be2404c
Normal file
|
@ -0,0 +1 @@
|
|||
doo
|
1
paste/c34c7220f89764e8
Normal file
1
paste/c34c7220f89764e8
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
paste/c64b23a68d8484ea
Normal file
1
paste/c64b23a68d8484ea
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
paste/c78e7f7161a150c0
Normal file
1
paste/c78e7f7161a150c0
Normal file
|
@ -0,0 +1 @@
|
|||
basr
|
1
paste/ebd8f44366c8c692
Normal file
1
paste/ebd8f44366c8c692
Normal file
|
@ -0,0 +1 @@
|
|||
tset
|
1
paste/test
Normal file
1
paste/test
Normal file
|
@ -0,0 +1 @@
|
|||
</h1>test</h1>
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
flask
|
2802
static/css/pico.css
Normal file
2802
static/css/pico.css
Normal file
File diff suppressed because it is too large
Load diff
4
static/css/pico.min.css
vendored
Normal file
4
static/css/pico.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
22
templates/base.j2
Normal file
22
templates/base.j2
Normal file
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="light">
|
||||
<head>
|
||||
{% block head %}
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="description" content="the main Adrianux page">
|
||||
<link rel="canonical" href="https://adrianux.net/">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/pico.css') }}" />
|
||||
<title>{% block title %}{% endblock %} - Adrianux.net</title>
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>{{ self.title() }}</h1>
|
||||
<article>{% block content %}{% endblock %}</article>
|
||||
</main>
|
||||
<footer class="container">
|
||||
<p><a href="mailto:ahoemann@proton.me">ahoemann@proton.me</a>
|
||||
</p>Authored by <a href="https://bin.adrianux.net/">Adrian Hoemann</a>.
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
22
templates/bin.j2
Normal file
22
templates/bin.j2
Normal file
|
@ -0,0 +1,22 @@
|
|||
{% extends "base.j2" %}
|
||||
{% block title %}Pastebin Service{% endblock %}
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% if paste_url %}
|
||||
<p>Your paste URL: <a href="{{ paste_url }}">{{ paste_url }}</a></p>
|
||||
<form method="post">
|
||||
<textarea name="content" rows="10" cols="50" placeholder="Paste your text here..."></textarea>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
{% elif paste_content %}
|
||||
<pre><code><script style="display:block" type="text/plain">{{ paste_content|safe }}</script></code></pre>
|
||||
{% else %}
|
||||
<form method="post">
|
||||
<textarea name="content" rows="10" cols="50" placeholder="Paste your text here..."></textarea>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
Loading…
Add table
Reference in a new issue