message/tmessage/views/static.py

27 lines
667 B
Python
Raw Normal View History

2024-12-23 22:38:49 -05:00
from django.http import HttpResponse
from django.urls import path
from django.views.decorators.cache import cache_control
from tmessage.settings import STATIC_DIR
def get_static_serve(path: str, content_type: str):
def x(request):
return HttpResponse(
open(STATIC_DIR / path, "rb").read(),
content_type=content_type
)
x.__name__ = path
return x
file_associations = {
"js": "text/javascript",
"css": "text/css"
}
urlpatterns = [path(i, cache_control(**{"max-age": 60 * 60 * 24 * 30})(get_static_serve(i, file_associations[i.split(".")[-1]]))) for i in [
"js/messages.js",
"css/messages.css"
]]