mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-10 20:27:53 +02:00
Automatically compress uploads with gzip (#1087)
* Gzip .html upload, tests for .html & .gz uploads * Gzip all file types that aren't already gzips * Show filename of what user uploaded before compression * Remove line I thought we need but we don't * cleanup and fix tests --------- Co-authored-by: kclark <kclark@autoverify.net> Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
@@ -236,8 +236,17 @@ class BookmarkFactoryMixin:
|
||||
|
||||
def read_asset_file(self, asset: BookmarkAsset):
|
||||
filepath = os.path.join(settings.LD_ASSET_FOLDER, asset.file)
|
||||
with open(filepath, "rb") as f:
|
||||
return f.read()
|
||||
|
||||
if asset.gzip:
|
||||
with gzip.open(filepath, "rb") as f:
|
||||
return f.read()
|
||||
else:
|
||||
with open(filepath, "rb") as f:
|
||||
return f.read()
|
||||
|
||||
def get_asset_filesize(self, asset: BookmarkAsset):
|
||||
filepath = os.path.join(settings.LD_ASSET_FOLDER, asset.file)
|
||||
return os.path.getsize(filepath) if os.path.exists(filepath) else 0
|
||||
|
||||
def has_asset_file(self, asset: BookmarkAsset):
|
||||
filepath = os.path.join(settings.LD_ASSET_FOLDER, asset.file)
|
||||
|
Reference in New Issue
Block a user