Validate report attachment size and return (safe_name, mime).
(file_storage)
| 17317 | aid: Parameter. |
| 17318 | |
| 17319 | Returns: |
| 17320 | Varies. |
| 17321 | """ |
| 17322 | owner = current_user() |
| 17323 | conn = db_connect() |
| 17324 | row = conn.execute(""" |
| 17325 | SELECT a.stored_path, e.owner |
| 17326 | FROM profiler_attachments a |
| 17327 | JOIN profiler_entries e ON e.id=a.entry_id |
| 17328 | WHERE a.id=? |
| 17329 | """, (aid,)).fetchone() |
| 17330 | if not row or row["owner"] != owner: |
| 17331 | conn.close() |
| 17332 | abort(404) |
| 17333 | sp = row["stored_path"] |
| 17334 | conn.execute("DELETE FROM profiler_attachments WHERE id=?", (aid,)) |
| 17335 | conn.commit() |
| 17336 | conn.close() |
| 17337 | try: |
| 17338 | if sp and os.path.exists(sp): |
| 17339 | os.remove(sp) |
no test coverage detected