from flask import Flask, request, render_template, abort, redirect import secrets import os app = Flask(__name__) paste_dir = os.environ['PASTE_DIR'] if not os.path.exists(paste_dir): os.makedirs(paste_dir) @app.route('/', methods=['GET', 'POST']) def bin(): if request.method == 'POST': content = request.form['content'] paste_id = secrets.token_hex(8) file_path = os.path.join(paste_dir, paste_id) with open(file_path, 'w') as f: f.write(f"{content}") paste_url = request.url_root + paste_id return render_template('bin.j2', paste_url=paste_url) return render_template('bin.j2') @app.route('/') def view_paste(paste_id): file_path = os.path.join(paste_dir, paste_id) if not os.path.exists(file_path): return redirect("/", code=302) with open(file_path, 'r') as f: content = f.read() return render_template('bin.j2', paste_content=content ) if __name__ == '__main__': app.run(debug=os.environ['DEBUG_MODE'])