handlers.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:toshi-id-service 作者: toshiapp 项目源码 文件源码
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'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号