def get(self, address, hash, format, include_body=True):
format = format.upper()
if format not in ['PNG', 'JPG', 'JPEG']:
raise HTTPError(404)
if format == 'JPG':
format = 'JPEG'
async with self.db:
if hash is None:
row = await self.db.fetchrow("SELECT * FROM avatars WHERE toshi_id = $1 AND format = $2 ORDER BY last_modified DESC",
address, format)
else:
row = await self.db.fetchrow(
"SELECT * FROM avatars WHERE toshi_id = $1 AND format = $2 AND substring(hash for {}) = $3"
.format(AVATAR_URL_HASH_LENGTH),
address, format, hash)
if row is None or row['format'] != format:
raise HTTPError(404)
await self.handle_file_response(row['img'], "image/{}".format(format.lower()),
row['hash'], row['last_modified'])
评论列表
文章目录