check file contents; work with file extensions

This commit is contained in:
Jakob Ketterl
2021-02-11 00:20:17 +01:00
parent 64f827d235
commit 0fd172edc3
4 changed files with 51 additions and 25 deletions

View File

@@ -78,7 +78,7 @@ class AssetsController(GzipMixin, ModificationAwareController, metaclass=ABCMeta
f.close()
if content_type is None:
(content_type, encoding) = mimetypes.MimeTypes().guess_type(self.getFilePath(file))
(content_type, encoding) = mimetypes.guess_type(self.getFilePath(file))
self.send_response(data, content_type=content_type, last_modified=modified, max_age=3600)
except FileNotFoundError:
self.send_response("file not found", code=404)
@@ -96,9 +96,10 @@ class OwrxAssetsController(AssetsController):
}
if file in mappedFiles and ("mapped" not in self.request.query or self.request.query["mapped"][0] != "false"):
config = CoreConfig()
user_file = config.get_data_directory() + "/" + mappedFiles[file]
if os.path.exists(user_file) and os.path.isfile(user_file):
return user_file
for ext in ["png", "jpg"]:
user_file = "{}/{}.{}".format(config.get_data_directory(), mappedFiles[file], ext)
if os.path.exists(user_file) and os.path.isfile(user_file):
return user_file
return pkg_resources.resource_filename("htdocs", file)
@@ -168,7 +169,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController):
contents = [self.getContents(f) for f in files]
(content_type, encoding) = mimetypes.MimeTypes().guess_type(profileName)
(content_type, encoding) = mimetypes.guess_type(profileName)
self.send_response("\n".join(contents), content_type=content_type, last_modified=modified, max_age=3600)
def getContents(self, file):