Initial Commit
This commit is contained in:
parent
e27c894937
commit
7b31c1e512
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
env/
|
||||
pastes
|
||||
test.py
|
||||
80
paste.py
Normal file
80
paste.py
Normal file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from flask import Flask, request
|
||||
import random, string
|
||||
from pathlib import Path
|
||||
|
||||
# Basic settings for paste
|
||||
|
||||
pasteDir = Path("pastes")
|
||||
nameLength = 10
|
||||
useSpecialChars = False
|
||||
allowListing = False
|
||||
|
||||
letters = string.ascii_letters
|
||||
if useSpecialChars:
|
||||
letters = letters + string.punctuation
|
||||
|
||||
# Functions
|
||||
def randomName():
|
||||
name = ""
|
||||
for x in range(0,nameLength):
|
||||
num = random.randint(0,len(letters))
|
||||
print(num)
|
||||
name += letters[num - 1]
|
||||
return name
|
||||
|
||||
def doesDirExist():
|
||||
if pasteDir.is_dir() == False:
|
||||
pasteDir.mkdir()
|
||||
|
||||
def doesPasteExist(pasteName):
|
||||
pasten = pasteDir / pasteName
|
||||
if pasten.is_file():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def writePaste(pasteName, pasteData):
|
||||
pasten = pasteDir / pasteName
|
||||
with pasten.open('w') as f: f.write(pasteData + '\n')
|
||||
|
||||
|
||||
|
||||
doesDirExist()
|
||||
|
||||
# Web interface
|
||||
|
||||
# https://paste.benjamyn.love/CBynvvjwDK
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['DEBUG'] = True
|
||||
|
||||
@app.route('/', methods=['POST', 'GET'])
|
||||
def index():
|
||||
if request.method == "GET":
|
||||
if allowListing == True:
|
||||
return "FileList"
|
||||
else:
|
||||
return "Nothing to see here ;)"
|
||||
elif request.method == "POST":
|
||||
data = request.get_data()
|
||||
name = randomName()
|
||||
while doesPasteExist(name):
|
||||
name = randomName()
|
||||
else:
|
||||
writePaste(name, data.decode())
|
||||
return "https://paste.benjamyn.love/" + name
|
||||
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def getPaste(path):
|
||||
pasten = pasteDir / path
|
||||
if pasten.is_file():
|
||||
with pasten.open() as f: data = f.read()
|
||||
return data
|
||||
else:
|
||||
return "No paste found"
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0')
|
||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
flask
|
||||
Loading…
x
Reference in New Issue
Block a user