Пример #1
0
 def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     return file_stream(file_path,
                        chunk_size=32,
                        mime_type=guess_type(file_path)[0] or 'text/plain',
                        _range=range)
Пример #2
0
async def pfp(request):
    ip = "ImRock"
    for _h in ['CF-Connecting-IP', 'CF_CONNECTING_IP', 'X_FORWARDED_FOR', 'REMOTE_ADDR']:
        _ip = request.headers.get(_h, False)
        if _ip:
            ip = _ip
            break
    print(ip)
    if ip != "ImRock":
        i = Image.new("RGBA", (256, 256))

        size = 50  # initial font size
        font_location = join(cdn_path, "Fonts", "default.ttf")
        font_draw = ImageDraw.Draw(i)

        print(ip)
        while size > 0:
            font = ImageFont.truetype(font_location, size)
            text_width, text_height = font_draw.textsize(
                text=ip,
                font=font)
            print(size, text_width, text_height)
            if text_width < i.width and text_height < i.height:
                break
            size -= 1

        font_draw.text(
            (math.floor((i.width - text_width) / 2),
             math.floor((i.height - text_height) / 2)),
            text=ip,
            align="left",
            font=font,
            fill=(255, 255, 255))

        font_draw.text(
            (math.floor((i.width - text_width) / 2) - 1,
             math.floor((i.height - text_height) / 2) - 1),
            text=ip,
            align="left",
            font=font,
            fill=(0, 0, 0))

        bytes_image = io.BytesIO()
        i.save(bytes_image, format="PNG", compress_level=1)
        bytes_image.seek(0)

        headers = {"content-Type": "image/png"}
        resp = response.raw(bytes_image.read(), headers=headers)
        return resp
    else:
        return response.file_stream("/home/rock/Welcomer 6.0/twist.png")
Пример #3
0
 async def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     headers = dict()
     headers['Accept-Ranges'] = 'bytes'
     if request.method == "HEAD":
         # Return a normal HTTPResponse, not a
         # StreamingHTTPResponse for a HEAD request
         stats = await async_os.stat(file_path)
         headers['Content-Length'] = str(stats.st_size)
         return HTTPResponse(
             headers=headers,
             content_type=guess_type(file_path)[0] or 'text/plain')
     else:
         return file_stream(file_path, chunk_size=32, headers=headers,
                            mime_type=guess_type(file_path)[0] or 'text/plain')
Пример #4
0
 async def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     headers = dict()
     headers['Accept-Ranges'] = 'bytes'
     if request.method == "HEAD":
         # Return a normal HTTPResponse, not a
         # StreamingHTTPResponse for a HEAD request
         stats = await async_os.stat(file_path)
         headers['Content-Length'] = str(stats.st_size)
         return HTTPResponse(
             headers=headers,
             content_type=guess_type(file_path)[0] or 'text/plain')
     else:
         return file_stream(file_path, chunk_size=32, headers=headers,
                     mime_type=guess_type(file_path)[0] or 'text/plain')
Пример #5
0
 def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     return file_stream(file_path, chunk_size=32, filename=dest)
Пример #6
0
 def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     return file_stream(file_path, chunk_size=32,
                       mime_type=guess_type(file_path)[0] or 'text/plain')