def try_get_banner(user_id, sizename, privacy=0):
if sizename.endswith(".png"):
sizename = sizename[:-4]
if sizename not in sizemap:
abort(404)
if len(str(user_id)) != 9:
abort(404)
size = sizemap[sizename]
try:
data, mtime = get_data(user_id)
key = "%d_p%d" % (user_id, privacy)
privatize(data, privacy)
res = get_sized_banner(key, data, mtime, size)
if request.query_string == "dl":
res.headers['Content-Disposition'] = 'attachment; filename=%d_p%d_%s.png' % (user_id, privacy, sizename)
return res
except APIError as e:
if e.code == 1457:
return send_file("static/error_404_%d.png" % size, mimetype="image/png", cache_timeout=60)
elif e.code == 101:
return send_file("static/error_503_%d.png" % size, mimetype="image/png", cache_timeout=60)
else:
app.logger.exception("API error for %r/%r/%r" % (user_id, sizename, privacy))
return send_file("static/error_%d.png" % size, mimetype="image/png", cache_timeout=60)
except Exception as e:
app.logger.exception("Exception thrown for %r/%r/%r" % (user_id, sizename, privacy))
return send_file("static/error_%d.png" % size, mimetype="image/png", cache_timeout=60)
评论列表
文章目录