aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/plugins/piwigo
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2013-03-21 09:16:05 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2013-03-21 09:18:07 +0100
commit398d384137bce928592dd63c210126ab989ee69c (patch)
treecda76aaabd537b5916418a34bd36ef3887b6daf0 /mediagoblin/plugins/piwigo
parentcf0816c182c2acab30b1ee9e191aff091ac41d13 (diff)
downloadmediagoblin-398d384137bce928592dd63c210126ab989ee69c.tar.lz
mediagoblin-398d384137bce928592dd63c210126ab989ee69c.tar.xz
mediagoblin-398d384137bce928592dd63c210126ab989ee69c.zip
piwigo start at pwg.images.addChunk.
This function receives part of an upload. Does most parameter validation, but does not safe the data anywhere for now. Also fake pwg.images.exist
Diffstat (limited to 'mediagoblin/plugins/piwigo')
-rw-r--r--mediagoblin/plugins/piwigo/views.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/mediagoblin/plugins/piwigo/views.py b/mediagoblin/plugins/piwigo/views.py
index 6198ec6e..e9ce6206 100644
--- a/mediagoblin/plugins/piwigo/views.py
+++ b/mediagoblin/plugins/piwigo/views.py
@@ -15,10 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
+import re
-from werkzeug.exceptions import MethodNotAllowed
+from werkzeug.exceptions import MethodNotAllowed, BadRequest
from werkzeug.wrappers import BaseResponse
+from mediagoblin import mg_globals
from mediagoblin.meddleware.csrf import csrf_exempt
from mediagoblin.tools.response import render_404
from .tools import CmdTable, PwgNamedArray, response_xml
@@ -73,6 +75,46 @@ def pwg_categories_getList(request):
}
+@CmdTable("pwg.images.exist")
+def pwg_images_exist(request):
+ return {}
+
+
+md5sum_matcher = re.compile(r"^[0-9a-fA-F]{32}$")
+
+def fetch_md5(request, parm_name, optional_parm=False):
+ val = request.form.get(parm_name)
+ if (val is None) and (not optional_parm):
+ _log.error("Parameter %s missing", parm_name)
+ raise BadRequest("Parameter %s missing" % parm_name)
+ if not md5sum_matcher.match(val):
+ _log.error("Parameter %s=%r has no valid md5 value", parm_name, val)
+ raise BadRequest("Parameter %s is not md5" % parm_name)
+ return val
+
+
+@CmdTable("pwg.images.addChunk", True)
+def pwg_images_addChunk(request):
+ o_sum = fetch_md5(request, 'original_sum')
+ typ = request.form.get('type')
+ pos = request.form.get('position')
+ data = request.form.get('data')
+
+ # Validate params:
+ pos = int(pos)
+ if not typ in ("file", "thumb"):
+ _log.error("type %r not allowed for now", typ)
+ return False
+
+ _log.info("addChunk for %r, type %r, position %d, len: %d",
+ o_sum, typ, pos, len(data))
+ if typ == "thumb":
+ _log.info("addChunk: Ignoring thumb, because we create our own")
+ return True
+
+ return True
+
+
def possibly_add_cookie(request, response):
# TODO: We should only add a *real* cookie, if
# authenticated. And if there is no cookie already.