fix timezones in all places

This commit is contained in:
Jakob Ketterl 2020-06-21 22:35:40 +02:00
parent 2eece08d27
commit 75f4f0bfe0

View File

@ -1,13 +1,34 @@
from . import Controller
from owrx.config import Config
from datetime import datetime
from datetime import datetime, timezone
import mimetypes
import os
import pkg_resources
from abc import ABCMeta, abstractmethod
class AssetsController(Controller, metaclass=ABCMeta):
class ModificationAwaraController(Controller, metaclass=ABCMeta):
@abstractmethod
def getModified(self, file):
pass
def wasModified(self, file):
try:
modified = self.getModified(file).astimezone(timezone.utc).replace(microsecond=0)
if modified is not None and "If-Modified-Since" in self.handler.headers:
client_modified = datetime.strptime(
self.handler.headers["If-Modified-Since"], "%a, %d %b %Y %H:%M:%S %Z"
).replace(tzinfo=timezone.utc)
if modified <= client_modified:
return False
except FileNotFoundError:
pass
return True
class AssetsController(ModificationAwaraController, metaclass=ABCMeta):
def getModified(self, file):
return datetime.fromtimestamp(os.path.getmtime(self.getFilePath(file)))
@ -22,11 +43,7 @@ class AssetsController(Controller, metaclass=ABCMeta):
try:
modified = self.getModified(file)
if modified is not None and "If-Modified-Since" in self.handler.headers:
client_modified = datetime.strptime(
self.handler.headers["If-Modified-Since"], "%a, %d %b %Y %H:%M:%S %Z"
)
if modified <= client_modified:
if not self.wasModified(file):
self.send_response("", code=304)
return
@ -63,7 +80,7 @@ class AprsSymbolsController(AssetsController):
return self.path + file
class CompiledAssetsController(Controller):
class CompiledAssetsController(ModificationAwaraController):
profiles = {
"receiver.js": [
"openwebrx.js",
@ -107,11 +124,7 @@ class CompiledAssetsController(Controller):
modified = self.getModified(files)
if modified is not None and "If-Modified-Since" in self.handler.headers:
client_modified = datetime.strptime(
self.handler.headers["If-Modified-Since"], "%a, %d %b %Y %H:%M:%S %Z"
)
if modified <= client_modified:
if not self.wasModified(files):
self.send_response("", code=304)
return