add: license and readme
This commit is contained in:
parent
10fb5bf100
commit
f43d6232b7
3 changed files with 93 additions and 14 deletions
28
LICENSE
28
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.
|
63
README.md
Normal file
63
README.md
Normal file
|
@ -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
|
||||
```
|
16
app.py
16
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('/<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
|
||||
|
||||
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__':
|
||||
|
|
Loading…
Add table
Reference in a new issue