aboutsummaryrefslogtreecommitdiff
path: root/cgi/oekaki.py
diff options
context:
space:
mode:
Diffstat (limited to 'cgi/oekaki.py')
-rw-r--r--cgi/oekaki.py56
1 files changed, 47 insertions, 9 deletions
diff --git a/cgi/oekaki.py b/cgi/oekaki.py
index 14446d7..14c3a1d 100644
--- a/cgi/oekaki.py
+++ b/cgi/oekaki.py
@@ -74,7 +74,7 @@ def oekaki(self, path_split):
'layer_count': '5',
'undo': '90',
'undo_in_mg': '15',
- 'url_save': Settings.BOARDS_URL + 'oek_temp/save.php?applet=shi'+applet_str,
+ 'url_save': Settings.BOARDS_URL + 'oek_temp/save.py?applet=shi'+applet_str,
'poo': 'false',
'send_advance': 'true',
'send_language': 'utf8',
@@ -109,6 +109,19 @@ def oekaki(self, path_split):
params['url_exit'] = Settings.CGI_URL + 'oekaki/finish/' + board['dir'] + '/' + str(parentid)
page += renderTemplate("paint.html", {'applet': applet_name, 'edit': editfile, 'replythread': parentid, 'width': width, 'height': height, 'params': params, 'selfy': use_selfy})
+ elif path_split[2] == 'save':
+ # path splits:
+ # 3: Board
+ # 4: Data format
+ board = setBoard(path_split[3])
+
+ ip = inet_aton(self.environ["REMOTE_ADDR"])
+ fname = "%s/%s/temp/%d.png" % (Settings.IMAGES_DIR, board['dir'], ip)
+
+ if path_split[4] == 'b64':
+ page = write_from_base64(fname, self.formdata['image'])
+ elif path_split[4] == 'paintbbs':
+ page = write_from_shi(fname, self.environ["wsgi.input"])
elif path_split[2] == 'finish':
# path splits:
# 3: Board
@@ -126,17 +139,11 @@ def oekaki(self, path_split):
ts = int(time.time())
ip = inet_aton(self.environ["REMOTE_ADDR"])
- fname = "%s/oek_temp/%d.png" % (Settings.HOME_DIR, ip)
+ fname = "%s/%s/temp/%d.png" % (Settings.IMAGES_DIR, board['dir'], ip)
oek = 'no'
if 'filebase' in self.formdata:
- img = self.formdata['filebase']
- if img.startswith("data:image/png;base64,"):
- img = img[22:]
- img = img.replace(' ', '+')
- img = img.decode('base64')
- with open(fname, 'wb') as f:
- f.write(img)
+ write_from_base64(fname, self.formdata['filebase'])
if os.path.isfile(fname):
oek = ip
@@ -176,3 +183,34 @@ def oekaki(self, path_split):
if not skiptemplate:
self.output = page
+
+def write_from_base64(fname, data):
+ # Skip header
+ if data.startswith("data:image/png;base64,"):
+ data = data[22:]
+ data = data.replace(' ', '+')
+ data = data.decode('base64')
+ with open(fname, 'wb') as f:
+ f.write(data)
+ return "OK"
+
+def write_from_shi(fname, fp):
+ # Check data type
+ type = fp.read(1)
+ if type != 'P':
+ return "UNSUPPORTED"
+
+ # Read header
+ headerLength = int(fp.read(8))
+ header = fp.read(headerLength)
+
+ # Read image data
+ imgLength = int(fp.read(8))
+ fp.read(2) # TODO: seek() isn't working for some reason. Debug.
+ img = fp.read(imgLength)
+
+ # Write image
+ with open(fname, 'wb') as f:
+ f.write(img)
+
+ return "OK" \ No newline at end of file