vienalatina/apps/board/templates/thread.html
Claude 9355121b7c
Let members post pictures, and back them up
Phase B. Images on threads and comments, stored in /data/uploads —
inside the volume that already holds board.db, so there is one directory
to back up rather than two and no second mount to remember.

Not in the site repository, which is the distinction that matters: the
content editor uploads by committing, and a private photo committed
there would go through the build pipeline and out onto vienalatina.com.

The type is decided by the first bytes, not the filename. content.py
trusts the extension, which is tolerable where Hugo serves the result;
here we serve it back, so an HTML file called gato.png would be a script
running on our own origin. Five magic-number checks, no new dependency.
The uploaded name is kept only as text to show a person; the name on
disk is generated. Staging is separate from saving so a refused picture
cannot leave a half-made thread behind.

Threads and comments are soft-deleted, so the serving route checks the
parent is still live. Without it, taking a post down leaves its photo
readable by anyone who noted the URL.

And the hole this phase existed to close: backup-board.sh archived
board.db and nothing else, so the first upload would have made the
nightly backup silently incomplete while still reporting success. It now
archives the uploads directory too, verifies the archive, and names the
directory when it is empty rather than passing over it in silence.
Tested by restoring: destroyed the directory, restored from the archive,
compared bytes.

IMAGE_EXTENSIONS moves to uploads.py and content.py imports it, so the
editor and the board cannot drift apart about what counts as a picture.

46 new tests, 176 in total.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
2026-09-28 09:02:18 +00:00

88 lines
3.6 KiB
HTML

{% extends "base.html" %}
{% from "_attachments.html" import attachments %}
{% block title %}{{ thread.title }}{% endblock %}
{% block main %}
<article class="card">
<div class="card__meta">
{% if thread.pinned %}<span class="tag">Fijado</span>{% endif %}
{% if thread.locked %}<span class="tag tag--quiet">Cerrado</span>{% endif %}
<span>{{ author }}</span> · <time>{{ thread.created_at }}</time>
{% if thread.edited_at %}<span class="muted small">(editado)</span>{% endif %}
</div>
<h1 class="card__title">{{ thread.title }}</h1>
<div class="prose">{{ body_html }}</div>
{{ attachments(thread_images) }}
<div class="actions">
{% if may_edit(thread) %}
<a class="linkish" href="{{ url_for('board.edit_thread', thread_id=thread.id) }}">Editar</a>
{% endif %}
{% if may_delete(thread) %}
<form method="post" action="{{ url_for('board.delete_thread', thread_id=thread.id) }}"
data-confirm="¿Eliminar este tema?">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button class="linkish linkish--danger" type="submit">Eliminar</button>
</form>
{% endif %}
{% if is_admin %}
<form method="post" action="{{ url_for('board.set_state', thread_id=thread.id) }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<input type="hidden" name="field" value="pinned">
<input type="hidden" name="value" value="{{ 0 if thread.pinned else 1 }}">
<button class="linkish" type="submit">{{ 'No fijar' if thread.pinned else 'Fijar' }}</button>
</form>
<form method="post" action="{{ url_for('board.set_state', thread_id=thread.id) }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<input type="hidden" name="field" value="locked">
<input type="hidden" name="value" value="{{ 0 if thread.locked else 1 }}">
<button class="linkish" type="submit">{{ 'Reabrir' if thread.locked else 'Cerrar' }}</button>
</form>
{% endif %}
</div>
</article>
<h2 class="section-head">{{ comments|length }} respuesta{{ '' if comments|length == 1 else 's' }}</h2>
{% for c in comments %}
<article class="card card--comment">
<div class="card__meta">
<span>{{ c.author }}</span> · <time>{{ c.created_at }}</time>
{% if c.edited_at %}<span class="muted small">(editado)</span>{% endif %}
</div>
<div class="prose">{{ to_html(c.body_md) }}</div>
{{ attachments(comment_images.get(c.id, [])) }}
<div class="actions">
{% if may_edit(c) %}
<a class="linkish" href="{{ url_for('board.edit_comment', comment_id=c.id) }}">Editar</a>
{% endif %}
{% if may_delete(c) %}
<form method="post" action="{{ url_for('board.delete_comment', comment_id=c.id) }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button class="linkish linkish--danger" type="submit">Eliminar</button>
</form>
{% endif %}
</div>
</article>
{% endfor %}
<span id="final"></span>
{% if thread.locked and not is_admin %}
<p class="muted">Este tema está cerrado a nuevas respuestas.</p>
{% else %}
<form class="card" method="post" enctype="multipart/form-data"
action="{{ url_for('board.comment', thread_id=thread.id) }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<label for="body">Responder</label>
<textarea id="body" name="body" rows="5" required
placeholder="Se puede usar Markdown: **negrita**, listas, enlaces."></textarea>
<label for="pictures">Imágenes <span class="muted small">(opcional)</span></label>
<input id="pictures" name="pictures" type="file" multiple accept="image/*">
<button class="btn" type="submit">Publicar respuesta</button>
</form>
{% endif %}
{% endblock %}