Skip to content

Commit

Permalink
return the url also
Browse files Browse the repository at this point in the history
  • Loading branch information
bhanderson committed Apr 29, 2016
1 parent 9287a41 commit 32ddaa0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 2 additions & 3 deletions pbnh/app/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io
import json
import magic
import mimetypes

Expand Down Expand Up @@ -29,7 +28,7 @@ def fileData(files, addr=None, sunset=None, mimestr=None):
username=config.get('username')) as pstr:
j = pstr.create(data, mime=mime, ip=addr,
sunset=sunset)
return json.dumps(j)
return j
except IOError as e:
return 'caught exception in filedata' + str(e)
return 'File save error'
Expand All @@ -41,7 +40,7 @@ def stringData(inputstr, addr=None, sunset=None, mime=None):
password=config.get('password'), port=config.get('port'),
username=config.get('username')) as pstr:
j = pstr.create(inputstr.encode('utf-8'), mime=mime, ip=addr, sunset=sunset)
return json.dumps(j)
return j
return 'String save error'

def getSunsetFromStr(sunsetstr):
Expand Down
19 changes: 13 additions & 6 deletions pbnh/app/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import re
import json

from datetime import datetime, timezone, timedelta
from docutils.core import publish_parts
Expand Down Expand Up @@ -38,22 +39,28 @@ def post_paste():
sunset = util.getSunsetFromStr(sunsetstr)
redirectstr = request.form.get('r') or request.form.get('redirect')
if redirectstr:
return util.stringData(redirectstr, addr=addr, sunset=sunset,
mime='redirect'), 201
j = util.stringData(redirectstr, addr=addr, sunset=sunset, mime='redirect')
if j:
j['link'] = request.url + str(j.get('id'))
return json.dumps(j), 201
inputstr = request.form.get('content') or request.form.get('c')
# we got string data
if inputstr and isinstance(inputstr, str):
try:
return util.stringData(inputstr, addr=addr, sunset=sunset,
mime=mimestr), 201
j = util.stringData(inputstr, addr=addr, sunset=sunset, mime=mimestr)
if j:
j['link'] = request.url + str(j.get('id'))
return json.dumps(j), 201
except (exc.OperationalError, exc.InternalError):
abort(500)
files = request.files.get('content') or request.files.get('c')
# we got file data
if files and isinstance(files, FileStorage):
try:
return util.fileData(files, addr=addr, sunset=sunset,
mimestr=mimestr), 201
j = util.fileData(files, addr=addr, sunset=sunset, mimestr=mimestr)
if j:
j['link'] = request.url + str(j.get('id'))
return json.dumps(j), 201
except (exc.OperationalError, exc.InternalError):
abort(500)
abort(400)
Expand Down

0 comments on commit 32ddaa0

Please sign in to comment.