Merge branch 'cfr34k-fastcgi'
This commit is contained in:
commit
be7a5142f4
|
@ -1,2 +1,4 @@
|
|||
# schort
|
||||
schort is a tiny link shortener written in python3 and flask
|
||||
|
||||
You need to create a directory /data/ which is writable by the webserver, which will contain the link database.
|
||||
|
|
6
schort.fcgi
Executable file
6
schort.fcgi
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
from flipflop import WSGIServer
|
||||
from schort import app
|
||||
|
||||
if __name__ == '__main__':
|
||||
WSGIServer(app).run()
|
|
@ -7,7 +7,7 @@ app = Flask(__name__)
|
|||
@app.route('/<shortLink>', methods=['GET', 'POST'])
|
||||
def short(shortLink=""):
|
||||
if request.method == "GET":
|
||||
conn = sqlite3.connect("links.sqlite")
|
||||
conn = sqlite3.connect("data/links.sqlite")
|
||||
c = conn.cursor()
|
||||
result = c.execute('SELECT * FROM links WHERE shortLink=?', (shortLink, )).fetchone()
|
||||
if result:
|
||||
|
@ -32,7 +32,7 @@ def insertIdUnique(idToCheck, longUrl):
|
|||
if len(idToCheck) == 0:
|
||||
idToCheck = base64Url[:4]
|
||||
|
||||
conn = sqlite3.connect("links.sqlite")
|
||||
conn = sqlite3.connect("data/links.sqlite")
|
||||
c = conn.cursor()
|
||||
try:
|
||||
c.execute('INSERT INTO links VALUES (?, ?, ?, ?, ?)', (idToCheck, longUrl, int(time.time()), request.remote_addr, "default" ))
|
||||
|
@ -60,7 +60,7 @@ def insertIdUnique(idToCheck, longUrl):
|
|||
return databaseId
|
||||
|
||||
def initDB():
|
||||
conn = sqlite3.connect("links.sqlite")
|
||||
conn = sqlite3.connect("data/links.sqlite")
|
||||
c = conn.cursor()
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS links (shortLink UNIQUE NOT NULL, longLink, timestamp, ip, redirectMethod);''')
|
||||
conn.commit()
|
||||
|
|
Loading…
Reference in a new issue