From f43d6232b7bda28afbaefbfaad42e56ca8980efb Mon Sep 17 00:00:00 2001 From: ahoemann Date: Fri, 28 Mar 2025 10:19:07 +0100 Subject: [PATCH] add: license and readme --- LICENSE | 28 +++++++++++++++++++++++++ README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ app.py | 16 ++------------ 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 README.md diff --git a/LICENSE b/LICENSE index e69de29..7f206be 100644 --- a/LICENSE +++ b/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2025, Adrian Hoemann + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8d7d52e --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# Installation + +## Setting up the environment + +1. Create a virtual environment: + +```sh +python3 -m venv .venv +``` + +2. Activate the virtual environment: + +```sh +. .venv/bin/activate +``` + +3. Install dependencies: + +```sh +pip install -r requirements.txt +``` + +4. Set the environment variables: + +```sh +export DEBUGMODE=False +export PASTE_DIR=paste +``` + +Or source the .env file: + +```sh +cp .env.example .env # change the variables to suit your environment as needed +``` + +```sh +. .env +``` + +5. Run the app: + +```sh +waitress-serve --listen=0.0.0.0:8080 app:app +``` + +# Docker + +## Building the container + +```sh +docker build -t adrianux:latest . +``` + +## Running the container + +```sh +docker run adrianux:latest +``` +# Docker Compose + +```sh +docker compose up adrianux +``` diff --git a/app.py b/app.py index 18b9cc4..dbe1486 100644 --- a/app.py +++ b/app.py @@ -4,47 +4,35 @@ 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(): +def bin(): 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('/') 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 - + return redirect("http://localhost:5000", code=302) 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__':