Download and store a remote GIF (or short MP4) as a DM attachment. This enables an Instagram-like GIF picker that sends a URL rather than an uploaded file. We keep this intentionally strict for safety: - only http(s) - size cap
(dm_id: int, gif_url: str)
| 12810 | if not os.path.exists(target): return None |
| 12811 | except Exception: return None |
| 12812 | return row, target |
| 12813 | |
| 12814 | |
| 12815 | @app.route("/s/<token>", methods=["GET", "POST"]) |
| 12816 | def public_share(token: str): |
| 12817 | loaded = _load_public_share(token) |
| 12818 | if not loaded: abort(404) |
| 12819 | row, target = loaded; access_key = "share:" + token |
| 12820 | locked = bool(row["pw_hash"] and not session.get(access_key)) |
| 12821 | if request.method == "POST" and locked: |
| 12822 | try: |
| 12823 | limited = _rate_limit_hit("share_password", f"{token}:{_client_ip()}", 10, 10 * 60) |
| 12824 | except Exception: |
| 12825 | limited = False |
| 12826 | if limited: |
| 12827 | abort(429) |
| 12828 | if check_password_hash(row["pw_hash"], request.form.get("password") or ""): |
| 12829 | session[access_key] = True |
| 12830 | locked = False |
| 12831 | else: |
| 12832 | flash("Incorrect password.") |
| 12833 | size = _folder_size(target) if os.path.isdir(target) else os.path.getsize(target) |
| 12834 | return render_template("public_share.html", locked=locked, token=token, name=os.path.basename(target), kind="Folder" if os.path.isdir(target) else "File", size_h=human_size(size), expires_at=row["expires_at"]) |
| 12835 | |
| 12836 | |
| 12837 | @app.route("/s/<token>/download") |
| 12838 | def public_share_download(token: str): |
| 12839 | loaded = _load_public_share(token) |
| 12840 | if not loaded: abort(404) |
| 12841 | row, target = loaded |
| 12842 | if row["pw_hash"] and not session.get("share:" + token): return redirect(url_for("public_share", token=token)) |
| 12843 | if os.path.isdir(target): |
| 12844 | path = _zip_paths(row["owner"], [row["relpath"]], os.path.basename(target)); _log_file_activity(row["owner"], "share_folder_downloaded", row["relpath"], actor="public"); return _send_temporary_zip(path, os.path.basename(target) + ".zip") |
| 12845 | _log_file_activity(row["owner"], "share_file_downloaded", row["relpath"], actor="public") |
| 12846 | if is_encrypted_file(target): |
| 12847 | response = Response(aesgcm_decrypt_generator(target), mimetype=guess_mime(target)); response.headers["Content-Disposition"] = f'attachment; filename="{os.path.basename(target)}"'; return response |
| 12848 | return send_file(target, as_attachment=True, download_name=os.path.basename(target), conditional=True, max_age=0) |
| 12849 | |
| 12850 | |
| 12851 | @app.route("/files/activity") |
| 12852 | @login_required |
| 12853 | def file_activity(): |
| 12854 | conn = db_connect(); activity = conn.execute("SELECT action, relpath, detail, created_at FROM file_activity WHERE owner=? ORDER BY id DESC LIMIT 300", (current_user(),)).fetchall(); conn.close(); return render_template("file_activity.html", activity=activity) |
| 12855 | |
| 12856 | |
| 12857 | @app.route("/view") |
| 12858 | @login_required |
| 12859 | def view_file(): |
| 12860 | rel = request.args.get("p", "") or "" |
| 12861 | try: |
| 12862 | rel = safe_relpath(rel); target = abs_user_path(current_user(), rel) |
| 12863 | if os.path.isdir(target) or not os.path.exists(target): abort(404) |
| 12864 | filename = os.path.basename(target); mime = guess_mime(filename); inline_ok = is_inline_safe(mime, filename) |
| 12865 | if is_encrypted_file(target): response = Response(aesgcm_decrypt_generator(target), mimetype=mime if inline_ok else "application/octet-stream") |
| 12866 | else: response = send_file(target, mimetype=mime if inline_ok else "application/octet-stream", as_attachment=not inline_ok, conditional=True, max_age=0) |
| 12867 | response.headers["Content-Disposition"] = f'{"inline" if inline_ok else "attachment"}; filename="{filename}"'; response.headers["Cache-Control"] = "no-store"; return response |
| 12868 | except Exception as exc: |
| 12869 | if getattr(exc, "code", None) == 404: raise |
nothing calls this directly
no test coverage detected