-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
121 additions
and
978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from fastapi import Response | ||
from fastapi.responses import FileResponse, RedirectResponse | ||
|
||
GITHUB_PROFILE_URL = os.environ["GITHUB_PROFILE_URL"] | ||
RESOURCES_PATH = Path("./resources/") | ||
|
||
|
||
def get_header(): | ||
return { | ||
"Cache-Control": "no-cache, max-age=0", | ||
# "Last-Modified": datetime.now().strftime("%a, %d %b %Y %H:%M:%S GMT"), | ||
# "ETag": etag, | ||
} | ||
|
||
|
||
def png_response(img: bytes): | ||
""" | ||
Maybe some optimisations could be done here. | ||
I'm pretty sure that the request *could* be cached but without being cached. | ||
Like -> if the content didn't change, don't send it again, otherwise send it. | ||
Also, the tiles are "shared" between the image, so maybe there is a way for the browser to reuse the same image. | ||
I don't want to dig more into this, but it's a thought. | ||
""" | ||
# etag = hashlib.md5(img).hexdigest() | ||
return Response(img, media_type="image/png", headers=get_header()) | ||
|
||
|
||
def file_response(path: Path): | ||
return FileResponse(path, headers=get_header()) | ||
|
||
|
||
def redirect_to_readme(anchor: str = ""): | ||
return RedirectResponse(f"{GITHUB_PROFILE_URL}{anchor}") | ||
|
||
|
||
def load_image(path: Path): | ||
with path.open("rb") as f: | ||
return f.read() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.