Browse Source

Merge branch 'cfr34k-fastcgi'

sqozz 3 years ago
parent
commit
be7a5142f4
3 changed files with 11 additions and 3 deletions
  1. 2
    0
      README.md
  2. 6
    0
      schort.fcgi
  3. 3
    3
      schort.py

+ 2
- 0
README.md View File

@@ -1,2 +1,4 @@
1 1
 # schort
2 2
 schort is a tiny link shortener written in python3 and flask
3
+
4
+You need to create a directory /data/ which is writable by the webserver, which will contain the link database.

+ 6
- 0
schort.fcgi View File

@@ -0,0 +1,6 @@
1
+#!/usr/bin/python3
2
+from flipflop import WSGIServer
3
+from schort import app
4
+
5
+if __name__ == '__main__':
6
+    WSGIServer(app).run()

+ 3
- 3
schort.py View File

@@ -7,7 +7,7 @@ app = Flask(__name__)
7 7
 @app.route('/<shortLink>', methods=['GET', 'POST'])
8 8
 def short(shortLink=""):
9 9
 	if request.method == "GET":
10
-		conn = sqlite3.connect("links.sqlite")
10
+		conn = sqlite3.connect("data/links.sqlite")
11 11
 		c = conn.cursor()
12 12
 		result = c.execute('SELECT * FROM links WHERE shortLink=?', (shortLink, )).fetchone()
13 13
 		if result:
@@ -32,7 +32,7 @@ def insertIdUnique(idToCheck, longUrl):
32 32
 	if len(idToCheck) == 0:
33 33
 		idToCheck = base64Url[:4]
34 34
 
35
-	conn = sqlite3.connect("links.sqlite")
35
+	conn = sqlite3.connect("data/links.sqlite")
36 36
 	c = conn.cursor()
37 37
 	try:
38 38
 		c.execute('INSERT INTO links VALUES (?, ?, ?, ?, ?)', (idToCheck, longUrl, int(time.time()), request.remote_addr, "default" ))
@@ -60,7 +60,7 @@ def insertIdUnique(idToCheck, longUrl):
60 60
 	return databaseId
61 61
 
62 62
 def initDB():
63
-	conn = sqlite3.connect("links.sqlite")
63
+	conn = sqlite3.connect("data/links.sqlite")
64 64
 	c = conn.cursor()
65 65
 	c.execute('''CREATE TABLE IF NOT EXISTS links (shortLink UNIQUE NOT NULL, longLink, timestamp, ip, redirectMethod);''')
66 66
 	conn.commit()

Loading…
Cancel
Save