Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: FileBone(public=True) for public files #1241

Merged
merged 39 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
42c8936
feat: added public flag to filebone and file entity. default: public …
Aug 15, 2024
b703f1b
fix: missing public flag
Aug 20, 2024
74dac89
feat: added servingurls for publicfiles
Aug 20, 2024
466728c
feat: added public bucket support.
Aug 20, 2024
740b3ea
chore: pep8
Aug 20, 2024
2678224
Merge branch 'main' into feat/public-files
akelch Aug 20, 2024
abc5110
Merge branch 'main' into feat/public-files
phorward Aug 20, 2024
0abb466
Merge branch 'develop' into feat/public-files
phorward Aug 27, 2024
8fc1475
Refactoring the new public file repo
phorward Aug 27, 2024
abd1ae7
Merge branch 'develop' into feat/public-files
phorward Aug 27, 2024
68281db
Cleaning up code for working order
phorward Aug 27, 2024
5c65dbd
Minor fixes
phorward Aug 27, 2024
dbc347c
Provide refactored File.serve function
phorward Aug 27, 2024
d8841b9
Ha ha ha
phorward Aug 27, 2024
67b09c7
clean code
phorward Aug 27, 2024
b8ba387
Consequent use of PUBLIC_DLKEY_POSTFIX
phorward Aug 28, 2024
14854d7
Fixed File.read() and some split calls.
phorward Aug 28, 2024
c8f8c21
fix: added public attribute to structure
Aug 28, 2024
610f59c
Always write Exception to log
phorward Aug 29, 2024
32bde87
Renamed PUBLIC_DLKEY_POSTFIX into PUBLIC_DLKEY_SUFFIX
phorward Aug 30, 2024
e19a204
Keep bucket lookups low
phorward Aug 30, 2024
eb4bc77
Fixed missing trailing commas
phorward Sep 2, 2024
6511311
Raise UnprocessableEntity on invalid format parameter
phorward Sep 2, 2024
9aadd06
Provide filename Content-Disposition with quotes
phorward Sep 2, 2024
6d835c0
Eliminated poor error handling with try...except
phorward Sep 2, 2024
9579523
Fixed pep-8 issues and broken suggestion
phorward Sep 2, 2024
d2d8cc5
Move serve-endpoint validiy dicts to File
phorward Sep 2, 2024
e539538
Merge remote-tracking branch 'origin/develop' into feat/public-files
Sep 4, 2024
74ae93e
fix: unlimit image sizes
Sep 4, 2024
935c03f
fix: serve now takes a host and a key parameter
Sep 4, 2024
599adfb
fix: added create_serve_parameters and create_serve_url function
Sep 4, 2024
eab49a1
chore: linting
Sep 4, 2024
716a9ec
Apply suggestions from code review
phorward Sep 18, 2024
ed7bca6
Merge branch 'develop' into feat/public-files
phorward Sep 20, 2024
f254a86
create_internal_serving_url() and Jinja wrapper
phorward Sep 20, 2024
f9d7166
fix: bucket object
Sep 20, 2024
7bffdee
Merge branch 'develop' into feat/public-files
phorward Sep 23, 2024
a94b922
Simplifying `create_internal_serving_url`
phorward Sep 23, 2024
fd1cb6b
Remove unused import for itertools
phorward Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/viur/core/bones/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class FileBone(TreeLeafBone):

kind = "file"
"""The kind of this bone is 'file'"""

type = "relational.tree.leaf.file"
"""The type of this bone is 'relational.tree.leaf.file'."""

Expand All @@ -137,7 +138,16 @@ def __init__(
derive: None | dict[str, t.Any] = None,
maxFileSize: None | int = None,
validMimeTypes: None | list[str] = None,
refKeys: t.Optional[t.Iterable[str]] = ("name", "mimetype", "size", "width", "height", "derived"),
refKeys: t.Optional[t.Iterable[str]] = (
"name",
"mimetype",
"size",
"width",
"height",
"derived",
"public",
),
public: bool = False,
**kwargs
):
r"""
Expand Down Expand Up @@ -170,6 +180,7 @@ def __init__(

self.refKeys.add("dlkey")
self.derive = derive
self.public = public
self.validMimeTypes = validMimeTypes
self.maxFileSize = maxFileSize

Expand All @@ -191,6 +202,10 @@ def isInvalid(self, value):
if self.maxFileSize:
if value["dest"]["size"] > self.maxFileSize:
return "File too large."

if value["dest"]["public"] != self.public:
return f"Only files marked public={self.public!r} are allowed."

return None

def postSavedHandler(self, skel, boneName, key):
Expand Down
Loading
Loading