Add per-user disk quotas, auto-eviction, and Keep flag
Bounds each user's disk footprint and makes throwaway artifacts self-clean:
- Per-user quota (default 1 GB) stored on a new UserProfile model,
adjustable per user in Django admin. Artifact.size_bytes records each
artifact's on-disk footprint (primary file + markdown sidecar) at
ingest so usage is a cheap SUM.
- Automatic eviction: on each post, oldest unkept artifacts are deleted
(files and rows) until the new one fits under quota. If the quota is
full of kept artifacts, the post is rejected with HTTP 413 rather than
evicting anything protected.
- Keep flag (Artifact.is_kept): a Keep button in the preview control bar
toggles protection via POST /a/{id}/keep; kept items are never evicted.
Kept rows show a green "K" badge in the listing.
- Details panel: a Details toggle in the control bar expands a panel
under it with full source, type, created time, size, and tags.
- Settings -> Storage: usage bar (green/amber/red), used/quota summary,
artifact and kept counts; superusers also see total allocated quota vs
free disk with an oversubscription warning.
- Type indicator in the listing is now a small grey pill instead of
plain text.
Storage accounting/eviction logic lives in artifacts/storage.py.
Migrations 0009 (fields + UserProfile) and 0010 (backfill sizes and
create profiles for existing users). Fresh installs no-op the backfill.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
37cd96fa7a
commit
e0f1cce626
12 changed files with 517 additions and 12 deletions
|
|
@ -67,12 +67,15 @@
|
|||
<a class="{% if selected_view == 'raw' %}selected{% endif %}{% if not selected_artifact %} disabled{% endif %}" href="{% if selected_artifact %}{{ raw_url }}{% else %}#{% endif %}" data-view="raw" {% if not selected_artifact %}aria-disabled="true"{% endif %}>Raw</a>
|
||||
</nav>
|
||||
<div class="artifact-action-links">
|
||||
<button type="button" class="keep-button {% if selected_artifact.is_kept %}kept{% endif %}" data-keep-button data-artifact-id="{% if selected_artifact %}{{ selected_artifact.id }}{% endif %}" {% if not selected_artifact %}disabled{% endif %}>{% if selected_artifact.is_kept %}✓ Kept{% else %}Keep{% endif %}</button>
|
||||
<button type="button" data-details-toggle {% if not selected_artifact %}disabled{% endif %}>Details</button>
|
||||
<a class="{% if not selected_artifact %}disabled{% endif %}" href="{% if selected_artifact %}{% url 'artifact' selected_artifact.id %}{% else %}#{% endif %}" target="_blank" rel="noopener" {% if not selected_artifact %}aria-disabled="true"{% endif %}>Open</a>
|
||||
<a class="{% if not selected_artifact %}disabled{% endif %}" href="{% if selected_artifact %}{% url 'artifact' selected_artifact.id %}{% else %}#{% endif %}" download {% if not selected_artifact %}aria-disabled="true"{% endif %}>Download</a>
|
||||
<button type="button" data-copy-url="{% if selected_artifact %}{% url 'artifact' selected_artifact.id %}{% endif %}" {% if not selected_artifact %}disabled{% endif %}>Copy Link</button>
|
||||
<button type="button" disabled>Send</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="details-panel" hidden data-details-panel></div>
|
||||
<div class="preview-body">
|
||||
{% if selected_artifact %}
|
||||
<div class="preview-frame-wrap">
|
||||
|
|
@ -218,6 +221,35 @@
|
|||
copyButton.disabled = false;
|
||||
copyButton.dataset.copyUrl = row.dataset.renderedUrl;
|
||||
}
|
||||
syncKeepButton(row.dataset.kept === "1");
|
||||
const keepButton = actions.querySelector("[data-keep-button]");
|
||||
if (keepButton) keepButton.dataset.artifactId = row.dataset.artifactId;
|
||||
actions.querySelector("[data-details-toggle]").disabled = false;
|
||||
renderDetails(row);
|
||||
};
|
||||
|
||||
const syncKeepButton = (isKept) => {
|
||||
const keepButton = document.querySelector("[data-keep-button]");
|
||||
if (!keepButton) return;
|
||||
keepButton.disabled = false;
|
||||
keepButton.classList.toggle("kept", isKept);
|
||||
keepButton.textContent = isKept ? "✓ Kept" : "Keep";
|
||||
};
|
||||
|
||||
const renderDetails = (row) => {
|
||||
const panel = document.querySelector("[data-details-panel]");
|
||||
if (!panel) return;
|
||||
const d = row.dataset;
|
||||
const tags = d.tags ? d.tags.split(",").map((t) => t.trim()).filter(Boolean) : [];
|
||||
const rows = [
|
||||
["Source", `${escapeHtml(d.source)} (${escapeHtml(d.sourceType)})`],
|
||||
["Source name", escapeHtml(d.sourceName || "—")],
|
||||
["Type", escapeHtml(d.kind)],
|
||||
["Created", escapeHtml(d.created)],
|
||||
["Size", escapeHtml(d.size)],
|
||||
["Tags", tags.length ? tags.map(escapeHtml).join(", ") : "—"],
|
||||
];
|
||||
panel.innerHTML = `<dl class="details-grid">${rows.map(([k, v]) => `<dt>${k}</dt><dd>${v}</dd>`).join("")}</dl>`;
|
||||
};
|
||||
|
||||
const disableActions = () => {
|
||||
|
|
@ -240,6 +272,15 @@
|
|||
copyButton.disabled = true;
|
||||
copyButton.dataset.copyUrl = "";
|
||||
}
|
||||
const keepButton = actions.querySelector("[data-keep-button]");
|
||||
if (keepButton) {
|
||||
keepButton.disabled = true;
|
||||
keepButton.classList.remove("kept");
|
||||
keepButton.textContent = "Keep";
|
||||
}
|
||||
actions.querySelector("[data-details-toggle]").disabled = true;
|
||||
const panel = document.querySelector("[data-details-panel]");
|
||||
if (panel) panel.hidden = true;
|
||||
};
|
||||
|
||||
const markRead = async (row) => {
|
||||
|
|
@ -440,6 +481,34 @@
|
|||
|
||||
observeSentinel();
|
||||
|
||||
// Populate the details panel for a server-preselected artifact so the first
|
||||
// "Details" click shows content immediately.
|
||||
const preselected = selectedRow();
|
||||
if (preselected) renderDetails(preselected);
|
||||
|
||||
const toggleKeep = async (button) => {
|
||||
const artifactId = button.dataset.artifactId;
|
||||
if (!artifactId) return;
|
||||
button.disabled = true;
|
||||
try {
|
||||
const response = await fetch(`/a/${artifactId}/keep`, {
|
||||
method: "POST",
|
||||
headers: {"X-CSRFToken": csrfToken},
|
||||
});
|
||||
const data = await response.json();
|
||||
syncKeepButton(data.is_kept);
|
||||
const row = document.querySelector(`.artifact-row[data-artifact-id="${artifactId}"]`);
|
||||
if (row) {
|
||||
row.dataset.kept = data.is_kept ? "1" : "0";
|
||||
row.classList.toggle("kept", data.is_kept);
|
||||
const badge = row.querySelector("[data-kept-badge]");
|
||||
if (badge) badge.hidden = !data.is_kept;
|
||||
}
|
||||
} catch {
|
||||
button.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
previewPane.addEventListener("click", (event) => {
|
||||
const copyButton = event.target.closest("[data-copy-url]");
|
||||
if (copyButton) {
|
||||
|
|
@ -448,6 +517,24 @@
|
|||
return;
|
||||
}
|
||||
|
||||
const keepButton = event.target.closest("[data-keep-button]");
|
||||
if (keepButton && !keepButton.disabled) {
|
||||
event.preventDefault();
|
||||
toggleKeep(keepButton);
|
||||
return;
|
||||
}
|
||||
|
||||
const detailsToggle = event.target.closest("[data-details-toggle]");
|
||||
if (detailsToggle && !detailsToggle.disabled) {
|
||||
event.preventDefault();
|
||||
const panel = document.querySelector("[data-details-panel]");
|
||||
if (panel) {
|
||||
panel.hidden = !panel.hidden;
|
||||
detailsToggle.classList.toggle("selected", !panel.hidden);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const toggle = event.target.closest("[data-view]");
|
||||
if (!toggle) return;
|
||||
if (toggle.classList.contains("disabled")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue