summaryrefslogtreecommitdiff
path: root/web/req/request.py
diff options
context:
space:
mode:
authorRichard Knight <q@1bpm.net>2020-08-24 14:47:08 +0100
committerRichard Knight <q@1bpm.net>2020-08-24 14:47:08 +0100
commit38b2a0d6928a7e29d7ac7a2332c3cccb1708ad30 (patch)
tree6cc0aa096ebf39bebb0e9a8eae46a10af736e457 /web/req/request.py
downloadpeep.1bpm.net-38b2a0d6928a7e29d7ac7a2332c3cccb1708ad30.tar.gz
peep.1bpm.net-38b2a0d6928a7e29d7ac7a2332c3cccb1708ad30.tar.bz2
peep.1bpm.net-38b2a0d6928a7e29d7ac7a2332c3cccb1708ad30.zip
initialHEADmaster
Diffstat (limited to 'web/req/request.py')
-rwxr-xr-xweb/req/request.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/web/req/request.py b/web/req/request.py
new file mode 100755
index 0000000..eaa2929
--- /dev/null
+++ b/web/req/request.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+import cgi
+import cgitb
+import os
+import db
+import datetime
+import json
+import base64
+
+cgitb.enable()
+
+class Error(Exception):
+ pass
+
+class JSONReponse(object):
+ def __init__(self, data):
+ self.data = data
+
+ def respond(self):
+ print "Content-Type: application/json\n\n" + json.dumps(self.data)
+
+
+def local_files_path():
+ return os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "files"))
+
+def local_file(name):
+ return os.path.join(local_files_path(), name)
+
+def new_file(extension):
+ return "{0}{1}".format(datetime.datetime.now().strftime("%s%f"), extension)
+
+
+class Handler(object):
+ def __init__(self):
+ request = cgi.FieldStorage()
+ if os.environ["REQUEST_METHOD"] == "POST":
+ self.handle_post(request)
+ else:
+ self.handle_get(request)
+
+ def handle_get(self, request):
+ pass
+
+ def handle_post(self, request):
+ imagedata = data["image"]
+ filename = new_file(os.path.splitext(fileitem.filename)[1])
+ dest_path = local_file(filename)
+ open(dest_path, "wb").write(base64.b64decode(imagedata.replace("data:image/png;base64,", "")))
+ db.GalleryImage.create(
+ path=filename,
+ added_by_ip=os.environ["REMOTE_ADDR"],
+ added_by_name=data.getvalue("name", None)
+ added_by_detail=data.getvalue("detail", None)
+ )
+ return JSONResponse({"ok": True})
+