Browse Source

minor changes

pull/8/head
lilydjwg 5 years ago
parent
commit
6e8cad19b6
3 changed files with 9 additions and 12 deletions
  1. +0
    -1
      .gitignore
  2. +1
    -1
      README.md
  3. +8
    -10
      main.py

+ 0
- 1
.gitignore View File

@@ -2,5 +2,4 @@ elimage.db
*~
*.bak
.*.swp

__pycache__/

+ 1
- 1
README.md View File

@@ -22,7 +22,7 @@ You can specify multiple `-F` parameters for multiple image files. The name of
the form field doesn't matter.

```sh
curl -F 'name=@path/to/image' http://<your_host>[:port]/
curl -F 'name=@path/to/image' http://<your_host>/
```

Requirement


+ 8
- 10
main.py View File

@@ -63,13 +63,14 @@ class IndexHandler(tornado.web.RequestHandler):
file_name = os.path.join(self.settings['template_path'], 'index.html')
with open(file_name, 'r') as index_file:
text = index_file.read()
self.index_template = tornado.template.Template(text,
compress_whitespace=False)
content = self.index_template.generate(url=self.request.full_url())
self.write(content)
except IOError:
logging.exception('failed to open the file: %s', file_name)
raise tornado.web.HTTPError(404, 'index.html is missing')
else:
self.index_template = tornado.template.Template(
text, compress_whitespace=False)
content = self.index_template.generate(url=self.request.full_url())
self.write(content)

def post(self):
# Check the user has been blocked or not
@@ -103,9 +104,10 @@ class IndexHandler(tornado.web.RequestHandler):
try:
with open(fpath, 'wb') as img_file:
img_file.write(file['body'])
except IOError:
except IOError:
logging.exception('failed to open the file: %s', fpath)
ret[file['filename']] = 'FAIL'
self.set_status(500)
continue

ftype = mimetypes.guess_type(fpath)[0]
@@ -115,18 +117,14 @@ class IndexHandler(tornado.web.RequestHandler):
if ext:
f += ext
ret[file['filename']] = '%s/%s/%s' % (
self.request.full_url().rstrip('/'), d, f)
self.request.full_url().rstrip('/'), d, f)

if len(ret) > 1:
for item in ret.items():
self.write('%s: %s\n' % item)
if item[1] == "FAIL":
self.set_status(500)
elif ret:
img_url = tuple(ret.values())[0]
self.write("%s\n" % img_url)
if img_url == "FAIL":
self.set_status(500)

class ToolHandler(tornado.web.RequestHandler):
def get(self):


Loading…
Cancel
Save