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