Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_attach.py @ 3202:2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
"path" refers to a local path of a file, we don't want to store it in database as the file
may be in a temporary location, or even be a temporary file. So once the file has been
uploaded, we remove it.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Mar 2020 18:19:03 +0100 |
parents | 883fb4981958 |
children | 2ba602aef90e |
comparison
equal
deleted
inserted
replaced
3201:439e2f88c3a9 | 3202:2e892f9f54f6 |
---|---|
57 to_delete = [] | 57 to_delete = [] |
58 attachments = data["extra"]["attachments"] | 58 attachments = data["extra"]["attachments"] |
59 | 59 |
60 for attachment in attachments: | 60 for attachment in attachments: |
61 try: | 61 try: |
62 path = Path(attachment["path"]) | 62 # we pop path because we don't want it to be stored, as the image can be |
63 # only in a temporary location | |
64 path = Path(attachment.pop("path")) | |
63 except KeyError: | 65 except KeyError: |
64 log.warning("no path in attachment: {attachment}") | 66 log.warning("no path in attachment: {attachment}") |
65 to_delete.append(attachment) | 67 to_delete.append(attachment) |
66 continue | 68 continue |
67 | 69 |
68 if "url" in attachment: | 70 if "url" in attachment: |
69 log.warning("invalid attachment: unknown URL") | 71 url = attachment.pop('url') |
70 to_delete.append(attachment) | 72 log.warning( |
73 f"unexpected URL in attachment: {url!r}\nattachment: {attachment}" | |
74 ) | |
71 | 75 |
72 try: | 76 try: |
73 name = attachment["name"] | 77 name = attachment["name"] |
74 except KeyError: | 78 except KeyError: |
75 name = attachment["name"] = path.name | 79 name = attachment["name"] = path.name |