Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "burn after reading" feature, closes issue #24 #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sprunge.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def help():
form = (
'data:text/html,<form action="{0}" method="POST" accept-charset="UTF-8">'
'<textarea name="{1}" cols="80" rows="24"></textarea>'
'<br><input type="radio" name="burn" value="true">Delete paste after one view?'
'<br><button type="submit">{1}</button></form>'.format(URL, POST)
)
return """
Expand All @@ -43,6 +44,7 @@ def help():
DESCRIPTION
add <a href='{3}'>?&lt;lang&gt;</a> to resulting url for line numbers and syntax highlighting
use <a href='{2}'>this form</a> to paste from a browser
add "burn=true" to your request to cause the paste to be deleted after one view

EXAMPLES
~$ cat bin/ching | curl -F '{0}=&lt;-' {1}
Expand All @@ -68,6 +70,7 @@ class Sprunge(db.Model):
content = db.TextProperty()
date = db.DateTimeProperty(auto_now_add=True)
blob = db.StringProperty()
burn = db.BooleanProperty()

class MainHandler(webapp2.RequestHandler):

Expand All @@ -88,6 +91,7 @@ def post(self):
s.name = nid
key = make_blob(nid, self.request.get(POST))
s.blob = key
s.burn = (self.request.get('burn') == 'true')
try:
s.put()
except Exception as ex:
Expand Down Expand Up @@ -128,7 +132,9 @@ def get(self, resource):
c.put()
except Exception as ex:
logging.error(ex)

if c.burn:
blobstore.delete(c.blob)
c.delete()
syntax = self.request.query_string
if not syntax:
self.response.headers['Content-Type'] = 'text/plain; charset=UTF-8'
Expand Down