Skip to content

Commit 8aa6883

Browse files
committed
Fix #26: do not offer any actions after burning a paste
1 parent 388a09a commit 8aa6883

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- Use the [two-face](https://docs.rs/two-face) crate for an extended syntax
2323
list.
2424
- Serve all CSS assets under hashed URL to avoid caching issues.
25+
- Do not offer any interactions for burn-after-reading pastes that will end up
26+
with a 404 anyway.
2527

2628
### Fixes
2729

src/handlers/html/paste.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub struct Paste {
2424
key: Key,
2525
theme: Option<Theme>,
2626
can_delete: bool,
27+
/// If the paste still in the database and can be fetched with another request.
28+
is_available: bool,
2729
html: String,
2830
title: String,
2931
}
@@ -43,7 +45,7 @@ pub async fn get(
4345
let password = form.map(|form| Password::from(form.password.as_bytes().to_vec()));
4446
let key: Key = id.parse()?;
4547

46-
let (data, can_be_cached) = match db.get(key.id, password.clone()).await {
48+
let (data, is_available) = match db.get(key.id, password.clone()).await {
4749
Ok(Entry::Regular(data)) => (data, true),
4850
Ok(Entry::Burned(data)) => (data, false),
4951
Ok(Entry::Expired) => return Err(Error::NotFound),
@@ -75,7 +77,7 @@ pub async fn get(
7577
} else {
7678
let html = highlighter.highlight(data, key.ext.clone()).await?;
7779

78-
if can_be_cached && password.is_none() {
80+
if is_available && password.is_none() {
7981
tracing::trace!(?key, "cache item");
8082
cache.put(key.clone(), html.clone());
8183
}
@@ -88,6 +90,7 @@ pub async fn get(
8890
html,
8991
theme.clone(),
9092
can_be_deleted,
93+
is_available,
9194
title,
9295
page.clone(),
9396
)
@@ -104,6 +107,7 @@ impl Paste {
104107
html: Html,
105108
theme: Option<Theme>,
106109
can_delete: bool,
110+
is_available: bool,
107111
title: String,
108112
page: Page,
109113
) -> Self {
@@ -114,6 +118,7 @@ impl Paste {
114118
key,
115119
theme,
116120
can_delete,
121+
is_available,
117122
html,
118123
title,
119124
}

src/handlers/html/qr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ pub async fn get(
2828
let key: Key = id.parse()?;
2929
let title = db.get_title(key.id).await?.unwrap_or_default();
3030

31+
// TODO: fix the bogus hardcoded can_delete and is_deleted fields.
3132
Ok(Qr {
3233
page: page.clone(),
3334
theme: theme.clone(),
3435
key,
3536
can_delete: false,
37+
is_available: false,
3638
code,
3739
title,
3840
})
@@ -49,6 +51,7 @@ pub struct Qr {
4951
theme: Option<Theme>,
5052
key: Key,
5153
can_delete: bool,
54+
is_available: bool,
5255
code: qrcodegen::QrCode,
5356
title: String,
5457
}

templates/paste.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{% endblock %}
1414

1515
{% block nav_common %}
16+
{% if is_available %}
1617
{% if can_delete %}
1718
<div class="nav-item">
1819
<a href="/delete/{{ key.id() }}" class="nav-button" title="delete paste" aria-label="delete paste">
@@ -36,8 +37,10 @@
3637
</svg>
3738
</a>
3839
</div>
40+
{% endif %}
3941
{% endblock %}
4042
{% block nav_specific %}
43+
{% if is_available %}
4144
<div class="nav-item">
4245
<a href="/qr/{{ key }}" class="nav-button" title="qr code" aria-label="qr code">
4346
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
@@ -46,4 +49,5 @@
4649
</svg>
4750
</a>
4851
</div>
52+
{% endif %}
4953
{% endblock %}

0 commit comments

Comments
 (0)