mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
fix: FileOption return already saved and hashed filepath
This commit is contained in:
parent
321aea4171
commit
e5a593a4bb
1 changed files with 11 additions and 1 deletions
|
@ -1363,9 +1363,19 @@ class FileOption(BaseInputOption):
|
||||||
if not value:
|
if not value:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
content, ext = cls._base_value_post_validator(value, field)
|
|
||||||
bind = field.field_info.extra["bind"]
|
bind = field.field_info.extra["bind"]
|
||||||
|
|
||||||
|
# to avoid "filename too long" with b64 content
|
||||||
|
if len(value.encode("utf-8")) < 255:
|
||||||
|
# Check if value is an already hashed and saved filepath
|
||||||
|
path = Path(value)
|
||||||
|
if path.exists() and value == bind.format(
|
||||||
|
filename=path.stem, ext=path.suffix
|
||||||
|
):
|
||||||
|
return value
|
||||||
|
|
||||||
|
content, ext = cls._base_value_post_validator(value, field)
|
||||||
|
|
||||||
m = hashlib.sha256()
|
m = hashlib.sha256()
|
||||||
m.update(content)
|
m.update(content)
|
||||||
sha256sum = m.hexdigest()
|
sha256sum = m.hexdigest()
|
||||||
|
|
Loading…
Add table
Reference in a new issue