Browse Source

add QR code support

master
lilydjwg 9 months ago
parent
commit
b1ae17bf47
3 changed files with 15 additions and 0 deletions
  1. +1
    -0
      README.md
  2. +9
    -0
      main.py
  3. +5
    -0
      templates/index.html

+ 1
- 0
README.md View File

@@ -29,3 +29,4 @@ Requirement
* Python 3.5+
* The `file` command
* [tornado](https://github.com/facebook/tornado) 3.2+
* The `qrencode` command if you want support for QR-code output

+ 9
- 0
main.py View File

@@ -39,6 +39,10 @@ def guess_mime_using_file(path):
encoding = None
return mime, encoding

def qrencode(s):
return subprocess.check_output(
['qrencode', '-t', 'UTF8', s]).decode()

mimetypes.guess_type = guess_mime_using_file

def guess_extension(ftype):
@@ -132,12 +136,17 @@ class IndexHandler(tornado.web.RequestHandler):
ret[file['filename']] = '%s/%s/%s' % (
self.request.full_url().rstrip('/'), d, f)

output_qr = self.get_argument('qr', None) is not None
if len(ret) > 1:
for item in ret.items():
self.write('%s: %s\n' % item)
if output_qr:
self.write('%s\n' % qrencode(item[1]))
elif ret:
img_url = tuple(ret.values())[0]
self.write("%s\n" % img_url)
if output_qr:
self.write('%s\n' % qrencode(img_url))
logging.info('%s posted: %s', self.request.remote_ip, ret)

class ToolHandler(tornado.web.RequestHandler):


+ 5
- 0
templates/index.html View File

@@ -18,6 +18,11 @@ DESCRIPTION
Paste image files with command line. You can give <u>-F</u> more times to paste
more images.

You can also add a <u>?qr</u> parameter to receive a QR code together with your
image URLs like this:

curl -F 'name=@/path/to/image' '{{ url }}?qr'

EXAMPLES
<span style="color:#ffc000" >$</span> curl -F 'name=@screenshot.png' {{ url }}
{% if url.find('vim-cn.com') != -1 or url.find('edisonnotes.com') != -1 %}<a href="{{ url }}97/2d8490849c8fab885218b478cc715ab0f3f4a9">{{ url }}97/2d8490849c8fab885218b478cc715ab0f3f4a9</a>{% else %}{{ url }}97/2d8490849c8fab885218b478cc715ab0f3f4a9{% end %}


Loading…
Cancel
Save